-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (64 loc) · 2.38 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from constants import ABORT_ALL_POSITIONS, FIND_COINTEGRATED, PLACE_TRADERS, MANAGE_EXITS
from func_connections import connect_dydx
from func_private import abort_all_positions
from func_public import construct_market_prices
from func_cointegration import store_cointegration_results
from func_entry_pairs import open_positions
from func_exit_pairs import manage_trade_exits
from func_messaging import send_message
if __name__ == "__main__":
send_message("anoter awesome message")
print("success")
exit(1)
# Connect to client
try:
print("Connecting to Client...")
client = connect_dydx()
except Exception as e:
print(e)
print("Error connecting to client: ", e)
exit(1)
if ABORT_ALL_POSITIONS:
try:
print("Closing all positions")
close_orders = abort_all_positions(client)
except Exception as e:
print("Error closing all positions", e)
exit(1)
# Find Cointegrated Pairs
if FIND_COINTEGRATED:
# Construct Market Prices
try:
print("Fetching market prices, please allow 3 mins...")
df_market_prices = construct_market_prices(client)
except Exception as e:
print("Error constructing market prices: ", e)
exit(1)
# Store Cointegrated Pairs
try:
print("Storing cointegrated pairs...")
stores_result = store_cointegration_results(df_market_prices)
if stores_result != "saved":
print("Error saving cointegrated pairs")
exit(1)
except Exception as e:
print("Error saving cointegrated pairs: ", e)
exit(1)
# Run as always on
while True:
# Place traders for opening positions
if MANAGE_EXITS:
try:
print("Managing exits...")
manage_trade_exits(client)
except Exception as e:
print("Error managing exiting positions: ", e)
exit(1)
# Place traders for opening positions
if PLACE_TRADERS:
try:
print("Finding trading opportunities...")
open_positions(client)
except Exception as e:
print("Error trading pairs: ", e)
exit(1)