diff --git a/src/bybit.py b/src/bybit.py index 9494ea1..8aa2764 100644 --- a/src/bybit.py +++ b/src/bybit.py @@ -2,6 +2,7 @@ import time import asyncio from pybit.unified_trading import HTTP +from pybit.unified_trading import WebSocket import options import credentials @@ -31,6 +32,49 @@ async def getClient(apiKey, apiSecret, testnet): return -1 +def handlePrice(message): + print(message) + + +def handleMessage(message): + print(message) + + +async def socketStrategy(pair: str, params): + ws = WebSocket( + testnet = options.testnet, + channel_type = options.category, + callback = handleMessage + ) + + ws_private = WebSocket( + testnet = options.testnet, + channel_type = "private", + api_key = credentials.api_key, + api_secret = credentials.api_secret, + callback = handleMessage + # trace_logging = True, + ) + + ws.ticker_stream( + symbol = pair, + callback = handleMessage + ) + + i = 0 + t = await arbus.checkPair(pair) + while t: + t = await arbus.checkPair(pair) + if t != 1: + break + await asyncio.sleep(options.loopSleepTime) + i += 1 + + print('Ending strategy with ', pair) + print('Ended on the iteration number ', i) + return i + + async def strategy(client: HTTP, pair: str, params): startTime = time.time() print('Starting strategy with ', pair) diff --git a/src/main.py b/src/main.py index d819fbc..354cf54 100644 --- a/src/main.py +++ b/src/main.py @@ -107,6 +107,7 @@ async def capture_params(message: Message, state: FSMContext): if client == -1: msg_text = (f'Аутентификация не удалась, сообщите администратору если увидете данное сообщение.') else: + asyncio.create_task(bybit.socketStrategy( data.get("pair"), data.get("params"))) asyncio.create_task(bybit.strategy(client, data.get("pair"), data.get("params"))) msg_text = (f'Вы запустили стратегию на паре {data.get("pair")} с данными параметрами:\n{data.get("params")}\n') elif t == -1: diff --git a/src/options.py b/src/options.py index 525dbed..6556af7 100644 --- a/src/options.py +++ b/src/options.py @@ -1,15 +1,17 @@ url = 'https://testnet.binance.vision/api' # API url testnet = True # Use testnet or not + + pairSymbol = 'ETHUSDT' # Trading pair mainSymbol = 'USDT' # Balance asset timeScape = '15m' # Candle length -category = 'spot' +category = 'linear' leverage = 1 # Leverage -notification = 1 # Telegram notifications +notification = 1 # Telegram notifications (not currently supported) -loopSleepTime = 2 # Time passing between loops/checks +loopSleepTime = 20 # Time passing between loops/checks paramsLines = ['highEnd', 'lowEnd',