Realtime Data¶
The Nubra Python SDK provides WebSocket-based realtime market-data streams through NubraDataSocket. Use realtime data when you need continuously updating values instead of point-in-time snapshots.
What This Page Covers¶
This page covers:
- how to initialize the WebSocket client
- how callbacks receive streamed data
- how to subscribe by stream type
- where to find the individual stream pages
LLM guidance
Realtime pages describe streaming subscriptions, not snapshot APIs. Use these pages when the application needs continuously updating values, event-driven callbacks, or tick-driven behavior. Use snapshot APIs for one-time reads, polling flows, or point-in-time inspection. Subscription keys differ by stream: index and ohlcv use symbols, option uses ASSET:EXPIRY, and orderbook / greeks use instrument ref_id values.
Walkthrough Video¶
If the embedded video does not load, watch it on YouTube: Realtime Data Walkthrough
Available Streams¶
| Stream | Purpose | Page |
|---|---|---|
| Index Data | streaming updates for indices, stocks, and some derivative symbols | Index Data |
| Option Chain Data | streaming option-chain updates by underlying and expiry | Option Chain Data |
| Order Book Data | streaming market depth by ref_id |
Order Book Data |
| Greeks Data | streaming option Greeks by option ref_id |
Greeks Data |
| OHLCV Data | streaming candle buckets by symbol and interval | OHLCV Data |
Basic Usage¶
from nubra_python_sdk.ticker import websocketdata
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
nubra = InitNubraSdk(NubraEnv.UAT, env_creds=True)
def on_market_data(msg):
print("[MarketData]", msg)
def on_connect(msg):
print("[status]", msg)
def on_close(reason):
print("Closed:", reason)
def on_error(err):
print("Error:", err)
socket = websocketdata.NubraDataSocket(
client=nubra,
on_market_data=on_market_data,
on_connect=on_connect,
on_close=on_close,
on_error=on_error,
)
socket.connect()
socket.subscribe(["NIFTY", "HDFCBANK"], data_type="index", exchange="NSE")
socket.keep_running()
Callback Model¶
The WebSocket client can emit:
on_market_datafor general market-data reception- stream-specific callbacks such as
on_index_data,on_option_data,on_orderbook_data,on_ohlcv_data, andon_greeks_data - lifecycle callbacks such as
on_connect,on_close, andon_error
Use stream-specific callbacks when you want a dedicated handler for one stream type. Use on_market_data when you want one central receiver.
Common Subscription Pattern¶
socket.subscribe(["NIFTY"], data_type="index", exchange="NSE")
socket.subscribe(["RELIANCE:20250626"], data_type="option", exchange="NSE")
socket.subscribe(["1746686"], data_type="orderbook")
socket.subscribe(["1058227"], data_type="greeks", exchange="NSE")
socket.subscribe(["NIFTY"], data_type="ohlcv", interval="5m", exchange="NSE")
Implementation Notes¶
socket.connect()starts the connection handshake.socket.keep_running()blocks the current thread.- Run the WebSocket in a separate thread or service loop if the main process must continue doing other work.
- Use Subscription Limits to plan stream capacity before scaling subscriptions.
Important Rules
- Realtime data is a streaming interface, not a snapshot API.
keep_running()blocks the current thread. Run the WebSocket loop outside the main application flow when needed.- Use the correct symbols or
ref_idvalues for the stream type you are subscribing to. - For option-chain and option-Greeks workflows, use Get Instruments to retrieve the latest instrument expiries before building expiry keys or resolving option
ref_idvalues. - Respect session subscription-weight limits. Review Subscription Limits before scaling usage.
- Use lifecycle callbacks such as
on_error,on_connect, andon_closeto handle production behavior safely.