def compare_init(): counts = 200 setting = Settings.objects.all()[0] percent = setting.market_percent / 100 * setting.market_koef currency = setting.currency currencyUSD = setting.currency_usd all_tokens = [] isTD = True while isTD: if len(gv.replica_idex) > 0 and len(gv.all_compared_tokens) > 0: isTD = False for token in gv.all_compared_tokens: if 'idex' not in token[2]: all_tokens.append(token) else: isTD = True time.sleep(1) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop = asyncio.get_event_loop() loop.set_default_executor( concurrent.futures.ThreadPoolExecutor(max_workers=counts)) all_result = loop.run_until_complete( make_compare(gv.replica_idex, all_tokens, currency, currencyUSD, percent)) loop.close() compare_result = rprep(all_result=all_result, exchanger='idex').result() print('idex_result', compare_result) ProfitExchanges.objects.filter( Q(buy_name__icontains='idex') | (Q(sell_name__icontains='idex') & ~Q(buy_name__icontains='hotbit') & ~Q(buy_name__icontains='hitbit') & ~Q(buy_name__icontains='bilaxy'))).delete() with transaction.atomic(): for result in compare_result: pair = ProfitExchanges(pair=result['pair'], buy_name=result['buy_name'], buy=result['buy'], buy_ask=result['buy_ask'], buyurl=result['buyurl'], sell_name=result['sell_name'], sell=result['sell'], sell_bid=result['sell_bid'], percent=result['percent'], tokenid=result['tokenid'], sellurl=result['sellurl'], sell_symbol=result['sell_symbol'], contract=result['contract']) pair.save() return compare_result
def hotbit_profits(): # print('hotbit_profits start', datetime.now()) setting = Settings.objects.all()[0] percent = setting.market_percent / 100 * setting.market_koef isTD = True hotbit_tokens = [] all_tokens = [] while isTD: if len(ex_serv.all_compared_tokens) > 0: # print(len(ex_serv.all_compared_tokens), datetime.now()) for token in ex_serv.all_compared_tokens: if 'hotbit' in token[2]: hotbit_tokens.append(token) else: all_tokens.append(token) isTD = False # print(len(hotbit_tokens)) else: isTD = True time.sleep(1) get_eth_btc() currency = Settings.objects.all().values()[0]['currency'] currencyUSD = Settings.objects.all().values()[0]['currency_usd'] all_result = [] xlen = math.ceil(len(hotbit_tokens) / 100) for i in range(xlen): parts_hotbit_tokens = [] for hi, htoken in enumerate(hotbit_tokens): if 100 * i <= hi < 100 * (i + 1): parts_hotbit_tokens.append(htoken) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop = asyncio.get_event_loop() loop.set_default_executor( concurrent.futures.ThreadPoolExecutor(max_workers=100)) # print('hotbit loop start', datetime.now()) init_result = loop.run_until_complete( init_compare(parts_hotbit_tokens, all_tokens, percent, currency, currencyUSD)) loop.close() # print('hotbit loop end', datetime.now()) all_result.extend(init_result) # print('hotbit_profits end', datetime.now()) compare_result = rprep(all_result=all_result, exchanger='hotbit').result() return compare_result