Orderbook
A gem for creating a realtime order book for the Coinbase Exchange.
Version 4.0.0 switches to keyword arguments, supports other currencies.
Version 3.0.0 has a slightly different interface and properly queues messages
for an accurate Orderbook.
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(start: false)
ob.start!
ob.stop!
ob.reset!
- Get the "BTC-GBP" orderbook instead of "BTC-USD":
ob = Orderbook.new(product_id: "BTC-GBP")
- Create a live Orderbook with a callback to fire on each message:
ob = Orderbook.new do |message|
if message.fetch 'type' == 'match'
puts ob.spread.to_f('s')
end
end
- Create or reset the message callback:
ob.on_message do |message|
puts ob.count
end
ob.bids
ob.asks
- Show sequence number for initial level 3 snapshot:
ob.snapshot_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
- Fork it ( https://github.com/mikerodrigues/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