def symbol_mapping(cls, refresh=False) -> Dict: if Symbols.populated(cls.id) and not refresh: return Symbols.get(cls.id)[0] try: LOG.debug("%s: reading symbol information from %s", cls.id, cls.symbol_endpoint) if isinstance(cls.symbol_endpoint, list): data = [] for ep in cls.symbol_endpoint: data.append(cls.http_sync.read(ep, json=True, uuid=cls.id)) elif isinstance(cls.symbol_endpoint, dict): data = [] for input, output in cls.symbol_endpoint.items(): for d in cls.http_sync.read(input, json=True, uuid=cls.id): data.append( cls.http_sync.read(f"{output}{d}", json=True, uuid=cls.id)) else: data = cls.http_sync.read(cls.symbol_endpoint, json=True, uuid=cls.id) syms, info = cls._parse_symbol_data(data) Symbols.set(cls.id, syms, info) return syms except Exception as e: LOG.error("%s: Failed to parse symbol information: %s", cls.id, str(e), exc_info=True) raise
def symbol_mapping(cls, refresh=False) -> Dict: if Symbols.populated(cls.id) and not refresh: return Symbols.get(cls.id)[0] try: data = [] for ep in cls.rest_endpoints: addr = cls._symbol_endpoint_prepare(ep) if isinstance(addr, list): for ep in addr: LOG.debug("%s: reading symbol information from %s", cls.id, ep) data.append( cls.http_sync.read(ep, json=True, uuid=cls.id)) else: LOG.debug("%s: reading symbol information from %s", cls.id, addr) data.append( cls.http_sync.read(addr, json=True, uuid=cls.id)) syms, info = cls._parse_symbol_data( data if len(data) > 1 else data[0]) Symbols.set(cls.id, syms, info) return syms except Exception as e: LOG.error("%s: Failed to parse symbol information: %s", cls.id, str(e), exc_info=True) raise
def info(cls) -> Dict: """ Return information about the Exchange for REST and Websocket data channels """ symbols = cls.symbol_mapping() data = Symbols.get(cls.id)[1] data['symbols'] = list(symbols.keys()) data['channels'] = { 'rest': list(cls.rest_channels) if hasattr(cls, 'rest_channels') else [], 'websocket': list(cls.websocket_channels.keys()) } return data
def symbol_mapping(cls, symbol_separator='-', refresh=False) -> Dict: if Symbols.populated(cls.id) and not refresh: return Symbols.get(cls.id)[0] try: LOG.debug("%s: reading symbol information from %s", cls.id, cls.symbol_endpoint) data = {} for ep, quote_curr in cls.symbol_endpoint: data[quote_curr] = cls.http_sync.read(ep, json=True, uuid=cls.id) syms, info = cls._parse_symbol_data(data, symbol_separator) Symbols.set(cls.id, syms, info) return syms except Exception as e: LOG.error("%s: Failed to parse symbol information: %s", cls.id, str(e), exc_info=True) raise
def __init__(self, config=None, sandbox=False, subaccount=None, **kwargs): self.config = Config(config=config) self.sandbox = sandbox self.subaccount = subaccount keys = self.config[self.id.lower()] if self.subaccount is None else self.config[self.id.lower()][self.subaccount] self.key_id = keys.key_id self.key_secret = keys.key_secret self.key_passphrase = keys.key_passphrase self.account_name = keys.account_name self.ignore_invalid_instruments = self.config.ignore_invalid_instruments if not Symbols.populated(self.id): self.symbol_mapping() self.normalized_symbol_mapping, _ = Symbols.get(self.id) self.exchange_symbol_mapping = {value: key for key, value in self.normalized_symbol_mapping.items()}
def info(cls) -> dict: """ Return information about the Exchange - what trading symbols are supported, what data channels, etc key_id: str API key to query the feed, required when requesting supported coins/symbols. """ symbols = cls.symbol_mapping() data = Symbols.get(cls.id)[1] data['symbols'] = list(symbols.keys()) data['channels'] = [] for channel in (FUNDING, FUTURES_INDEX, LIQUIDATIONS, L2_BOOK, L3_BOOK, OPEN_INTEREST, MARKET_INFO, TICKER, TRADES, VOLUME, CANDLES): try: feed_to_exchange(cls.id, channel, silent=True) data['channels'].append(channel) except UnsupportedDataFeed: pass return data
def symbol_mapping(cls, refresh=False) -> Dict: if Symbols.populated(cls.id) and not refresh: return Symbols.get(cls.id)[0] try: data = {} for ep in cls.rest_endpoints[0].route('instruments'): ret = cls.http_sync.read(ep, json=True, uuid=cls.id) if 'BTC' in ep: data['BTC'] = ret else: data['KRW'] = ret syms, info = cls._parse_symbol_data(data) Symbols.set(cls.id, syms, info) return syms except Exception as e: LOG.error("%s: Failed to parse symbol information: %s", cls.id, str(e), exc_info=True) raise