websocker WIP

This commit is contained in:
2025-04-27 16:59:31 +03:00
parent de13a172e9
commit bf0eecc213
3 changed files with 50 additions and 3 deletions

View File

@ -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)

View File

@ -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'Вы запустили стратегию на паре <b>{data.get("pair")}</b> с данными параметрами:\n<b>{data.get("params")}</b>\n')
elif t == -1:

View File

@ -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',