-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdemo.py
56 lines (41 loc) · 1.31 KB
/
demo.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
from src.order_book import OrderBook
'''
Basic liquidity providing principles
'''
book = OrderBook()
# 0 0 0
print(book.ask_size, book.bid_size, book.total_volume_traded)
# LMT sell 10pcs @12.5
book.submit_order('lmt', 'ask', 10, 12.5, 1)
# LMT buy 10pcs @10.5
book.submit_order('lmt', 'bid', 10, 10.5, 2)
# 10 10 0
print(book.ask_size, book.bid_size, book.total_volume_traded)
# Satisfies market demand on both sides
book.submit_order('lmt', 'bid', 10, 20, 3)
book.submit_order('lmt', 'ask', 10, 5, 3)
# 0 0 20
print(book.ask_size, book.bid_size, book.total_volume_traded)
'''
Market microstructure
---
Implementation is not making concrete orders public
only order sizes on given level
'''
book = OrderBook()
# Get 5 levels of order book
# [[], []]
print(book.get_mkt_depth(5))
book.submit_order('lmt', 'ask', 2, 10, 1)
book.submit_order('lmt', 'ask', 4, 20, 1)
book.submit_order('lmt', 'ask', 6, 30, 1)
book.submit_order('lmt', 'bid', 1, 1, 2)
book.submit_order('lmt', 'bid', 5, 2, 2)
book.submit_order('lmt', 'bid', 7, 3, 2)
# [[[Price, Size] * n], [[Price, Size] * n]]
print(book.get_mkt_depth(3))
# ([IDs], [{ID: (size, side, priority_id)}])
# OrderBook respects time priority. It means that if
# trader A submitted LMT buy @10 and trader B did same
# then trader A is traded first
print(book.get_participant_orders(1))