class

GDAX::WebSocket

Inherits Reference < Object

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

Constants

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

new(subscription : Hash, production = true, uri : URI | String = default_host(production), headers = HTTP::Headers.new, auth : GDAX::Auth | Nil = 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.

Source

Instance methods

close(*args)

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

Source
closed?(*args)

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

Source
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
Source
on_close

alias to HTTP::WebSocket's on_close method.

Source
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.

Source

Nested types