Orderbook

A gem for creating a realtime order book for the Coinbase Exchange.

Version 1.0.0 and greater now use the official Coinbase Exchange Ruby Gem's EventMachine-driven client. It should be more reliable than the previous socket code.

Also, the gem now uses BigDecimal in place of Float when dealing with sizes and prices.

Installation

Add this line to your application's Gemfile:

gem 'orderbook'

And then execute:

$ bundle

Or install it yourself as:

$ gem install orderbook

Usage

require 'orderbook'
  • Create a live updating Orderbook:

    ob = Orderbook.new
    
  • Create an Orderbook object but don't fetch an orderbook or start live updating.

    ob = Orderbook.new(false)
    

When you want it to go live:

ob.live!


* Create a live Orderbook with a callback to fire on each message:
```ruby
ob = Orderbook.new do |message|
  puts message.fetch 'type'
end
  • Create or reset the callback:

    ob.callback = lambda do |message|
    puts message.fetch 'callback'
    end
    
  • The old class name is still supported and is equivalent to an Orderbook:

    rtb = Orderbook::RealTimeBook.new
    
  • List current bids:

    ob.bids
    
  • List current asks:

    ob.asks
    
  • Show sequence number for initial level 3 snapshot:

    ob.first_sequence
    
  • Show sequence number for the last message received

    ob.last_sequence
    
  • Show the last Time a pong was received after a ping (ensures the connection is still alive):

    ob.last_pong
    

Contributing

  1. Fork it ( https://github.com/mikerodrigues/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