orderbook.cr v0.1.0

An event driven orderbook for algotrading written in Crystal

Orderbook

GitHub release

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

  1. Add the dependency to your shard.yml:

    dependencies:
      orderbook:
        github: nolantait/orderbook.cr
    
  2. Run shards install

Usage

require "orderbook"
require "big"

book = Orderbook::Partial.new

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

OR you could initialize a simple book with just the best bid/ask:

book = Orderbook::Simple.new

tick = Tick.new(
  timestamp: 123456,
  is_trade: false,
  is_bid: true,
  price: BigDecimal.new(0.1),
  quantity: BigDecimal.new(1)
)

book.emit tick

The above would set the book.best_bid to equal the new tick

Development

shards install and then crystal specs

Contributing

  1. Fork it (https://github.com/nolantait/orderbook/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

orderbook.cr

Owner
Statistic
  • 2
  • 0
  • 0
  • 0
  • 1
  • about 2 years ago
  • March 27, 2022
License

MIT License

Links
Synced at

Fri, 17 May 2024 18:37:59 GMT

Languages