-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
74 lines (61 loc) · 2.32 KB
/
app.py
File metadata and controls
74 lines (61 loc) · 2.32 KB
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
from flask import Flask
from src.routes.routes import bp
import src.globals.globals as g
from src.classes.MatchingEngine import MatchingEngine
from src.classes.Transaction import Transaction
from src.classes.TradedEngine import TradedEngine
from src.classes.User import User
from src.classes.Portfolio import Portfolio
from src.classes.TradedEngineCollection import TradedEngineCollection
import threading, time, random, csv
from src.simulation import transactionLoop, transactionLoop_preloaded
app = Flask(__name__)
app.register_blueprint(bp)
LOCALSTARTTIME = time.time()
THREADENABLED = True
MSFT_ENGINE = TradedEngine()
AAPL_ENGINE = TradedEngine()
AMZN_ENGINE = TradedEngine()
GOOG_ENGINE = TradedEngine()
INTC_ENGINE = TradedEngine()
STOCK_ENGINES = {
"MSFT": MSFT_ENGINE,
"AAPL": AAPL_ENGINE,
"AMZN": AMZN_ENGINE,
"GOOG": GOOG_ENGINE,
"INTC": INTC_ENGINE,
}
MSFT_ACCOUNT = User(accountBalance=1000000)
AMZN_ACCOUNT = User(accountBalance=10000000)
GOOG_ACCOUNT = User(accountBalance=10000000)
AAPL_ACCOUNT = User(accountBalance=10000000)
INTC_ACCOUNT = User(accountBalance=1000000)
STOCK_ACCOUNTS = {
"MSFT": MSFT_ACCOUNT,
"AAPL": AAPL_ACCOUNT,
"AMZN": AMZN_ACCOUNT,
"GOOG": GOOG_ACCOUNT,
"INTC": INTC_ACCOUNT,
}
PORTFOLIO = Portfolio(STOCK_ACCOUNTS)
ENGINE_COLLECTION = TradedEngineCollection(STOCK_ENGINES)
# 🔑 assign into globals module
g.ENGINE_COLLECTION = ENGINE_COLLECTION
g.PORTFOLIO = PORTFOLIO
g.LOCALSTARTTIME = LOCALSTARTTIME
g.THREADENABLED = THREADENABLED
if __name__ == "__main__":
STOCK_THREADS = [
threading.Thread(target=transactionLoop, args=["Resources/MSFT1/MSFTBook.csv", "MSFT"], kwargs={"delay": 0.2}),
threading.Thread(target=transactionLoop, args=["Resources/AAPL1/AAPLBook.csv", "AAPL"], kwargs={"delay": 0.2}),
threading.Thread(target=transactionLoop, args=["Resources/AMZN1/AMZNBook.csv", "AMZN"], kwargs={"delay": 0.2}),
threading.Thread(target=transactionLoop, args=["Resources/GOOG1/GOOGBook.csv", "GOOG"], kwargs={"delay": 0.2}),
threading.Thread(target=transactionLoop, args=["Resources/INTC1/INTCBook.csv", "INTC"], kwargs={"delay": 0.2}),
]
for STOCK in STOCK_THREADS:
STOCK.start()
app.run(debug=True, threaded=True)
g.THREADENABLED = False
for STOCK in STOCK_THREADS:
STOCK.join()
exit(0)