forked from leverj/ordersigner-daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaemon.py
64 lines (50 loc) · 1.47 KB
/
daemon.py
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
from sys import stderr
from codetiming import Timer
from leverj_ordersigner_client import OrderSignerClient, async_create_client
from tqdm import tqdm
from twisted.internet import reactor
from resources import instruments, orders, signer
def main():
d = async_create_client(reactor)
d.addCallback(client_connected)
d.addErrback(client_connection_failure)
reactor.run()
def client_connected(client):
# type: (OrderSignerClient) -> None
"""
Runs when the client successfully establishes a connection to the daemon.
"""
progress = tqdm(orders)
def response_received(actual, expected):
try:
assert actual == expected
finally:
progress.update()
if progress.n >= progress.total:
progress.close()
reactor.stop()
t.stop()
def request_failed(failure_):
failure_.printTraceback(stderr)
reactor.stop()
t = Timer()
t.start()
for order in orders:
d = client.sign_spot(
order,
instruments[order['instrument']],
signer,
)
d.addCallback(
response_received,
expected=order['signature'],
)
d.addErrback(request_failed)
def client_connection_failure(failure_):
try:
reactor.stop()
finally:
failure_.printTraceback(stderr)
print('Check that the daemon is running.')
if __name__ == '__main__':
main()