Joel Grunbaum
2022-01-07 4497ee326ceb2dfc3fe9d57b7b9ec9e8adc0cf8b
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
43
44 # print(json.dumps(message))
45 # print(send(message))
46 # printRecoveryLog()
47 # logAllIncomingMessages()
48 # print(getInformation())
49 # wstest()
50
51 bs = {}
4497ee 52 recoverBook(bs)
JG 53 print(list(bs))
54 for i in bs:
55     print(bs[i].product)
56     bs[i].printBook()
57     print()
58     if (len(bs[i].askSide.levels) > 0):
59         print(bs[i].askSide.levels[0])
60     if (len(bs[i].bidSide.levels)):
61         print(bs[i].bidSide.levels[0])
62     print()
63 # book.testBook()