Almost telegram integration + Bybit started
This commit is contained in:
75
src/bybit.py
Normal file
75
src/bybit.py
Normal 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
|
||||
Reference in New Issue
Block a user