-
Notifications
You must be signed in to change notification settings - Fork 3
/
Main.py
82 lines (59 loc) · 1.67 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
77
78
79
80
81
82
import threading
from multiprocessing import Process, Queue
import time
from Trader import Trader
from API import API
from Market import Market
from Visualization import Visual
import matplotlib.pyplot as plt
#À modifier pour changer la vitesse de simulation
vitesse = 400
def initVisual(qDisp, qStart, qData):
app = Visual(qDisp, qStart, qData)
app.app.run_server()
def main():
qDisp = Queue()
qStart = Queue()
qData = Queue()
market = Market(qDisp, vitesse)
Tapp = Process(target=initVisual, args=(qDisp, qStart, qData,))
Tapp.start()
start = False
while(not start):
while(qStart.empty()):
time.sleep(0.1)
start = qStart.get()
api1 = API(market)
trader1 = Trader(api1)
t1 = threading.Thread(target=trader1.run)
t1.start()
market.start()
while(start):
while(qStart.empty() and not market.done):
time.sleep(0.1)
try:
data = qData.get_nowait();
if(data == True):
market.displayData()
except:
pass
if(not qStart.empty()):
start = qStart.get()
else:
start = market.done
t1.run = False
if market.done:
while(start):
while(qStart.empty()):
time.sleep(0.1)
try:
data = qData.get_nowait();
if(data == True):
market.displayData()
except:
pass
start = qStart.get()
market.stop()
t1.join()
if __name__ == "__main__":
main()