-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
64 lines (48 loc) · 1.51 KB
/
test.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
from algo.data_source import *
from algo.root import *
from algo.nanit import *
from algo.dom import *
from algo.virtual_exchange import *
from tqdm import tqdm
import matplotlib.pyplot as plt
def exchange_simulation():
store = DataSource()
root = Root(store=store)
robo = Robo2(store=store)
#mount(root, robo)
#add_child(root, robo)
exchange = Exchange(65000, symbol="Si-3.19")
q_data = deque()
q_orders = deque()
q_trades = deque()
def on_data(price, symbol):
#print("data",price, "symbol", symbol)
q_data.append({"price": price, "symbol": symbol})
def on_trades(trade):
q_trades.append(trade)
# generated by robo
def on_orders(order):
q_orders.append(order)
def on_new_trade(trade):
robo.profit_history.append(robo.profit())
exchange.on('data', on_data)
exchange.on('trades', on_trades)
root.on('trade', on_new_trade)
for i in tqdm(range(100000)):
exchange.step()
while len(q_data):
l1 = q_data.popleft()
event = DataEvent(l1["symbol"], l1["price"])
for action in root.do(event):
on_orders(action)
while len(q_orders):
order = q_orders.popleft()
exchange.apply_raw_order(order)
while len(q_trades):
trade = q_trades.popleft()
for action in root.do(trade):
on_orders(action)
# time.sleep(0.01)
plt.plot(robo.profit_history)
plt.show()
exchange_simulation()