class GDAX::WebSocket

Overview

GDAX WebSocket API wrapper.

ws = GDAX::WebSocket.new production: true, subscription: {
  "type" => "subscribe",
  "channels" => [{ "name" => "heartbeat", "product_ids" => ["ETH-EUR"] }]
}

ws.on "subscriptions" do |data, event|
  puts "GDAX CONNECTED"
end

ws.run

Defined in:

gdax/WebSocket.cr

Constant Summary

DEFAULT_PRODUCTION_HOST = "wss://ws-feed.gdax.com"

GDAX's API URL

DEFAULT_SANDBOX_HOST = "wss://ws-feed.sandbox.gdax.com"

GDAX's Sandbox API URL

Constructors

Instance Method Summary

Constructor Detail

def self.new(subscription : Hash, production = true, uri : URI | String = default_host(production), headers = HTTP::Headers.new, auth : GDAX::Auth? = nil) #

subscription is your GDAX Subscribe Request in the form of a Hash.

uri is the WebSocket URI. Defaults to sandbox URI unless production is set to true

headers are any additional headers you would like to add to the connection.

If production is false, sandbox URI will be used by default.

auth can be passed to sign/authenticate over WebSockets.


[View source]

Instance Method Detail

def close(*args) #

closes the WebSocket alias to HTTP::WebSocket's #close method.


[View source]
def closed?(*args) #

Returns Bool based on whether WebSocket is closed. alias to HTTP::WebSocket's #closed? method.


[View source]
def on(event : String, &block : Proc(*EmitArgType, Void)) #

Adds event listener for events based on GDAX's message type's . Takes in String of the event to listen for and a block to run when the event fires. The block is passed two arguments: the first being the JSON::Any response data from GDAX, and the second being the event itself. e.g.

ws.on "subscriptions" do |data, event|
  message_recieved = true
end

[View source]
def on_close(&on_close : String -> ) #

alias to HTTP::WebSocket's #on_close method.


[View source]
def run(*args) #

runs the WebSocket (invoke after adding "subscriptions" event listeners; must be called for the WebSocket to run) alias to HTTP::WebSocket's #run method.


[View source]