Ejemplo n.º 1
0
    def __init__(self,
                 address,
                 pairs=None,
                 channels=None,
                 config=None,
                 callbacks=None,
                 book_interval=1000):
        self.hash = str(uuid.uuid4())
        self.uuid = self.id + self.hash
        self.config = {}
        self.address = address
        self.book_update_interval = book_interval
        self.updates = 0
        self.do_deltas = False
        self.pairs = []
        self.channels = []
        load_exchange_pair_mapping(self.id)

        if config is not None and (pairs is not None or channels is not None):
            raise ValueError("Use config, or channels and pairs, not both")

        if config is not None:
            for channel in config:
                chan = feed_to_exchange(self.id, channel)
                self.config[chan] = [
                    pair_std_to_exchange(pair, self.id)
                    for pair in config[channel]
                ]

        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),
            INSTRUMENT: Callback(None)
        }

        if callbacks:
            for cb_type, cb_func in callbacks.items():
                self.callbacks[cb_type] = cb_func
                if cb_type == BOOK_DELTA:
                    self.do_deltas = True

        for key, callback in self.callbacks.items():
            if not isinstance(callback, list):
                self.callbacks[key] = [callback]
Ejemplo n.º 2
0
    def __init__(self,
                 address,
                 pairs=None,
                 channels=None,
                 config=None,
                 callbacks=None,
                 book_interval=1000):
        self.config = {}
        self.address = address
        self.book_update_interval = book_interval
        self.updates = 0
        self.do_deltas = False
        self.pairs = []
        self.channels = []

        load_exchange_pair_mapping(self.id)

        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 or you must use config"
                )

        if config is not None and (pairs is not None or channels is not None):
            raise ValueError("Use config, or channels and pairs, not both")

        if config is not None:
            for channel in config:
                chan = feed_to_exchange(self.id, channel)
                self.config[chan] = [
                    pair_std_to_exchange(pair, self.id)
                    for pair in config[channel]
                ]

        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_type, cb_func in callbacks.items():
                self.callbacks[cb_type] = cb_func
                if cb_type == BOOK_DELTA:
                    self.do_deltas = True
Ejemplo n.º 3
0
 def __getitem__(self, key):
     if not self.mapped:
         load_exchange_pair_mapping(self.ID)
         self.mapped = True
     if key == 'trades':
         return self.trades
     elif key == 'funding':
         return self.funding
Ejemplo n.º 4
0
 def __getattr__(self, attr):
     exch = self.lookup[attr.lower()]
     if not exch.mapped:
         try:
             load_exchange_pair_mapping(exch.ID + 'REST')
         except KeyError:
             load_exchange_pair_mapping(exch.ID)
         exch.mapped = True
     return exch
Ejemplo n.º 5
0
    def __init__(self, address, pairs=None, channels=None, config=None, callbacks=None, max_depth=None, book_interval=1000, cross_check=False, origin=None):
        self.hash = str(uuid.uuid4())
        self.uuid = self.id + self.hash
        self.config = defaultdict(set)
        self.address = address
        self.book_update_interval = book_interval
        self.cross_check = cross_check
        self.updates = defaultdict(int)
        self.do_deltas = False
        self.pairs = []
        self.channels = []
        self.max_depth = max_depth
        self.previous_book = defaultdict(dict)
        self.origin = origin
        load_exchange_pair_mapping(self.id)

        if config is not None and (pairs is not None or channels is not None):
            raise ValueError("Use config, or channels and pairs, not both")

        if config is not None:
            for channel in config:
                chan = feed_to_exchange(self.id, channel)
                self.config[chan].update([pair_std_to_exchange(pair, self.id) for pair in config[channel]])

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

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

        if callbacks:
            for cb_type, cb_func in callbacks.items():
                self.callbacks[cb_type] = cb_func
                if cb_type == BOOK_DELTA:
                    self.do_deltas = True

        for key, callback in self.callbacks.items():
            if not isinstance(callback, list):
                self.callbacks[key] = [callback]
Ejemplo n.º 6
0
    def __init__(self, config, sandbox=False):
        load_exchange_pair_mapping(self.ID)
        path = os.path.dirname(os.path.abspath(__file__))
        self.key_id, self.key_secret, self.key_passphrase = None, None, None
        self.sandbox = sandbox
        if not config:
            config = "config.yaml"

        try:
            with open(os.path.join(path, config), 'r') as fp:
                data = yaml.safe_load(fp)
                self.key_id = data[self.ID.lower()]['key_id']
                self.key_secret = data[self.ID.lower()]['key_secret']
                if 'key_passphrase' in data[self.ID.lower()]:
                    self.key_passphrase = data[self.ID.lower()]['key_passphrase']
        except (KeyError, FileNotFoundError, TypeError):
            pass
Ejemplo n.º 7
0
 def __getitem__(self, key):
     if not self.mapped:
         try:
             load_exchange_pair_mapping(self.ID + 'REST')
         except KeyError:
             load_exchange_pair_mapping(self.ID)
         self.mapped = True
     if key == 'trades':
         return self.trades
     elif key == 'funding':
         return self.funding
     elif key == 'l2_book':
         return self.l2_book
     elif key == 'l3_book':
         return self.l3_book
     elif key == 'ticker':
         return self.ticker
Ejemplo n.º 8
0
 def __getattr__(self, attr):
     exch = self.lookup[attr.lower()]
     if not exch.mapped:
         load_exchange_pair_mapping(exch.ID)
         exch.mapped = True
     return exch
