Class: Melaya::StreamAPI
- Inherits:
-
Object
- Object
- Melaya::StreamAPI
- Defined in:
- lib/melaya/stream.rb
Overview
WebSocket streaming API.
Each method yields parsed JSON frame hashes to a block, or returns an Enumerator if no block is given. The connection is closed when the block returns or the Enumerator is exhausted.
Public stream example:
melaya.stream.ticker(exchange: "binance", symbol: "BTC/USDT", market: "spot") do |frame|
puts frame["last"]
break # close after first frame
end
Private stream example (ticket minted automatically):
melaya.stream.strategies do |ev|
puts ev["type"], ev["strategyId"]
break
end
Constant Summary collapse
- DEFAULT_WS_URL =
"wss://wss.melaya.org"
Instance Method Summary collapse
-
#initialize(api_key, ws_url, http, verify_ssl: true) ⇒ StreamAPI
constructor
A new instance of StreamAPI.
-
#liquidations(exchange: nil, &block) ⇒ Object
Cross-exchange liquidation firehose.
-
#ohlcv(exchange:, symbol:, timeframe:, market: nil, &block) ⇒ Object
Live OHLCV candle frames.
-
#orderbook(exchange:, symbol:, limit: nil, market: nil, &block) ⇒ Object
Live order-book frames.
-
#private(exchange:, market: nil, api_key_id: nil, key_id: nil, symbol: nil, &block) ⇒ Object
Live private account feed for one connected exchange key (balance, positions, your orders/fills).
-
#strategies(&block) ⇒ Object
Live strategy events for your account (cycle markers, agent messages, approval requests, executions, status).
-
#ticker(exchange:, symbol:, market: nil, &block) ⇒ Object
Live ticker frames.
-
#trades(exchange:, symbol:, market: nil, &block) ⇒ Object
Live public-trade frames.
Constructor Details
#initialize(api_key, ws_url, http, verify_ssl: true) ⇒ StreamAPI
Returns a new instance of StreamAPI.
261 262 263 264 265 266 |
# File 'lib/melaya/stream.rb', line 261 def initialize(api_key, ws_url, http, verify_ssl: true) @api_key = api_key @ws_url = ws_url.to_s.chomp("/") @http = http @verify_ssl = verify_ssl end |
Instance Method Details
#liquidations(exchange: nil, &block) ⇒ Object
Cross-exchange liquidation firehose. Omit exchange for all venues.
289 290 291 |
# File 'lib/melaya/stream.rb', line 289 def liquidations(exchange: nil, &block) open_public("/ws/liquidations", compact(exchange: exchange), &block) end |
#ohlcv(exchange:, symbol:, timeframe:, market: nil, &block) ⇒ Object
Live OHLCV candle frames.
279 280 281 |
# File 'lib/melaya/stream.rb', line 279 def ohlcv(exchange:, symbol:, timeframe:, market: nil, &block) open_public("/ws/ohlcv", compact(exchange: exchange, symbol: symbol, timeframe: timeframe, market: market), &block) end |
#orderbook(exchange:, symbol:, limit: nil, market: nil, &block) ⇒ Object
Live order-book frames.
274 275 276 |
# File 'lib/melaya/stream.rb', line 274 def orderbook(exchange:, symbol:, limit: nil, market: nil, &block) open_public("/ws/orderbook", compact(exchange: exchange, symbol: symbol, limit: limit, market: market), &block) end |
#private(exchange:, market: nil, api_key_id: nil, key_id: nil, symbol: nil, &block) ⇒ Object
Live private account feed for one connected exchange key (balance, positions, your orders/fills). Pass api_key_id from account.keys().
301 302 303 304 305 306 307 |
# File 'lib/melaya/stream.rb', line 301 def private(exchange:, market: nil, api_key_id: nil, key_id: nil, symbol: nil, &block) params = compact( exchange: exchange, market: market, apiKeyId: api_key_id, keyId: key_id, symbol: symbol ) open_private("/ws/private", "private", params, &block) end |
#strategies(&block) ⇒ Object
Live strategy events for your account (cycle markers, agent messages, approval requests, executions, status). Mints a ticket, opens /ws/strategies.
295 296 297 |
# File 'lib/melaya/stream.rb', line 295 def strategies(&block) open_private("/ws/strategies", "strategies", {}, &block) end |
#ticker(exchange:, symbol:, market: nil, &block) ⇒ Object
Live ticker frames.
269 270 271 |
# File 'lib/melaya/stream.rb', line 269 def ticker(exchange:, symbol:, market: nil, &block) open_public("/ws/ticker", compact(exchange: exchange, symbol: symbol, market: market), &block) end |
#trades(exchange:, symbol:, market: nil, &block) ⇒ Object
Live public-trade frames.
284 285 286 |
# File 'lib/melaya/stream.rb', line 284 def trades(exchange:, symbol:, market: nil, &block) open_public("/ws/public-trades", compact(exchange: exchange, symbol: symbol, market: market), &block) end |