Almost telegram integration + Bybit started

This commit is contained in:
2025-04-24 21:19:59 +03:00
parent 01d181c763
commit de13a172e9
6 changed files with 271 additions and 68 deletions

75
src/bybit.py Normal file
View File

@ -0,0 +1,75 @@
import time
import asyncio
from pybit.unified_trading import HTTP
import options
import credentials
import arbus
async def getClient(apiKey, apiSecret, testnet):
if testnet:
print('Using testnet API.')
else:
print('Using real API.')
client = HTTP(
testnet = testnet,
api_key = apiKey,
api_secret = apiSecret,
)
try:
response = client.get_account_info()
print('Auth succesful!')
print('Account info:', response.get('retMsg'))
return client
except Exception as e:
print('Auth failed! Check API key!')
print('Error:', e)
return -1
async def strategy(client: HTTP, pair: str, params):
startTime = time.time()
print('Starting strategy with ', pair)
paramsDict = await arbus.parseParams(params)
i = 0
t = await arbus.checkPair(pair)
while t:
t = await arbus.checkPair(pair)
if t != 1:
break
# client = getClient(credentials.api_key, credentials.api_secret, options.testnet)
r1 = client.get_order_history(
category=options.category,
symbol=pair
)
print(r1, '\n')
r2 = client.place_order(
category = options.category,
symbol = pair,
side = 'BUY',
orderType = 'Market',
qty = paramsDict['orderSize'],
marketUnit = 'quoteCoin'
)
print(r2, '\n')
if r2['retMsg'] == 'OK':
print('Order placed succesfully!')
await asyncio.sleep(20)
i += 1
print('Ending strategy with ', pair)
print('Ended on the iteration number ', i)
return i