Joel Grunbaum
2022-01-12 611ad7b12fcc6b34229316099ae66bccbcf24ad9
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
4497ee 9 test = False
JG 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)
5d61a1 48 # print(json.dumps(message))
JG 49 # print(send(message))
50 # printRecoveryLog()
51 # logAllIncomingMessages()
52 # print(getInformation())
53 # wstest()
54
55 bs = {}
6926be 56 # recoverBook(bs)
JG 57 testRecoverBook(bs)
4497ee 58 print(list(bs))
JG 59 for i in bs:
60     print(bs[i].product)
61     bs[i].printBook()
62     print()
63     if (len(bs[i].askSide.levels) > 0):
64         print(bs[i].askSide.levels[0])
65     if (len(bs[i].bidSide.levels)):
66         print(bs[i].bidSide.levels[0])
67     print()
68 # book.testBook()