-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOrder Example 2.py
More file actions
51 lines (41 loc) · 1.58 KB
/
Copy pathOrder Example 2.py
File metadata and controls
51 lines (41 loc) · 1.58 KB
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
43
44
45
46
47
48
49
50
51
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:
old = requests.get('http://www.okex.com/api/v5/market/ticker?instId=BTC-USDC').json()
print(old['data'][0]['bidPx'])
except Exception as e:
print(f'Unable to obtain ticker: {e}')
time.sleep(300)
try:
new = requests.get('http://www.okex.com/api/v5/market/ticker?instId=BTC-USDC').json()
print(new['data'][0]['bidPx'])
except Exception as e:
print(f'Unable to obtain ticker: {e}')
percent = ((float(new['data'][0]['bidPx']) - float(old['data'][0]['bidPx'])) / float(old['data'][0]['bidPx'])) * 100
if percent >= 5:
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(f'Requirement not reached. Percentage move at {percent}')