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):
if message['price'] == '':
print('meow')
print(message)
@ -41,10 +43,23 @@ def handleMessage(message):
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(
testnet = options.testnet,
channel_type = options.category,
callback = handleMessage
# callback = handleMessage
)
ws_private = WebSocket(
@ -52,13 +67,15 @@ async def socketStrategy(pair: str, params):
channel_type = "private",
api_key = credentials.api_key,
api_secret = credentials.api_secret,
callback = handleMessage
# trace_logging = True,
# callback = handleMessage
# trace_logging = True
)
print(ws.is_connected())
ws.ticker_stream(
symbol = pair,
callback = handleMessage
callback = handlePrice
)
i = 0
@ -66,6 +83,8 @@ async def socketStrategy(pair: str, params):
while t:
t = await arbus.checkPair(pair)
if t != 1:
# ws.exit()
# ws_private.exit()
break
await asyncio.sleep(options.loopSleepTime)
i += 1
@ -104,13 +123,10 @@ async def strategy(client: HTTP, pair: str, params):
marketUnit = 'quoteCoin'
)
print(r2, '\n')
if r2['retMsg'] == 'OK':
print('Order placed succesfully!')
await asyncio.sleep(20)
i += 1

View File

@ -108,7 +108,7 @@ async def capture_params(message: Message, state: FSMContext):
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")))
# 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')
elif t == -1:
msg_text = (f'Параметры введены в неверном формате, пожалуйста начните заново.')

View File

@ -11,7 +11,8 @@ leverage = 1 # Leverage
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',
'lowEnd',