-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
60 lines (47 loc) · 1.98 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
import time
from timeit import default_timer
from threading import Thread
from trade import buy_path, test_path
from graph import find_negative_cycle, path_product
from price_websocket import start_price_websocket
from config import config
def main():
print('Starting main thread...')
start = config['holding_currencies'][0]
returns = []
print('Searching for cycles...')
while True:
time.sleep(0.1) # Yield to allow t_price thread to catch up
cycle = find_negative_cycle(start)
if cycle and cycle[0] in config['holding_currencies']:
blacklist = False
for i in cycle:
if i in config['blacklist']:
blacklist = True
break
if blacklist:
continue
print('Cycle found:', cycle)
if config['live_trading']:
start_time = default_timer()
pct_return = buy_path(cycle, config['holding_balance'])
print('Time for buy path:', default_timer() - start_time)
returns.append(pct_return)
print('Pct return:', pct_return, '%')
est_pct_ret = (path_product(cycle) - 1) * 100
print('Estimated trade return (graph price):', est_pct_ret, '%')
else:
start_time = default_timer()
est_pct_ret = test_path(cycle)
print('Time for test path:', default_timer() - start_time)
print('Estimated trade return (client price):', est_pct_ret, '%')
est_pct_ret = (path_product(cycle) - 1) * 100
returns.append(est_pct_ret)
print('Estimated trade return (graph price):', est_pct_ret, '%')
print('Cumulative return from all trades:', sum(returns), '%', end='\n\n')
if __name__ == '__main__':
t_price = Thread(target=start_price_websocket)
t_main = Thread(target=main)
t_price.start()
t_main.start()
t_main.join()