websocket WIP 2

This commit is contained in:
2025-04-27 22:14:28 +03:00
parent 2a22392ee3
commit 31966e5561
3 changed files with 27 additions and 10 deletions

View File

@ -33,6 +33,8 @@ async def getClient(apiKey, apiSecret, testnet):
def handlePrice(message): def handlePrice(message):
if message['price'] == '':
print('meow')
print(message) print(message)
@ -41,10 +43,23 @@ def handleMessage(message):
async def socketStrategy(pair: str, params): async def socketStrategy(pair: str, params):
print('Starting strategy with ', pair)
# 'highEnd',
# 'lowEnd',
# 'highBreak',
# 'lowBreak',
# 'netLevelsAmount',
# 'takeDelta',
# 'stopDelta',
# 'orderSize'
paramsDict = await arbus.parseParams(params)
ws = WebSocket( ws = WebSocket(
testnet = options.testnet, testnet = options.testnet,
channel_type = options.category, channel_type = options.category,
callback = handleMessage # callback = handleMessage
) )
ws_private = WebSocket( ws_private = WebSocket(
@ -52,13 +67,15 @@ async def socketStrategy(pair: str, params):
channel_type = "private", channel_type = "private",
api_key = credentials.api_key, api_key = credentials.api_key,
api_secret = credentials.api_secret, api_secret = credentials.api_secret,
callback = handleMessage # callback = handleMessage
# trace_logging = True, # trace_logging = True
) )
print(ws.is_connected())
ws.ticker_stream( ws.ticker_stream(
symbol = pair, symbol = pair,
callback = handleMessage callback = handlePrice
) )
i = 0 i = 0
@ -66,6 +83,8 @@ async def socketStrategy(pair: str, params):
while t: while t:
t = await arbus.checkPair(pair) t = await arbus.checkPair(pair)
if t != 1: if t != 1:
# ws.exit()
# ws_private.exit()
break break
await asyncio.sleep(options.loopSleepTime) await asyncio.sleep(options.loopSleepTime)
i += 1 i += 1
@ -104,13 +123,10 @@ async def strategy(client: HTTP, pair: str, params):
marketUnit = 'quoteCoin' marketUnit = 'quoteCoin'
) )
print(r2, '\n') print(r2, '\n')
if r2['retMsg'] == 'OK': if r2['retMsg'] == 'OK':
print('Order placed succesfully!') print('Order placed succesfully!')
await asyncio.sleep(20) await asyncio.sleep(20)
i += 1 i += 1

View File

@ -107,8 +107,8 @@ async def capture_params(message: Message, state: FSMContext):
if client == -1: if client == -1:
msg_text = (f'Аутентификация не удалась, сообщите администратору если увидете данное сообщение.') msg_text = (f'Аутентификация не удалась, сообщите администратору если увидете данное сообщение.')
else: else:
asyncio.create_task(bybit.socketStrategy( data.get("pair"), data.get("params"))) asyncio.create_task(bybit.socketStrategy(data.get("pair"), data.get("params")))
asyncio.create_task(bybit.strategy(client, data.get("pair"), data.get("params"))) # asyncio.create_task(bybit.strategy(client, data.get("pair"), data.get("params")))
msg_text = (f'Вы запустили стратегию на паре <b>{data.get("pair")}</b> с данными параметрами:\n<b>{data.get("params")}</b>\n') msg_text = (f'Вы запустили стратегию на паре <b>{data.get("pair")}</b> с данными параметрами:\n<b>{data.get("params")}</b>\n')
elif t == -1: elif t == -1:
msg_text = (f'Параметры введены в неверном формате, пожалуйста начните заново.') msg_text = (f'Параметры введены в неверном формате, пожалуйста начните заново.')

View File

@ -11,7 +11,8 @@ leverage = 1 # Leverage
notification = 1 # Telegram notifications (not currently supported) notification = 1 # Telegram notifications (not currently supported)
loopSleepTime = 20 # Time passing between loops/checks marketBuyRange = 0.5
loopSleepTime = 1 # Time passing between loops/checks
paramsLines = ['highEnd', paramsLines = ['highEnd',
'lowEnd', 'lowEnd',