Esempio n. 1
0
    def __init__(self, address, pairs=None, channels=None, callbacks=None, book_interval=1000):
        self.address = address
        self.standardized_pairs = pairs
        self.standardized_channels = channels
        self.book_update_interval = book_interval
        self.updates = 0
        self.do_deltas = False

        if channels is not None and FUNDING in channels and self.id == BITFINEX:
            if len(channels) > 1:
                raise ValueError("Funding channel must be in a separate feedhanlder on Bitfinex")

        if pairs:
            self.pairs = [pair_std_to_exchange(pair, self.id) for pair in pairs]
        if channels:
            self.channels = [feed_to_exchange(self.id, chan) for chan in channels]

        self.l3_book = {}
        self.l2_book = {}
        self.callbacks = {TRADES: Callback(None),
                          TICKER: Callback(None),
                          L2_BOOK: Callback(None),
                          L3_BOOK: Callback(None),
                          VOLUME: Callback(None),
                          FUNDING: Callback(None)}


        if callbacks:
            for cb in callbacks:
                self.callbacks[cb] = callbacks[cb]
                if isinstance(callbacks[cb], BookUpdateCallback):
                    self.do_deltas = True
Esempio n. 2
0
    def __init__(self, address, pairs=None, channels=None, callbacks=None):
        self.address = address
        self.standardized_pairs = pairs
        self.standardized_channels = channels

        if pairs:
            self.pairs = [
                pair_std_to_exchange(pair, self.id) for pair in pairs
            ]
        if channels:
            self.channels = [
                feed_to_exchange(self.id, chan) for chan in channels
            ]

        self.l3_book = {}
        self.l2_book = {}
        self.callbacks = {
            TRADES: Callback(None),
            TICKER: Callback(None),
            L2_BOOK: Callback(None),
            L3_BOOK: Callback(None),
            VOLUME: Callback(None)
        }

        if callbacks:
            for cb in callbacks:
                self.callbacks[cb] = callbacks[cb]
Esempio n. 3
0
    def __init__(self, pairs=None, channels=None, callbacks=None, **kwargs):
        if len(pairs) != 1:
            LOG.error("Binance requires a websocket per trading pair")
            raise ValueError("Binance requires a websocket per trading pair")
        if len(channels) != 1:
            LOG.error("Binance requires a websocket per channel pair")
            raise ValueError("Binance requires a websocket per channel pair")

        p = pair_std_to_exchange(pairs[0], BINANCE)
        self.pairs = pairs[0]
        c = feed_to_exchange(BINANCE, channels[0])
        endpoint = "wss://stream.binance.com:9443/ws/{}@{}".format(p.lower(), c)

        super().__init__(endpoint, None, None, callbacks, **kwargs)
        self.__reset()
Esempio n. 4
0
    def __init__(self,
                 address,
                 pairs=None,
                 channels=None,
                 callbacks=None,
                 book_interval=1000):
        self.address = address
        self.standardized_pairs = pairs
        self.standardized_channels = channels
        self.book_update_interval = book_interval
        self.updates = 0
        self.do_deltas = False

        if channels is not None and FUNDING in channels and self.id == BITFINEX:
            if any(map(lambda x: x[0] != 'f', pairs)):
                raise ValueError(
                    "Funding channel on bitfinex can be used with funding pairs only"
                )

        if pairs:
            self.pairs = [
                pair_std_to_exchange(pair, self.id) for pair in pairs
            ]
        if channels:
            self.channels = [
                feed_to_exchange(self.id, chan) for chan in channels
            ]

        self.l3_book = {}
        self.l2_book = {}
        self.callbacks = {
            TRADES: Callback(None),
            TICKER: Callback(None),
            L2_BOOK: Callback(None),
            L3_BOOK: Callback(None),
            VOLUME: Callback(None),
            FUNDING: Callback(None)
        }

        if callbacks:
            for cb in callbacks:
                self.callbacks[cb] = callbacks[cb]
                if isinstance(callbacks[cb], BookUpdateCallback):
                    self.do_deltas = True
Esempio n. 5
0
    def __init__(self,
                 address,
                 pairs=None,
                 channels=None,
                 callbacks=None,
                 intervals=None,
                 default_interval=60 * 60):
        self.address = address
        self.standardized_pairs = pairs
        self.standardized_channels = channels

        if pairs:
            self.pairs = [
                pair_std_to_exchange(pair, self.id) for pair in pairs
            ]
        if channels:
            self.channels = [
                feed_to_exchange(self.id, chan) for chan in channels
            ]

        self.l3_book = {}
        self.l2_book = {}
        self.callbacks = {
            TRADES: Callback(None),
            TICKER: Callback(None),
            L2_BOOK: Callback(None),
            L3_BOOK: Callback(None),
            L3_BOOK_UPDATE: Callback(None),
            VOLUME: Callback(None)
        }

        self.intervals = defaultdict(
            lambda: default_interval
        )  # {func_name: schedule_interval_in_seconds}
        if intervals is not None:
            self.intervals.update(intervals)

        if callbacks:
            for cb in callbacks:
                self.callbacks[cb] = callbacks[cb]
Esempio n. 6
0
    def __init__(self,
                 address,
                 pairs=None,
                 channels=None,
                 callbacks=None,
                 book_interval=1000):
        self.address = address
        self.standardized_pairs = pairs
        self.standardized_channels = channels
        self.book_update_interval = book_interval
        self.updates = 0
        self.do_deltas = False

        if pairs:
            self.pairs = [
                pair_std_to_exchange(pair, self.id) for pair in pairs
            ]
        if channels:
            self.channels = [
                feed_to_exchange(self.id, chan) for chan in channels
            ]

        self.l3_book = {}
        self.l2_book = {}
        self.callbacks = {
            TRADES: Callback(None),
            TICKER: Callback(None),
            L2_BOOK: Callback(None),
            L3_BOOK: Callback(None),
            VOLUME: Callback(None)
        }

        if callbacks:
            for cb in callbacks:
                self.callbacks[cb] = callbacks[cb]
                if isinstance(callbacks[cb], BookUpdateCallback):
                    self.do_deltas = True