11import os
2- import datetime
32import ccxt .async_support as ccxt
43from typing import List
54from tqdm .auto import tqdm
98import octobot_commons .symbols as symbols
109import octobot_commons .constants as constants
1110
12- from triangular_arbitrage import REDIS_HOST_ENV , REDIS_PASSWORD_ENV , REDIS_PORT_ENV , REDIS_KEY_ENV , EXCHANGE_NAME_ENV
11+ from triangular_arbitrage import EXCHANGE_NAME_ENV
1312
1413@dataclass
1514class ShortTicker :
@@ -93,7 +92,7 @@ def get_opportunity_symbol(a, b):
9392 return best_triplet , best_profit
9493
9594async def get_exchange_data (exchange_name ):
96- exchange_class = getattr (ccxt , os . getenv ( EXCHANGE_NAME_ENV , exchange_name ) )
95+ exchange_class = getattr (ccxt , exchange_name )
9796 exchange = exchange_class ()
9897 tickers = await fetch_tickers (exchange )
9998 exchange_time = exchange .milliseconds ()
@@ -105,28 +104,7 @@ async def get_exchange_last_prices(exchange_name):
105104 last_prices = get_last_prices (exchange_time , tickers )
106105 return last_prices
107106
108- async def run_detection (exchange_name = "binance" ):
109- exchange = os .getenv (EXCHANGE_NAME_ENV , exchange_name )
110- last_prices = await get_exchange_last_prices (exchange )
111- best_opportunity , best_profit = get_best_opportunity (last_prices )
112- if os .getenv (REDIS_HOST_ENV , None ) is not None :
113- upload_result (best_opportunity , best_profit , exchange )
114-
115- return best_opportunity , best_profit , exchange
116-
117- def upload_result (best_opportunities , best_profit , exchange_id ):
118- import redis
119- redis_client = redis .Redis (
120- host = os .getenv (REDIS_HOST_ENV , None ),
121- port = os .getenv (REDIS_PORT_ENV , None ),
122- password = os .getenv (REDIS_PASSWORD_ENV , None ),
123- ssl = True
124- )
125-
126- data = {
127- 'best_opportunity' : [str (best_opportunity .symbol ) for best_opportunity in best_opportunities ],
128- 'best_profit' : best_profit ,
129- 'exchange_id' : exchange_id ,
130- 'timestamp' : datetime .datetime .utcnow ().timestamp ()
131- }
132- redis_client .json ().set (f"{ os .getenv (REDIS_KEY_ENV , None )} :{ exchange_id } " , '$' , data )
107+ async def run_detection (exchange_name ):
108+ last_prices = await get_exchange_last_prices (exchange_name )
109+ best_opportunity , best_profit = get_best_opportunity (last_prices )
110+ return best_opportunity , best_profit
0 commit comments