Skip to content

Instantly share code, notes, and snippets.

@shredding
Created June 20, 2017 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shredding/7ee241db6c9f2afa58fccc1623a9e8d3 to your computer and use it in GitHub Desktop.
Save shredding/7ee241db6c9f2afa58fccc1623a9e8d3 to your computer and use it in GitHub Desktop.
# coding=utf-8
import logging
from django.core.management import BaseCommand
from backend.engine.tasks import get_strategies, get_strategy_by_currency_pair
log = logging.getLogger('notifications')
VERSION = '1.4.2'
currency_streams = {}
def callback(api, stream):
prev = currency_streams.get(api.currency_pair)
if prev and prev.get('bid') == stream['bid'] and prev.get('ask') == stream['ask']:
return
strategy = get_strategy_by_currency_pair(currency_pair=api.currency_pair)
strategy.execute(stream)
currency_streams[api.currency_pair] = stream
class Command(BaseCommand):
def handle(self, *args, **options):
for strategy in get_strategies():
strategy.setup()
strategy.source.api.connect_to_stream(callback)
log.info('{} {} - Version {}'.format(
strategy.source.source_name,
strategy.source.currency_pair,
VERSION
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment