Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

orderbook

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orderbook

  • 4.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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)

# When you want it to go live:

ob.start!

# When you want to stop it:

ob.stop!

# Reset the orderbook by fetching a fresh orderbook snapshot. This just calls
# `stop!` and then `start!` again:

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
  • List current bids:
ob.bids
  • List current asks:
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

  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

FAQs

Package last updated on 19 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc