websocket WIP 2
This commit is contained in:
30
src/bybit.py
30
src/bybit.py
@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user