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/"
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.
124 125 126 127 128 129 130 131 |
# File 'lib/polygonio/websocket/client.rb', line 124 def initialize(path, api_key, opts = {}) path = Types::Coercible::String.enum("stocks", "forex", "crypto")[path] @api_key = api_key @ws = nil @opts = opts @url = "#{BASE_URL}#{path}" end |
Instance Method Details
#subscribe(channels, &block) ⇒ Object
133 134 135 136 137 |
# File 'lib/polygonio/websocket/client.rb', line 133 def subscribe(channels, &block) EM.run do Connection.connect(@api_key, @url, channels, @opts, &block) end end |