MCPcopy Index your code
hub / github.com/ccxt/ccxt / get_valid_symbol

Method get_valid_symbol

python/ccxt/test/tests_sync.py:470–502  ·  view source on GitHub ↗
(self, exchange, spot=True)

Source from the content-addressed store, hash-verified

468 return res
469
470 def get_valid_symbol(self, exchange, spot=True):
471 current_type_markets = self.get_markets_from_exchange(exchange, spot)
472 codes = ['BTC', 'ETH', 'XRP', 'LTC', 'BNB', 'DASH', 'DOGE', 'ETC', 'TRX', 'USDT', 'USDC', 'USD', 'GUSD', 'EUR', 'TUSD', 'CNY', 'JPY', 'BRL']
473 spot_symbols = ['BTC/USDT', 'BTC/USDC', 'BTC/USD', 'BTC/CNY', 'BTC/EUR', 'BTC/AUD', 'BTC/BRL', 'BTC/JPY', 'ETH/USDT', 'ETH/USDC', 'ETH/USD', 'ETH/CNY', 'ETH/EUR', 'ETH/AUD', 'ETH/BRL', 'ETH/JPY', 'EUR/USDT', 'EUR/USD', 'EUR/USDC', 'USDT/EUR', 'USD/EUR', 'USDC/EUR', 'BTC/ETH', 'ETH/BTC']
474 swap_symbols = ['BTC/USDT:USDT', 'BTC/USD:USDT', 'BTC/USDC:USDC', 'BTC/USD:USDC', 'BTC/USD:USD', 'ETH/USDT:USDT', 'ETH/USD:USDT', 'ETH/USDC:USDC', 'ETH/USD:USDC', 'ETH/USD:USD', 'BTC/USD:BTC', 'ETH/USD:ETH']
475 target_symbols = spot_symbols if spot else swap_symbols
476 symbol = self.get_test_symbol(exchange, spot, target_symbols)
477 # if symbols wasn't found from above hardcoded list, then try to locate any symbol which has our target hardcoded 'base' code
478 if symbol is None:
479 for i in range(0, len(codes)):
480 current_code = codes[i]
481 markets_array_for_current_code = exchange.filter_by(current_type_markets, 'base', current_code)
482 indexed_mkts = exchange.index_by(markets_array_for_current_code, 'symbol')
483 symbols_array_for_current_code = list(indexed_mkts.keys())
484 symbols_length = len(symbols_array_for_current_code)
485 if symbols_length:
486 symbol = self.get_test_symbol(exchange, spot, symbols_array_for_current_code)
487 break
488 # if there wasn't found any symbol with our hardcoded 'base' code, then just try to find symbols that are 'active'
489 if symbol is None:
490 active_markets = exchange.filter_by(current_type_markets, 'active', True)
491 active_symbols = []
492 for i in range(0, len(active_markets)):
493 active_symbols.append(active_markets[i]['symbol'])
494 symbol = self.get_test_symbol(exchange, spot, active_symbols)
495 if symbol is None:
496 values = list(current_type_markets.values())
497 values_length = len(values)
498 if values_length > 0:
499 first = values[0]
500 if first:
501 symbol = first['symbol']
502 return symbol
503
504 def test_exchange(self, exchange, provided_symbol=None):
505 spot_symbols = None

Callers 1

test_exchangeMethod · 0.95

Calls 7

get_test_symbolMethod · 0.95
filter_byMethod · 0.80
index_byMethod · 0.80
rangeFunction · 0.50
appendMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected