Class: DhanHQ::WS::MarketDepth::Client
- Inherits:
-
BaseConnection
- Object
- BaseConnection
- DhanHQ::WS::MarketDepth::Client
- Defined in:
- lib/DhanHQ/ws/market_depth/client.rb
Overview
WebSocket client for Full Market Depth data Provides real-time market depth (bid/ask levels) for specified symbols
Constant Summary collapse
- SUBSCRIBE_REQUEST_CODE =
23- UNSUBSCRIBE_REQUEST_CODE =
12
Constants inherited from BaseConnection
BaseConnection::COOL_OFF_429, BaseConnection::MAX_BACKOFF
Instance Attribute Summary
Attributes inherited from BaseConnection
#callbacks, #started, #stopping, #url
Instance Method Summary collapse
-
#initialize(symbols: [], **options) ⇒ Client
constructor
Initialize Market Depth WebSocket client.
-
#start ⇒ Client
Start the Market Depth WebSocket connection.
-
#subscribe(symbols) ⇒ Client
Subscribe to market depth for specific symbols.
-
#subscribed?(symbol) ⇒ Boolean
Check if subscribed to a symbol.
-
#subscriptions ⇒ Array<String>
Get current subscriptions.
-
#unsubscribe(symbols) ⇒ Client
Unsubscribe from market depth for specific symbols.
Methods inherited from BaseConnection
#connected?, #disconnect!, #emit, #on, #open?, #send_message, #stop
Constructor Details
#initialize(symbols: [], **options) ⇒ Client
Initialize Market Depth WebSocket client
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/DhanHQ/ws/market_depth/client.rb', line 23 def initialize(symbols: [], **) cfg = DhanHQ.configuration url = [:url] || build_market_depth_url(cfg) super(url: url, **) @symbols = Array(symbols) @subscriptions = Concurrent::Map.new @instrument_cache = Concurrent::Map.new @decoder = Decoder.new end |
Instance Method Details
#start ⇒ Client
Start the Market Depth WebSocket connection
37 38 39 40 41 |
# File 'lib/DhanHQ/ws/market_depth/client.rb', line 37 def start super subscribe_to_symbols(@symbols) if @symbols.any? self end |
#subscribe(symbols) ⇒ Client
Subscribe to market depth for specific symbols
47 48 49 50 |
# File 'lib/DhanHQ/ws/market_depth/client.rb', line 47 def subscribe(symbols) subscribe_to_symbols(Array(symbols)) self end |
#subscribed?(symbol) ⇒ Boolean
Check if subscribed to a symbol
72 73 74 |
# File 'lib/DhanHQ/ws/market_depth/client.rb', line 72 def subscribed?(symbol) @subscriptions.key?(normalize_label(symbol)) end |
#subscriptions ⇒ Array<String>
Get current subscriptions
64 65 66 |
# File 'lib/DhanHQ/ws/market_depth/client.rb', line 64 def subscriptions @subscriptions.values.map { || [:original_label] } end |
#unsubscribe(symbols) ⇒ Client
Unsubscribe from market depth for specific symbols
56 57 58 59 |
# File 'lib/DhanHQ/ws/market_depth/client.rb', line 56 def unsubscribe(symbols) unsubscribe_from_symbols(Array(symbols)) self end |