Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathorder_book_test.py
More file actions
Latest commit
37 lines (28 loc) · 1.45 KB
/
Copy pathorder_book_test.py
File metadata and controls
37 lines (28 loc) · 1.45 KB
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
importbookmapasbm
alias_to_order_book= {}
defhandle_subscribe_instrument(addon, alias, full_name, is_crypto, pips, size_multiplier, instrument_multiplier, supported_features):
print("Instrument received "+alias, flush=True)
# create order book for each subscribed instrument
alias_to_order_book[alias] =bm.create_order_book()
req_id=1
# subscribe to depth update for this instrument
bm.subscribe_to_depth(addon, alias, req_id)
print("Data subscribed", flush=True)
defhandle_unsubscribe_instrument(addon, alias):
print("The instrument "+alias+" has been removed", flush=True)
# handler for depth. it receives information about side, price and size.
defhandle_depth_info(addon, alias, is_bid, price, size):
order_book=alias_to_order_book[alias]
# on_depth method updates internal order book
bm.on_depth(order_book, is_bid, price, size)
print("Depth: bid: "+str(is_bid) +", price: "+
str(price) +", size: "+str(size), flush=True)
# get liquidity for 20 levels from both side from current order book
bid, ask=bm.get_sum(order_book, 20)
print("Bid sum: "+str(bid) +", ask sum: "+str(ask), flush=True)
if__name__=="__main__":
addon=bm.create_addon()
print("Addon created", flush=True)
bm.add_depth_handler(addon, handle_depth_info)
bm.start_addon(addon, handle_subscribe_instrument, handle_unsubscribe_instrument)
bm.wait_until_addon_is_turned_off(addon)