def create_supported_pairs_csv(): usd_prices = get_token_prices(token_utils.tokens()) # usd_prices = get_token_prices(tokens=set(sum(map(list, BAD_PAIRS), []))) filename = get_filename_base(prefix='totle_vs_agg_supported_tokens') with SavingsCSV(filename, fieldnames=CSV_FIELDS) as csv_writer: todo = [] combos = list(combinations(usd_prices, 2)) random.shuffle(combos) for base, quote in combos: # for base, quote in BAD_PAIRS: todo.append( (check_pair, base, quote, usd_prices[quote], csv_writer)) print(f"{todo[0:5]}") MAX_THREADS = 8 print( f"Queueing up {len(todo)} pairs for execution on {MAX_THREADS} workers" ) with concurrent.futures.ThreadPoolExecutor( max_workers=MAX_THREADS) as executor: futures_p = {executor.submit(*p): p for p in todo} for f in concurrent.futures.as_completed(futures_p): _, base, quote, *_ = futures_p[f] print(f"Completed: {base}/{quote}: result={f.result()}")
def get_best_tokens_for_dexs(top_n=100, day_volume=90): top_by_volume = top_tokens.top_tokens_by_volume(top_n, day_volume) top_by_market_cap = top_tokens.top_tokens_by_market_cap(top_n) overlap = set(top_by_market_cap) & set(top_by_volume) print( f"\n\nOverlap of top tokens by market cap and volume ({len(overlap)} tokens)", overlap) missing = [t for t in overlap if t not in token_utils.tokens()] print( f"\n\nFrom Top Volume/Top Market Cap token_utils is missing {sorted(missing)}" ) print(f"proabably because they are only available on IDEX") good = [t for t in overlap if t in token_utils.tokens()] print( f"\n\nList of Top Volume/Top Market Cap tokens available on DEXs {sorted(good)}" )
def test_basics(): print("\ntokens_json():", token_utils.tokens_json()) print("\ntokens():", token_utils.tokens()) print("\ntokens_decimals():", token_utils.token_decimals()) print("\nselect_tokens():", token_utils.select_tokens()) print("\ntradable_tokens():", token_utils.tradable_tokens()) print("\nTradable Tokens:", sorted(token_utils.tradable_tokens().keys())) print("\bUSD Tokens:", [ t for t in token_utils.tradable_tokens().keys() if t.find('USD') >= 0 ])
def test_find_duplicates(): print(f"\nlen(token_utils.tokens()) = {len(token_utils.tokens())}") print( f"\nlen(token_utils.tokens_by_addr()) = {len(token_utils.tokens_by_addr())}" ) for s, a in token_utils.tokens().items(): # if s.upper() != s: print(f"token_utils: {s.upper()} != {s}") lookup_sym = token_utils.tokens_by_addr().get(a) if not lookup_sym: print(f"{s} address {a} is not in addr") else: if s != lookup_sym: print(f"token_utils: addr->{lookup_sym} but tokens->{s}") tu_syms = [s for s in token_utils.tokens()] print( f"\nduplicate symbols in tokens(): {set([s for s in tu_syms if tu_syms.count(s) > 1])}" )
def top_tokens_not_tradable_on_totle(top_n=100, day_volume=90): tradable_tokens = token_utils.tradable_tokens() print(f"tradable_tokens={sorted(tradable_tokens.keys())}") print( f"Below is a list of tokens in the top {top_n} by {day_volume}-day volume that are not tradable on Totle" ) top_by_volume = list( enumerate(top_tokens.top_tokens_by_volume(top_n, day_volume))) # print(f"top_by_volume={top_by_volume}") for rank, token in top_by_volume: if not token in tradable_tokens: print(f"{rank:>3}. {token}") all_tokens = token_utils.tokens() print( f"Below is a list of tokens in the top {top_n} by {day_volume}-day volume that are not even in Totle's tokens API" ) for rank, token in top_by_volume: if not token in all_tokens: print(f"{rank:>3}. {token}")
import binance_client import huobi_client import kraken_client import totle_client import dexag_client import oneinch_client import token_utils # print(totle_client.get_pairs('USDC')) print(dexag_client.get_pairs()) ALL_CEX_CLIENTS = [binance_client, huobi_client, kraken_client] ALL_AGG_CLIENTS = [totle_client, dexag_client, oneinch_client] QUOTE = 'ETH' for c in ALL_CEX_CLIENTS + ALL_AGG_CLIENTS: overlap_pairs = [(b, q) for b, q in c.get_pairs(QUOTE) if b in token_utils.tokens()] overlap_tokens = sorted([b for b, q in overlap_pairs]) print(f"{c.name()} has {len(overlap_pairs)} overlap XXX/ETH pairs:", overlap_tokens) if 'DAI' in overlap_tokens: print(f"{c.name()} has DAI")
# https://api.dex.ag/price?from=DAI&to=ETH&toAmount=1.5&dex=ag -> price: 180 <- sell (OK) test_get_swap('ETH', from_token='DAI', to_amount=1.5) print(f"price ^ should be 180") # https://api.dex.ag/price?from=DAI&to=ETH&fromAmount=1.5&dex=ag -> price: 0.0055 <- sell (inverted) test_get_swap('ETH', from_token='DAI', from_amount=1.5) print(f"price ^ should be 180") exit(0) # test_get_quote('MKR', to_amount=1.0) test_get_swap('MKR', from_amount=1.0) # Buying CVC for 993.5942467706458 PAX test_get_quote('CVC', from_token='PAX', from_amount=994) test_get_quote('MKR', from_amount=1.0, dex='all') test_get_quote('ETHOS', from_amount=1.0) test_get_quote('ETHOS', from_amount=1, to_amount=200.0) test_get_quote('OMG', from_amount=1.0) test_get_quote('OMG', to_amount=200.0) test_get_quote('ETH', from_token='OMG', from_amount=1.0) test_get_quote('ETH', from_token='OMG', to_amount=200.0) test_get_quote('BAT', from_amount=100.0, dex='all', debug=True) test_which_tokens_supported(token_utils.tokens(), dex='0xMesh')