Add order book scaffolding

This commit is contained in:
Tim Kächele 2023-10-27 14:56:35 +02:00
parent da31634600
commit 44ab975d2f

32
lib/rex/order_book.rb Normal file
View 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