Orderbook
An extensible limit order book model written in Crystal.
Designed to be used in live trading and backtesting market making strategies.
It uses the Dense Tick Format for all ticks and orders in an effort to keep the API somewhat uniform.
Installation
-
Add the dependency to your
shard.yml
:dependencies: orderbook: github: nolantait/orderbook.cr
-
Run
shards install
Usage
require "orderbook"
require "big"
Orderbook.run do |book|
book.on Orderbook::LimitOrderFilled do |order|
puts "ORDER FILLED"
end
sell_order = Orderbook::LimitOrder.new(
id: "1",
is_bid: false,
quantity: BigDecimal.new(0.5),
price: BigDecimal.new(0.1)
)
tick = Tick.new(
timestamp: 123456,
is_trade: true,
is_bid: true,
price: BigDecimal.new(0.1),
quantity: BigDecimal.new(1)
)
book.add_order sell_order
book.emit tick
end
OR you could initialize the book yourself without a block:
book = Orderbook.build
# Do stuff from above here
Running either would print "ORDER FILLED"
Development
shards install
and then crystal specs
Contributing
- Fork it (https://github.com/nolantait/orderbook/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Nolan J Tait - creator and maintainer