Joel Grunbaum
2022-01-06 5d61a1e5c5942901cc02f87b664ad6304cf79213
commit | author | age
5d61a1 1 """.#test.py main module."""
JG 2 import json
3 import time
4 import httpx
5 from whereismysock import all
6
7 import book
8 import protocol
9
10 HOST: str = 'sytev070'
11 PORT: str = '9000'
12
13 USER: str = 'test'
14 PASS: str = 'none'
15
16
17 def send(message):
18     """Send message to exchange."""
19     return httpx.post(f"http://{HOST}:{PORT}/execution",
20                       data={"message": json.dumps(message),
21                             "username": USER,
22                             "password": PASS}).json()
23
24
25 def logAllIncomingMessages():
26     """Test function to print websocket."""
27     messages = all(f"ws://{HOST}:{PORT}/information")
28     while True:
29         for message in next(messages):
30             print(message)
31             time.sleep(0.1)
32
33
34 def printRecoveryLog():
35     """Test function to print recovery log."""
36     so_far_today = httpx.get(f"http://{HOST}:{PORT}/recover").json()
37     for message in so_far_today:
38         print(message)
39
40
41 def recoverBook(bs: {str, book.Book}):
42     """Recover book from completely lost state."""
43     so_far_today = httpx.get(f"http://{HOST}:{PORT}/recover").json()
44     for message in so_far_today:
45         protocol.handleMessage(bs, message)
46
47
48 message = {"type": "ADD", "product": "F_SOH_APP0104T1700", "price": 99.0,
49            "side": "BUY", "volume": 1000000}
50 # print(json.dumps(message))
51 # print(send(message))
52 # printRecoveryLog()
53 # logAllIncomingMessages()
54 # print(getInformation())
55 # wstest()
56
57 bs = {}
58 # recoverBook(bs)
59 # print(list(bs))
60 # for i in bs:
61     # print(bs[i].product)
62     # bs[i].printBook()
63 book.testBook()