-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOrder Example 1.py
42 lines (35 loc) · 1.25 KB
/
Order Example 1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import okex.Trade_api as Trade
import requests, time
api_key = ""
secret_key = ""
passphrase = ""
instId = "ETH-USDC"
flag = '0'
tradeAPI = Trade.TradeAPI(api_key, secret_key, passphrase, False, flag)
while True:
try:
ticker = requests.get('http://www.okex.com/api/v5/market/ticker?instId=BTC-USDC').json()
print(ticker['data'][0]['bidPx'])
except Exception as e:
print(f'Unable to obtain ticker: {e}')
if float(ticker['data'][0]['bidPx']) >= 32000.00:
try:
result = tradeAPI.place_order(instId=instId, tdMode='cash', side='buy',
ordType='limit', sz='0.005', px='2000.00')
ordId = result['data'][0]['ordId']
except Exception as e:
print(f'Unable to execute order: {e}')
time.sleep(2)
try:
check = tradeAPI.get_orders(instId, ordId)
except Exception as e:
print(f'Unable to check order: {e}')
if check['data'][0]['state'] == 'canceled':
print('Order was canceled.')
break
else:
print('Order was executed!')
break
else:
print('Requirement not reached.')
time.sleep(15)