Project

rtcbx

0.0
No release in over 3 years
Low commit activity in last 3 years
Uses the Coinbase Pro (formerly GDAX, formerly Coinbase Exchange) Exchange Websocket stream to maintain a real-time copy of the order book, place and track orders, and calculate historic rates by the minute in real-time.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 12.3

Runtime

>= 0.2.0, ~> 0.2
~> 2.0
 Project Readme

RTCBX

Gem Version

RTCBX uses the Coinbase Pro (formerly GDAX and Coinbase Exchange) Exchange websocket feed to provide immediate access to the current state of the exchange without repeatedly polling parts of the RESTful API. It can:

  • Keep a synchronized copy of the entire orderbook - RTCBX::Orderbook
  • Calculate historic rates (candles) by the minute - RTCBX::Candles
  • Place and track orders for an account - RTCBX::Trader

Each type of RTCBX object will supports defining callbacks to run when:

  • The Orderbook changes.
  • A new candle is generated.
  • Your order(s) change status.

Installation

Add this line to your application's Gemfile:

gem 'rtcbx'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rtcbx 

Usage

require 'rtcbx'

RTCBX objects share a common interface:

#
# :product_id
#   sets the currency (defaults to 'BTC-USD')
#
# :start
#   run #start! at creation?  (defaults to true)
# 

rtcbx = RTCBX.new({product_id: 'BTC-GPB', start: false}) do |change|
  # check some values, do some stuff
end

rtcbx.start! # Starts the websocket feed and tracking/update threads.

rtcbx.stop!  # Stops the websocket feed and any tracking/update threads.

rtcbx.reset! # Calls #stop! then calls #start!.

Orderbooks

  • Create a live updating Orderbook:
ob = RTCBX::Orderbook.new
  • Create an Orderbook object but don't fetch an orderbook or start live updating.
ob = RTCBX::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 = RTCBX::Orderbook.new(product_id: "BTC-GBP")
  • Create a live Orderbook with a callback to fire on each message:
ob = RTCBX::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
  • Aggregates the top N bids in the Orderbook (optional parameter defaults to aggregate all available bids):
ob.aggregate_bids(10)
  • Aggregates the first N asks in the Orderbook (optional parameter defaults to aggregate all available asks):
ob.aggregate_asks(10)
  • Aggregates the top N bids and the first N asks in the Orderbook (optional parameter defaults to aggregate the entire Orderbook):
# Will perform the aggregation on each call. Avoid abusing this function since it may degrade performance.
ob.aggregate(10)

Candles

Trader

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