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
GDAX's API URL
GDAX's Sandbox API URL
Constructors
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.
Instance methods
Returns Bool based on whether WebSocket is closed.
alias to HTTP::WebSocket's closed? method.
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
runs the WebSocket (invoke after adding "subscriptions" event listeners; must be called for the WebSocket to run)
alias to HTTP::WebSocket's run method.