Ejemplo n.º 9
0
def test_bitfinex_pair_conversions():
    load_exchange_pair_mapping(BITFINEX)
    for _, pair in bitfinex_pairs().items():
        std = pair_exchange_to_std(pair)
        assert (pair == pair_std_to_exchange(std, BITFINEX))
Ejemplo n.º 10
0
    def __init__(self,
                 address,
                 pairs=None,
                 channels=None,
                 config=None,
                 callbacks=None,
                 max_depth=None,
                 book_interval=1000,
                 snapshot_interval=False,
                 checksum_validation=False,
                 cross_check=False,
                 origin=None):
        """
        max_depth: int
            Maximum number of levels per side to return in book updates
        book_interval: int
            Number of updates between snapshots. Only applicable when book deltas are enabled.
            Book deltas are enabled by subscribing to the book delta callback.
        snapshot_interval: bool/int
            Number of updates between snapshots. Only applicable when book delta is not enabled.
            Updates between snapshots are not delivered to the client
        checksum_validation: bool
            Toggle checksum validation, when supported by an exchange.
        cross_check: bool
            Toggle a check for a crossed book. Should not be needed on exchanges that support
            checksums or provide message sequence numbers.
        origin: str
            Passed into websocket connect. Sets the origin header.
        """
        self.hash = str(uuid.uuid4())
        self.uuid = f"{self.id}-{self.hash}"
        self.config = defaultdict(set)
        self.address = address
        self.book_update_interval = book_interval
        self.snapshot_interval = snapshot_interval
        self.cross_check = cross_check
        self.updates = defaultdict(int)
        self.do_deltas = False
        self.pairs = []
        self.channels = []
        self.max_depth = max_depth
        self.previous_book = defaultdict(dict)
        self.origin = origin
        self.checksum_validation = checksum_validation
        load_exchange_pair_mapping(self.id)

        if config is not None and (pairs is not None or channels is not None):
            raise ValueError("Use config, or channels and pairs, not both")

        if config is not None:
            for channel in config:
                chan = feed_to_exchange(self.id, channel)
                self.config[chan].update([
                    pair_std_to_exchange(pair, self.id)
                    for pair in config[channel]
                ])

        if pairs:
            self.pairs = [
                pair_std_to_exchange(pair, self.id) for pair in pairs
            ]
        if channels:
            self.channels = list(
                set([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),
            OPEN_INTEREST: Callback(None),
            LIQUIDATIONS: Callback(None),
            FUTURES_INDEX: Callback(None)
        }

        if callbacks:
            for cb_type, cb_func in callbacks.items():
                self.callbacks[cb_type] = cb_func
                if cb_type == BOOK_DELTA:
                    self.do_deltas = True

        for key, callback in self.callbacks.items():
            if not isinstance(callback, list):
                self.callbacks[key] = [callback]
Ejemplo n.º 11
0
 def get_active_symbols():
     load_exchange_pair_mapping(Upbit.id)
     symbols = []
     for data in Upbit.get_active_symbols_info():
         symbols.append(pair_exchange_to_std(data['market']))
     return symbols
Ejemplo n.º 12
0
def test_bitcoincom_pair_conversions():
    load_exchange_pair_mapping(BITCOINCOM)
    for _, pair in bitcoincom_pairs().items():
        std = pair_exchange_to_std(pair)
        assert (pair == pair_std_to_exchange(std, BITCOINCOM))
Ejemplo n.º 13
0
def test_blockchain_pair_conversions():
    load_exchange_pair_mapping(BLOCKCHAIN)
    for _, pair in blockchain_pairs().items():
        assert (pair_exchange_to_std(pair) == pair_std_to_exchange(
            pair, BLOCKCHAIN))
Ejemplo n.º 14
0
def test_gemini_pair_conversions():
    load_exchange_pair_mapping(GEMINI)
    for _, pair in gemini_pairs().items():
        std = pair_exchange_to_std(pair)
        assert (pair == pair_std_to_exchange(std, GEMINI))
Ejemplo n.º 15
0
def test_bitstamp_pair_conversions():
    load_exchange_pair_mapping(BITSTAMP)
    for _, pair in bitstamp_pairs().items():
        std = pair_exchange_to_std(pair)
        assert (pair == pair_std_to_exchange(std, BITSTAMP))
Ejemplo n.º 16
0
def test_hitbtc_pair_conversions():
    load_exchange_pair_mapping(HITBTC)
    for _, pair in hitbtc_pairs().items():
        std = pair_exchange_to_std(pair)
        assert (pair == pair_std_to_exchange(std, HITBTC))
Ejemplo n.º 17
0
 def __getitem__(self, key):
     exch = self.lookup[key.lower()]
     if not exch.mapped:
         load_exchange_pair_mapping(exch.ID)
         exch.mapped = True
     return exch
Ejemplo n.º 18
0
def test_poloniex_pair_conversions():
    load_exchange_pair_mapping(POLONIEX)
    for _, pair in poloniex_pairs().items():
        std = pair_exchange_to_std(pair)
        assert (pair == pair_std_to_exchange(std, POLONIEX))
Ejemplo n.º 19
0
def test_dsx_pair_conversion():
    load_exchange_pair_mapping(DSX)
    for _, pair in dsx_pairs().items():
        std = pair_exchange_to_std(pair)
        assert (pair == pair_std_to_exchange(std, DSX))
Ejemplo n.º 20
0
def test_coinbase_pair_conversions():
    load_exchange_pair_mapping(COINBASE)
    for _, pair in coinbase_pairs().items():
        assert (pair_exchange_to_std(pair) == pair_std_to_exchange(
            pair, COINBASE))