Created
June 20, 2017 15:43
-
-
Save shredding/7ee241db6c9f2afa58fccc1623a9e8d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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