Class: Polygonio::Websocket::Client
- Inherits:
-
Object
- Object
- Polygonio::Websocket::Client
- Defined in:
- lib/polygonio/websocket/client.rb
Constant Summary collapse
- BASE_URL =
"wss://socket.polygon.io/"
- BASE_URL_DELAYED =
"wss://delayed.polygon.io/"
Instance Method Summary collapse
-
#initialize(path, api_key, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #subscribe(channels, &block) ⇒ Object
Constructor Details
#initialize(path, api_key, opts = {}) ⇒ Client
Returns a new instance of Client.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/polygonio/websocket/client.rb', line 132 def initialize(path, api_key, opts = {}) path = Types::Coercible::String.enum("stocks", "forex", "crypto")[path] @api_key = api_key @ws = nil opts[:comm_inactivity_timeout] = 0 @opts = opts delayed = opts.fetch(:delayed) { false } if delayed @url = "#{BASE_URL_DELAYED}#{path}" else @url = "#{BASE_URL}#{path}" end end |
Instance Method Details
#subscribe(channels, &block) ⇒ Object
147 148 149 150 151 |
# File 'lib/polygonio/websocket/client.rb', line 147 def subscribe(channels, &block) EM.run do Connection.connect(@api_key, @url, channels, @opts, &block) end end |