class GDAX::WebSocket
- GDAX::WebSocket
- Reference
- Object
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.crConstant 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
-
.new(subscription : Hash, production = true, uri : URI | String = default_host(production), headers = HTTP::Headers.new, auth : GDAX::Auth? = nil)
subscriptionis your GDAX Subscribe Request in the form of aHash.
Instance Method Summary
-
#close(*args)
closes the WebSocket alias to
HTTP::WebSocket's#closemethod. -
#closed?(*args)
Returns Bool based on whether WebSocket is closed.
-
#on(event : String, &block : Proc(*EmitArgType, Void))
Adds event listener for events based on GDAX's message
type's . -
#on_close(&on_close : String -> )
alias to
HTTP::WebSocket's#on_closemethod. -
#run(*args)
runs the WebSocket (invoke after adding "subscriptions" event listeners; must be called for the WebSocket to run) alias to
HTTP::WebSocket's#runmethod.
Constructor Detail
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 Method Detail
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