Joel Grunbaum
2022-01-20 441abf1e6a15a39f1ef7bf5e4ee2a4a43bff327b
commit | author | age
5d61a1 1 """.#test.py main module."""
JG 2 import time
3 import httpx
4 from whereismysock import all
5
6 import book
7 import protocol
8
0bef19 9 test = True
4497ee 10
5d61a1 11 HOST: str = 'sytev070'
4497ee 12 if (test):
JG 13     PORT: str = '9005'
14 else:
15     PORT: str = '9000'
5d61a1 16
JG 17 USER: str = 'test'
18 PASS: str = 'none'
19
20
21 def logAllIncomingMessages():
22     """Test function to print websocket."""
23     messages = all(f"ws://{HOST}:{PORT}/information")
24     while True:
25         for message in next(messages):
26             print(message)
27             time.sleep(0.1)
28
29
30 def printRecoveryLog():
31     """Test function to print recovery log."""
32     so_far_today = httpx.get(f"http://{HOST}:{PORT}/recover").json()
33     for message in so_far_today:
34         print(message)
35
36
37 def recoverBook(bs: {str, book.Book}):
38     """Recover book from completely lost state."""
39     so_far_today = httpx.get(f"http://{HOST}:{PORT}/recover").json()
40     for message in so_far_today:
41         protocol.handleMessage(bs, message)
42
6926be 43 def testRecoverBook(bs: {str, book.Book}):
JG 44     f = open("data.test", "r");
45     so_far_today = f.read();
46     for message in so_far_today:
47         protocol.handleMessage(bs, message)
0bef19 48
JG 49
50 message = {"type": "ADD", "product": "F_THS_APP0119T2230", "price": 99.0,
51            "side": "BUY", "volume": 1}
52
5d61a1 53 # print(json.dumps(message))
0bef19 54 print(protocol.send(message))
5d61a1 55 # printRecoveryLog()
JG 56 # logAllIncomingMessages()
57 # print(getInformation())
58 # wstest()
59
0bef19 60 # bs = {}
6926be 61 # recoverBook(bs)
0bef19 62 # testRecoverBook(bs)
JG 63 # print(list(bs))
64 # for i in bs:
65 #     print(bs[i].product)
66 #     bs[i].printBook()
67 #     print()
68 #     if (len(bs[i].askSide.levels) > 0):
69 #         print(bs[i].askSide.levels[0])
70 #     if (len(bs[i].bidSide.levels)):
71 #         print(bs[i].bidSide.levels[0])
72 #     print()
4497ee 73 # book.testBook()