websocker WIP
This commit is contained in:
44
src/bybit.py
44
src/bybit.py
@ -2,6 +2,7 @@ import time
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from pybit.unified_trading import HTTP
|
from pybit.unified_trading import HTTP
|
||||||
|
from pybit.unified_trading import WebSocket
|
||||||
|
|
||||||
import options
|
import options
|
||||||
import credentials
|
import credentials
|
||||||
@ -31,6 +32,49 @@ async def getClient(apiKey, apiSecret, testnet):
|
|||||||
return -1
|
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):
|
async def strategy(client: HTTP, pair: str, params):
|
||||||
startTime = time.time()
|
startTime = time.time()
|
||||||
print('Starting strategy with ', pair)
|
print('Starting strategy with ', pair)
|
||||||
|
|||||||
@ -107,6 +107,7 @@ 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.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:
|
||||||
|
|||||||
@ -1,15 +1,17 @@
|
|||||||
url = 'https://testnet.binance.vision/api' # API url
|
url = 'https://testnet.binance.vision/api' # API url
|
||||||
testnet = True # Use testnet or not
|
testnet = True # Use testnet or not
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pairSymbol = 'ETHUSDT' # Trading pair
|
pairSymbol = 'ETHUSDT' # Trading pair
|
||||||
mainSymbol = 'USDT' # Balance asset
|
mainSymbol = 'USDT' # Balance asset
|
||||||
timeScape = '15m' # Candle length
|
timeScape = '15m' # Candle length
|
||||||
category = 'spot'
|
category = 'linear'
|
||||||
leverage = 1 # Leverage
|
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',
|
paramsLines = ['highEnd',
|
||||||
'lowEnd',
|
'lowEnd',
|
||||||
|
|||||||
Reference in New Issue
Block a user