Order Book Data¶
The orderbook realtime stream delivers continuously updating market-depth data for subscribed instruments.
This stream can be used with supported ref_id values resolved from NSE, BSE, and MCX.
LLM guidance
Use this page when the application needs live market-depth updates keyed by ref_id. Use Market Quotes for one-time order-book snapshots instead of a streaming feed.
Basic Usage¶
from nubra_python_sdk.ticker import websocketdata
from nubra_python_sdk.refdata.instruments import InstrumentData
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
nubra = InitNubraSdk(NubraEnv.PROD, env_creds=True)
instruments = InstrumentData(nubra)
nse_ref_id = instruments.get_instrument_by_symbol("HDFCBANK", exchange="NSE").ref_id
bse_ref_id = instruments.get_instrument_by_symbol("HDFCBANK", exchange="BSE").ref_id
mcx_ref_id = instruments.get_instrument_by_symbol("FUT_CRUDEOIL_20260618", exchange="MCX").ref_id
def on_orderbook_data(msg):
print("[ORDERBOOK]", msg)
def on_connect(msg):
print("[status]", msg)
def on_close(reason):
print(f"Closed: {reason}")
def on_error(err):
print(f"Error: {err}")
socket = websocketdata.NubraDataSocket(
client=nubra,
on_orderbook_data=on_orderbook_data,
on_connect=on_connect,
on_close=on_close,
on_error=on_error,
)
socket.connect()
socket.subscribe([str(nse_ref_id)], data_type="orderbook")
socket.subscribe([str(bse_ref_id)], data_type="orderbook")
socket.subscribe([str(mcx_ref_id)], data_type="orderbook")
socket.keep_running()
Subscription Contract¶
| Parameter | Type | Required | Meaning |
|---|---|---|---|
ref_ids |
list[str] |
yes | instrument reference IDs |
data_type |
str |
yes | must be orderbook |
Response Shape¶
Response Shape
class OrderBookWrapper:
ref_id: int
timestamp: int
last_traded_price: int
last_traded_quantity: int
volume: int
bids: list[Orders]
asks: list[Orders]
class Orders:
price: int
quantity: int
num_orders: int
Response Contract¶
| Field | Type | Meaning |
|---|---|---|
ref_id |
int |
subscribed instrument identifier |
timestamp |
int |
event timestamp |
last_traded_price |
int |
latest traded price |
last_traded_quantity |
int |
latest traded quantity |
volume |
int |
traded volume |
bids |
list[Orders] |
bid-side market depth |
asks |
list[Orders] |
ask-side market depth |
bids[].price / asks[].price |
int |
price at that level |
bids[].quantity / asks[].quantity |
int |
quantity at that level |
bids[].num_orders / asks[].num_orders |
int |
order count at that level |
Implementation Notes¶
- This stream is the realtime counterpart to snapshot Market Quotes.
- Use
ref_idvalues resolved from the matching exchange instruments master. - Bid and ask prices are returned in exchange-native units where applicable.
Important Rules
- This is a realtime stream, not a snapshot API.
orderbooksubscriptions require validref_idvalues.orderbooksubscriptions can use eligible instrumentref_idvalues fromNSE,BSE, andMCX.- Do not reuse environment-specific identifiers across UAT and PROD.
- Review Subscription Limits before opening large numbers of depth subscriptions.