Module: DhanHQ::WS::MarketDepth

Defined in:
lib/DhanHQ/ws/market_depth.rb,
lib/DhanHQ/ws/market_depth/client.rb,
lib/DhanHQ/ws/market_depth/decoder.rb

Defined Under Namespace

Classes: Client, Decoder

Class Method Summary collapse

Class Method Details

.client(symbols: []) ⇒ Client

Create a new Market Depth client with advanced features

Parameters:

  • symbols (Array<String>) (defaults to: [])

    Symbols to subscribe to

  • options (Hash)

    Connection options

Returns:

  • (Client)

    New client instance



31
32
33
# File 'lib/DhanHQ/ws/market_depth.rb', line 31

def client(symbols: [], **)
  Client.new(symbols: symbols, **)
end

.connect(symbols: []) ⇒ Client

Connect to Market Depth WebSocket with a simple callback

Parameters:

  • symbols (Array<String>) (defaults to: [])

    Symbols to subscribe to

  • options (Hash)

    Connection options

  • block (Proc)

    Callback for depth updates

Returns:

  • (Client)

    WebSocket client instance



20
21
22
23
24
# File 'lib/DhanHQ/ws/market_depth.rb', line 20

def connect(symbols: [], **, &)
  client = Client.new(symbols: symbols, **)
  client.on(:depth_update, &) if block_given?
  client.start
end

.connect_with_handlers(symbols: [], handlers: {}) ⇒ Client

Quick connection with multiple event handlers

Parameters:

  • symbols (Array<String>) (defaults to: [])

    Symbols to subscribe to

  • handlers (Hash) (defaults to: {})

    Event handlers

  • options (Hash)

    Connection options

Returns:

  • (Client)

    Started client instance



41
42
43
44
45
46
47
48
49
# File 'lib/DhanHQ/ws/market_depth.rb', line 41

def connect_with_handlers(symbols: [], handlers: {}, **)
  client = Client.new(symbols: symbols, **).start

  handlers.each do |event, handler|
    client.on(event, &handler)
  end

  client
end

.snapshot(symbols:) ⇒ Client

Get market depth snapshot for symbols

Parameters:

  • symbols (Array<String>)

    Symbols to get snapshot for

  • options (Hash)

    Connection options

  • block (Proc)

    Callback for snapshot data

Returns:

  • (Client)

    Started client instance



67
68
69
70
71
# File 'lib/DhanHQ/ws/market_depth.rb', line 67

def snapshot(symbols:, **, &)
  client = Client.new(symbols: symbols, **)
  client.on(:depth_snapshot, &) if block_given?
  client.start
end

.subscribe(symbols:) ⇒ Client

Subscribe to market depth for specific symbols

Parameters:

  • symbols (Array<String>)

    Symbols to subscribe to

  • options (Hash)

    Connection options

  • block (Proc)

    Callback for depth updates

Returns:

  • (Client)

    Started client instance



57
58
59
# File 'lib/DhanHQ/ws/market_depth.rb', line 57

def subscribe(symbols:, **, &)
  connect(symbols: symbols, **, &)
end