Add order book scaffolding
This commit is contained in:
parent
da31634600
commit
44ab975d2f
32
lib/rex/order_book.rb
Normal file
32
lib/rex/order_book.rb
Normal file
@ -0,0 +1,32 @@
|
||||
require "rbtree"
|
||||
|
||||
module Rex
|
||||
class OrderBook
|
||||
def initialize()
|
||||
@sell_side = tree_with_limit_default
|
||||
@buy_side = tree_with_limit_default
|
||||
end
|
||||
|
||||
def add_order(order)
|
||||
side = if order.is_buy
|
||||
@buy_side
|
||||
else
|
||||
@sell_side
|
||||
end
|
||||
|
||||
side[order.price].add_order(order)
|
||||
end
|
||||
|
||||
|
||||
def cancel_order(order_id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def tree_with_limit_default
|
||||
tree = RBTree.new
|
||||
tree.default_proc = -> (tree, key) { tree[key] = Limit.new(key) }
|
||||
tree
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user