-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmisc.py
More file actions
23 lines (21 loc) · 790 Bytes
/
misc.py
File metadata and controls
23 lines (21 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from datetime import datetime
def print_orderbook(result):
timestamp = result[1].get('timestamp')
bids = result[1].get('bids')
asks = result[1].get('asks')
depth = len(asks) if len(asks) >= len(bids) else len(bids)
print('\n')
print(result[0], datetime.fromtimestamp(timestamp))
print(f'|volume{" ":5} bids{"":7} asks{" ":5} volume|')
for i in range(depth):
try:
b_price = bids[i].get('price')
b_volume = bids[i].get('volume')
except IndexError:
b_price = b_volume = 0
try:
a_price = asks[i].get('price')
a_volume = asks[i].get('volume')
except IndexError:
a_price = a_volume = 0
print(f'|{b_volume:4} {b_price:12} {a_price:12} {a_volume:9}|')