-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathFTX Order Example_2.py
56 lines (42 loc) · 1.56 KB
/
FTX Order Example_2.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
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import requests
import pandas as pd
import time, json
from time import sleep
import FTX_Class
c = FTX_Class.FtxClient(api_key="", api_secret="")
while True:
try:
btc_old = requests.get('https://ftx.com/api/markets/BTC-PERP').json()
print(btc_old['result']['ask'])
except Exception as e:
print(f'Error obtaining BTC old data: {e}')
sleep(300)
try:
btc_new = requests.get('https://ftx.com/api/markets/BTC-PERP').json()
print(btc_new['result']['ask'])
except Exception as e:
print(f'Error obtaining BTC new data: {e}')
percent = (((float(btc_new['result']['ask']) - float(btc_old['result']['ask'])) * 100) / float(btc_old['result']['ask']))
if percent < 5:
print(f'The trade requirement was not satisfied. Percentage move is at {percent}')
continue
elif btc_data['result']['ask'] >= 5:
try:
r = c.place_order("ETH/USD", "buy", 1800.0, 0.006, "1243")
print(r)
except Exception as e:
print(f'Error making order request: {e}')
sleep(2)
try:
check = c.get_open_orders(r['id'])
except Exception as e:
print(f'Error checking for order status: {e}')
if check[0]['status'] == 'open':
print ('Order placed at {}'.format(pd.Timestamp.now()))
break
else:
print('Order was either filled or canceled at {}'.format(pd.Timestamp.now()))
break