def _parse_symbol_data(cls, data: list) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) currencies = [] for entry in data: for e in entry['result']: base = e['base_currency'] if base not in currencies: currencies.append(base) quote = e['quote_currency'] stype = e['kind'] if e[ 'settlement_period'] != 'perpetual' else PERPETUAL otype = e.get('option_type') strike_price = e.get('strike') strike_price = int(strike_price) if strike_price else None expiry = e['expiration_timestamp'] / 1000 s = Symbol(base, quote, type=FUTURES if stype == 'future' else stype, option_type=otype, strike_price=strike_price, expiry_date=expiry) ret[s.normalized] = e['instrument_name'] info['tick_size'][s.normalized] = e['tick_size'] info['instrument_type'][s.normalized] = stype for currency in currencies: s = Symbol(currency, currency, type=CURRENCY) ret[s.normalized] = currency info['instrument_type'][s.normalized] = CURRENCY return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) normalized_currencies = { 'USD': 'USDT', 'USDB': 'USD', } for symbol in data: # Filter out pairs ending in _BQX # From Bequant support: "BQX pairs are our 0 taker fee pairs that are only to be used by our retail broker clients (the BQX is to differentiate them from the traditional pairs)" if symbol['id'][-4:] == '_BQX': continue base_currency = normalized_currencies[ symbol['baseCurrency']] if symbol[ 'baseCurrency'] in normalized_currencies else symbol[ 'baseCurrency'] quote_currency = normalized_currencies[ symbol['quoteCurrency']] if symbol[ 'quoteCurrency'] in normalized_currencies else symbol[ 'quoteCurrency'] s = Symbol(base_currency, quote_currency) ret[s.normalized] = symbol['id'] info['tick_size'][s.normalized] = symbol['tickSize'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: _kraken_futures_product_type = { 'FI': 'Inverse Futures', 'FV': 'Vanilla Futures', 'PI': 'Perpetual Inverse Futures', 'PV': 'Perpetual Vanilla Futures', 'IN': 'Real Time Index', 'RR': 'Reference Rate', } ret = {} info = defaultdict(dict) data = data['instruments'] for entry in data: if not entry['tradeable']: continue ftype, symbol = entry['symbol'].upper().split("_", maxsplit=1) stype = PERPETUAL expiry = None if "_" in symbol: stype = FUTURES symbol, expiry = symbol.split("_") symbol = symbol.replace('XBT', 'BTC') base, quote = symbol[:3], symbol[3:] s = Symbol(base, quote, type=stype, expiry_date=expiry) info['tick_size'][s.normalized] = entry['tickSize'] info['contract_size'][s.normalized] = entry['contractSize'] info['underlying'][s.normalized] = entry['underlying'] info['product_type'][ s.normalized] = _kraken_futures_product_type[ftype] info['instrument_type'][s.normalized] = stype ret[s.normalized] = entry['symbol'] return ret, info
def _parse_symbol_data(cls, data: list) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for entry in data: for e in entry['data']: expiry = None otype = None stype = e['instType'].lower() strike = None if stype == SPOT: base = e['baseCcy'] quote = e['quoteCcy'] elif stype == FUTURES: base, quote, expiry = e['instId'].split("-") elif stype == OPTION: base, quote, expiry, strike, otype = e['instId'].split("-") otype = PUT if otype == 'P' else CALL elif stype == 'swap': # this is a perpetual swap (aka perpetual futures contract), not a real swap stype = PERPETUAL base, quote, _ = e['instId'].split("-") s = Symbol(base, quote, expiry_date=expiry, type=stype, option_type=otype, strike_price=strike) ret[s.normalized] = e['instId'] info['tick_size'][s.normalized] = e['tickSz'] info['instrument_type'][s.normalized] = stype return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for symbol in data['symbols']: if symbol.get('status', 'TRADING') != "TRADING": continue if symbol.get('contractStatus', 'TRADING') != "TRADING": continue expiration = None stype = SPOT if symbol.get('contractType') == 'PERPETUAL': stype = PERPETUAL elif symbol.get('contractType') in ('CURRENT_QUARTER', 'NEXT_QUARTER'): stype = FUTURES expiration = symbol['symbol'].split("_")[1] s = Symbol(symbol['baseAsset'], symbol['quoteAsset'], type=stype, expiry_date=expiration) ret[s.normalized] = symbol['symbol'] info['tick_size'][s.normalized] = symbol['filters'][0]['tickSize'] info['instrument_type'][s.normalized] = stype return ret, info
def _parse_symbol_data(cls, data: Union[List, Dict]) -> Tuple[Dict, Dict]: """ contract types umcbl USDT Unified Contract dmcbl Quanto Swap Contract sumcbl USDT Unified Contract Analog disk (naming makes no sense, but these are basically testnet coins) sdmcbl Quanto Swap Contract Analog disk (naming makes no sense, but these are basically testnet coins) """ ret = {} info = defaultdict(dict) if isinstance(data, dict): data = [data] for d in data: for entry in d['data']: """ Spot { "baseCoin":"ALPHA", "makerFeeRate":"0.001", "maxTradeAmount":"0", "minTradeAmount":"2", "priceScale":"4", "quantityScale":"4", "quoteCoin":"USDT", "status":"online", "symbol":"ALPHAUSDT_SPBL", "symbolName":"ALPHAUSDT", "takerFeeRate":"0.001" } """ if "symbolName" in entry: sym = Symbol(entry['baseCoin'], entry['quoteCoin']) ret[sym.normalized] = entry['symbolName'] else: sym = Symbol(entry['baseCoin'], entry['quoteCoin'], type=PERPETUAL) ret[sym.normalized] = entry['symbol'] info['instrument_type'][sym.normalized] = sym.type info['is_quanto'][ sym.normalized] = 'dmcbl' in entry['symbol'].lower() return ret, info
def _parse_symbol_data(cls, data: list) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for entry in data: if entry['code'] != 0: raise ValueError('%s - Failed to collect instrument data - %s', cls.id, entry['message']) for mapping in entry['data']: if 'category' in mapping: expiry = None strike = None otype = None if mapping['category'] == 'option': stype = OPTION strike = int(float(mapping['strike_price'])) expiry = cls.timestamp_normalize( mapping['expiration_at']) otype = mapping['option_type'] elif mapping['category'] == 'future': if 'PERPETUAL' in mapping['instrument_id']: stype = PERPETUAL else: stype = FUTURES expiry = cls.timestamp_normalize( mapping['expiration_at']) s = Symbol(mapping['base_currency'], mapping['quote_currency'], type=stype, option_type=otype, expiry_date=expiry, strike_price=strike) ret[s.normalized] = mapping['instrument_id'] info['instrument_type'][s.normalized] = stype else: # Spot s = Symbol(mapping['base_currency'], mapping['quote_currency'], type=SPOT) ret[s.normalized] = mapping['pair'] info['instrument_type'][s.normalized] = SPOT return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = {'instrument_type': {}} for entry in data: quote, base = entry['market'].split("-") s = Symbol(base, quote) ret[s.normalized] = entry['market'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for entry in data['result']['instruments']: sym = Symbol(entry['base_currency'], entry['quote_currency']) info['instrument_type'][sym.normalized] = sym.type ret[sym.normalized] = entry['instrument_name'] return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for e in data: s = Symbol(e['base_currency'], e['quote_currency']) ret[s.normalized] = e['instrument_id'] info['tick_size'][s.normalized] = e['tick_size'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: info = {'instrument_type': {}} ret = {} for e in data: if e['status'] != 'ONLINE': continue s = Symbol(e['baseCurrencySymbol'], e['quoteCurrencySymbol']) ret[s.normalized] = e['symbol'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: list) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for entry in data: sym = Symbol(entry['base_currency'], entry['quote_currency']) info['tick_size'][sym.normalized] = entry['quote_increment'] info['instrument_type'][sym.normalized] = sym.type ret[sym.normalized] = entry['id'] return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = {'instrument_type': {}} for entry in data: if entry["trade_status"] != "tradable": continue s = Symbol(entry['base'], entry['quote']) ret[s.normalized] = entry['id'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = {'instrument_type': {}} for symbol in data: cls._channel_map[data[symbol]['id']] = symbol std = symbol.replace("STR", "XLM") quote, base = std.split("_") s = Symbol(base, quote) ret[s.normalized] = symbol info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: list) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) bases, quotes = data for base in bases: for quote in quotes: sym = Symbol(base.upper().replace('XBT', 'BTC'), quote.upper()) info['instrument_type'][sym.normalized] = sym.type ret[sym.normalized] = f"{base.lower()}-{quote.lower()}" return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = {'tick_size': {}, 'instrument_type': {}} for symbol in data['data']: if not symbol['enableTrading']: continue s = Symbol(symbol['baseCurrency'], symbol['quoteCurrency']) info['tick_size'][s.normalized] = symbol['priceIncrement'] ret[s.normalized] = symbol['symbol'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = {'instrument_type': {}} exchange = [key.upper() for key in data.keys()] for sym in exchange: b, q = sym.split("_") s = Symbol(b, q) ret[s.normalized] = sym info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: info = {'instrument_type': {}} ret = {} for entry in data: if entry['status'] != 'open': continue base, quote = entry['symbol'].split("-") s = Symbol(base, quote) ret[s.normalized] = entry['symbol'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = {'instrument_type': {}} # doc: https://docs-en.probit.com/reference-link/market for entry in data['data']: if entry['closed']: continue s = Symbol(entry['base_currency_id'], entry['quote_currency_id']) ret[s.normalized] = entry['id'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for symbol in data: if symbol['status'] == 'closed': continue s = Symbol(symbol['base_currency'], symbol['quote_currency']) ret[s.normalized] = symbol['symbol'] info['tick_size'][s.normalized] = symbol['tick_size'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for e in data['data']: # Pricing is all in USD, see https://huobiglobal.zendesk.com/hc/en-us/articles/360000113102-Introduction-of-Huobi-Futures s = Symbol(e['symbol'], 'USD', type=FUTURES, expiry_date=e['contract_code'].replace(e['symbol'], '')) ret[s.normalized] = e['contract_code'] info['tick_size'][s.normalized] = e['price_tick'] info['instrument_type'][s.normalized] = FUTURES return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for e in data['data']: base, quote = e['contract_code'].split("-") # Perpetual futures contract == perpetual swap s = Symbol(base, quote, type=PERPETUAL) ret[s.normalized] = e['contract_code'] info['tick_size'][e['contract_code']] = e['price_tick'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for symbol, entry in data['markets'].items(): if entry['status'] != 'ONLINE': continue stype = entry['type'].lower() s = Symbol(entry['baseAsset'], entry['quoteAsset'], type=stype) ret[s.normalized] = symbol info['tick_size'][s.normalized] = entry['tickSize'] info['instrument_type'][s.normalized] = stype return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for entry in data['data']: # Only "Normal" status symbols are tradeable if entry['status'] == 'Normal': s = Symbol(entry['baseAsset'], entry['quoteAsset']) ret[s.normalized] = entry['symbol'] info['tick_size'][s.normalized] = entry['tickSize'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: list) -> Tuple[Dict, Dict]: # https://docs.bitfinex.com/docs/ws-general#supported-pairs ret = {} info = {'instrument_type': {}} pairs = data[0][0] currencies = data[1][0] perpetuals = data[2][0] for c in currencies: c = c.replace('BCHN', 'BCH') # Bitfinex uses BCHN, other exchanges use BCH c = c.replace('UST', 'USDT') s = Symbol(c, c, type=CURRENCY) ret[s.normalized] = "f" + c info['instrument_type'][s.normalized] = CURRENCY for p in pairs: norm = p.replace('BCHN', 'BCH') norm = norm.replace('UST', 'USDT') if ':' in norm: base, quote = norm.split(":") else: base, quote = norm[:3], norm[3:] s = Symbol(base, quote) ret[s.normalized] = "t" + p info['instrument_type'][s.normalized] = s.type for f in perpetuals: norm = f.replace('BCHN', 'BCH') norm = norm.replace('UST', 'USDT') base, quote = norm.split(':') # 'ALGF0:USTF0' base, quote = base[:-2], quote[:-2] s = Symbol(base, quote, type=PERPETUAL) ret[s.normalized] = "t" + f info['instrument_type'][s.normalized] = s.type return ret, info
def main(): config = {'log': {'filename': 'demo.log', 'level': 'DEBUG', 'disabled': False}} # the config will be automatically passed into any exchanges set up by string. Instantiated exchange objects would need to pass the config in manually. f = FeedHandler(config=config) f.add_feed(FMFW(symbols=['BTC-USDT'], channels=[CANDLES, L2_BOOK, TRADES, TICKER], callbacks={CANDLES: candle_callback, TICKER: ticker, L2_BOOK: book, TRADES: trade})) f.add_feed(AscendEX(symbols=['XRP-USDT'], channels=[L2_BOOK, TRADES], callbacks={L2_BOOK: book, TRADES: trade})) f.add_feed(Bequant(symbols=['BTC-USDT'], channels=[L2_BOOK], callbacks={L2_BOOK: book, TRADES: trade, TICKER: ticker, CANDLES: candle_callback})) pairs = Binance.symbols()[:1] f.add_feed(Binance(symbols=pairs, channels=[L2_BOOK], callbacks={L2_BOOK: book, CANDLES: candle_callback, TRADES: trade, TICKER: ticker})) pairs = BinanceFutures.symbols()[:30] f.add_feed(BinanceFutures(symbols=pairs, channels=[TRADES, OPEN_INTEREST, FUNDING, LIQUIDATIONS], callbacks={TRADES: trade, OPEN_INTEREST: oi, FUNDING: funding, LIQUIDATIONS: liquidations})) f.add_feed(BinanceUS(symbols=BinanceUS.symbols()[:2], channels=[TRADES, L2_BOOK], callbacks={L2_BOOK: book, TRADES: trade})) f.add_feed(Bitfinex(symbols=['BTC-USDT'], channels=[L3_BOOK], callbacks={L3_BOOK: book, TICKER: ticker, TRADES: trade})) f.add_feed(Bitflyer(symbols=['BTC-JPY'], channels=[TICKER, TRADES, L2_BOOK], callbacks={L2_BOOK: book, TICKER: ticker, TRADES: trade})) f.add_feed(Bithumb(symbols=['BTC-KRW'], channels=[TRADES], callbacks={TRADES: trade})) f.add_feed(Bitmex(timeout=5000, symbols=Bitmex.symbols(), channels=[LIQUIDATIONS], callbacks={LIQUIDATIONS: liquidations, OPEN_INTEREST: oi, FUNDING: funding})) f.add_feed(Bitstamp(channels=[L2_BOOK, TRADES], symbols=['BTC-USD'], callbacks={L2_BOOK: book, TRADES: trade})) f.add_feed(Bittrex(subscription={L2_BOOK: ['BTC-USDT'], CANDLES: ['BTC-USDT', 'ETH-USDT'], TRADES: ['ETH-USDT', 'BTC-USDT'], TICKER: ['ETH-USDT']}, callbacks={CANDLES: candle_callback, L2_BOOK: book, TICKER: ticker, TRADES: trade})) f.add_feed(BLOCKCHAIN, subscription={L2_BOOK: ['BTC-USD'], TRADES: Blockchain.symbols()}, callbacks={L2_BOOK: book, TRADES: trade}) f.add_feed(Bybit(symbols=['BTC-USDT-PERP', 'BTC-USD-PERP'], channels=[INDEX, FUNDING, OPEN_INTEREST], callbacks={OPEN_INTEREST: oi, INDEX: index, FUNDING: funding})) f.add_feed(Bybit(candle_closed_only=True, symbols=['BTC-USDT-PERP', 'BTC-USD-PERP'], channels=[CANDLES, TRADES, L2_BOOK], callbacks={CANDLES: candle_callback, TRADES: trade, L2_BOOK: book})) f.add_feed(Coinbase(subscription={L2_BOOK: ['BTC-USD'], TRADES: ['BTC-USD'], TICKER: ['BTC-USD']}, callbacks={TRADES: trade, L2_BOOK: book, TICKER: ticker})) f.add_feed(Coinbase(subscription={L3_BOOK: ['LTC-USD']}, callbacks={L3_BOOK: book})) f.add_feed(Deribit(symbols=['BTC-USD-PERP'], channels=[L2_BOOK, TRADES, TICKER, FUNDING, OPEN_INTEREST, LIQUIDATIONS], callbacks={TRADES: trade, L2_BOOK: book, TICKER: ticker, OPEN_INTEREST: oi, FUNDING: funding, LIQUIDATIONS: liquidations})) f.add_feed(dYdX(symbols=dYdX.symbols(), channels=[L2_BOOK, TRADES], callbacks={TRADES: trade, L2_BOOK: book})) f.add_feed(FTX(checksum_validation=True, symbols=['ALGO-USD-PERP'], channels=[TICKER, TRADES, L2_BOOK, LIQUIDATIONS, OPEN_INTEREST, FUNDING], callbacks={TICKER: ticker, TRADES: trade, OPEN_INTEREST: oi, FUNDING: funding, LIQUIDATIONS: liquidations, L2_BOOK: book})) f.add_feed(Gateio(symbols=['BTC-USDT', 'ETH-USDT'], channels=[L2_BOOK, CANDLES, TRADES, TICKER], callbacks={CANDLES: candle_callback, L2_BOOK: book, TRADES: trade, TICKER: ticker})) f.add_feed(GEMINI, subscription={L2_BOOK: ['BTC-USD', 'ETH-USD'], TRADES: ['ETH-USD', 'BTC-USD']}, callbacks={TRADES: trade, L2_BOOK: book}) f.add_feed(HitBTC(channels=[TRADES], symbols=['BTC-USDT'], callbacks={TRADES: trade})) f.add_feed(Huobi(symbols=['BTC-USDT'], channels=[CANDLES, TRADES, L2_BOOK], callbacks={TRADES: trade, L2_BOOK: book, CANDLES: candle_callback})) f.add_feed(HuobiDM(subscription={L2_BOOK: HuobiDM.symbols()[:2], TRADES: HuobiDM.symbols()[:10]}, callbacks={TRADES: trade, L2_BOOK: book})) pairs = ['BTC-USD-PERP', 'ETH-USD-PERP', 'EOS-USD-PERP', 'BCH-USD-PERP', 'BSV-USD-PERP', 'LTC-USD-PERP'] f.add_feed(HuobiSwap(symbols=pairs, channels=[TRADES, L2_BOOK, FUNDING], callbacks={FUNDING: funding, TRADES: trade, L2_BOOK: book})) f.add_feed(KrakenFutures(symbols=KrakenFutures.symbols(), channels=[L2_BOOK, TICKER, TRADES, OPEN_INTEREST, FUNDING], callbacks={L2_BOOK: book, FUNDING: funding, OPEN_INTEREST: oi, TRADES: trade, TICKER: ticker})) f.add_feed(Kraken(config='config.yaml', checksum_validation=True, subscription={L2_BOOK: ['BTC-USD'], TRADES: ['BTC-USD'], CANDLES: ['BTC-USD'], TICKER: ['ETH-USD']}, callbacks={L2_BOOK: book, CANDLES: candle_callback, TRADES: trade, TICKER: ticker})) f.add_feed(KuCoin(symbols=['BTC-USDT', 'ETH-USDT'], channels=[TICKER, TRADES, CANDLES], callbacks={CANDLES: candle_callback, TICKER: ticker, TRADES: trade})) f.add_feed(OKX(checksum_validation=True, symbols=['BTC-USDT-PERP'], channels=[TRADES, TICKER, FUNDING, OPEN_INTEREST, LIQUIDATIONS, L2_BOOK], callbacks={L2_BOOK: book, TICKER: ticker, LIQUIDATIONS: liquidations, FUNDING: funding, OPEN_INTEREST: oi, TRADES: trade})) f.add_feed(OKCoin(checksum_validation=True, symbols=['BTC-USD'], channels=[TRADES, TICKER, L2_BOOK], callbacks={L2_BOOK: book, TICKER: ticker, TRADES: trade})) f.add_feed(Phemex(symbols=[Symbol('BTC', 'USD', type=PERPETUAL)], channels=[L2_BOOK, CANDLES, TRADES], callbacks={TRADES: trade, L2_BOOK: book, CANDLES: candle_callback})) f.add_feed(Poloniex(symbols=['BTC-USDT'], channels=[TICKER, TRADES], callbacks={TICKER: ticker, TRADES: trade})) f.add_feed(Poloniex(subscription={TRADES: ['DOGE-BTC'], L2_BOOK: ['LTC-BTC']}, callbacks={TRADES: trade, L2_BOOK: book})) f.add_feed(Probit(subscription={TRADES: ['BTC-USDT'], L2_BOOK: ['BTC-USDT']}, callbacks={TRADES: trade, L2_BOOK: book})) f.add_feed(Upbit(subscription={TRADES: ['BTC-USDT'], L2_BOOK: ['BTC-USDT']}, callbacks={TRADES: trade, L2_BOOK: book})) f.add_feed(CryptoDotCom(symbols=['BTC-USDT'], channels=[L2_BOOK, TICKER, CANDLES, TRADES], callbacks={TRADES: trade, CANDLES: candle_callback, TICKER: ticker, L2_BOOK: book})) f.add_feed(Delta(symbols=['BTC-USDT', 'BTC-USDT-PERP'], channels=[L2_BOOK, TRADES, CANDLES], callbacks={TRADES: trade, CANDLES: candle_callback, L2_BOOK: book})) f.add_feed(BitDotCom(config="config.yaml", sandbox=True, symbols=['BTC-USDT', 'BTC-USD-PERP'], channels=[TICKER, TRADES, L2_BOOK], callbacks={TRADES: trade, L2_BOOK: book, TICKER: ticker})) f.add_feed(Bitget(config='config.yaml', symbols=['BTC-USD-PERP', 'BTC-USDT-PERP', 'BTC-USDT'], channels=[L2_BOOK, TICKER, CANDLES, TRADES], callbacks={CANDLES: candle_callback, TRADES: trade, L2_BOOK: book, TICKER: ticker})) f.add_feed(IndependentReserve(symbols=['BTC-USD'], channels=[L3_BOOK, TRADES], callbacks={TRADES: trade, L3_BOOK: book})) f.run()
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = {'instrument_type': {}} for quote_curr, response in data.items(): bases = response['data'] for base_curr in bases.keys(): if base_curr == 'date': continue s = Symbol(base_curr, quote_curr) ret[s.normalized] = f"{base_curr}_{quote_curr}" info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = {'instrument_type': {}} for e in data['data']: if e['state'] == 'offline': continue base, quote = e['base-currency'].upper( ), e['quote-currency'].upper() s = Symbol(base, quote) ret[s.normalized] = e['symbol'] info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = {'instrument_type': {}} for d in data: if d['trading'] != 'Enabled': continue base, quote = d['name'].split("/") s = Symbol(base, quote) symbol = d['url_symbol'] ret[s.normalized] = symbol info['instrument_type'][s.normalized] = s.type return ret, info
def _parse_symbol_data(cls, data: dict) -> Tuple[Dict, Dict]: ret = {} info = defaultdict(dict) for entry in data['result']: quote = entry['quoting_asset']['symbol'] base = entry['underlying_asset']['symbol'] if entry['contract_type'] == 'spot': sym = Symbol(base, quote, type=SPOT) elif entry['contract_type'] == 'perpetual_futures': sym = Symbol(base, quote, type=PERPETUAL) elif entry['contract_type'] == 'futures' or entry[ 'contract_type'] == 'move_options': sym = Symbol(base, quote, type=FUTURES, expiry_date=entry['settlement_time']) elif entry['contract_type'] == 'call_options' or entry[ 'contract_type'] == 'put_options': otype = PUT if entry['contract_type'].startswith( 'put') else CALL sym = Symbol(base, quote, type=OPTION, strike_price=entry['strike_price'], expiry_date=entry['settlement_time'], option_type=otype) elif entry['contract_type'] in {'interest_rate_swaps', 'spreads'}: continue else: raise ValueError(entry['contract_type']) info['instrument_type'][sym.normalized] = sym.type info['tick_size'][sym.normalized] = entry['tick_size'] ret[sym.normalized] = entry['symbol'] return ret, info