Fetching data from Zerodha Order Book in Python

Use the following python code to convert the Zerodha order book to a dataframe.

Once you create the DataFrame, you’ll note that it has the following fields:

(I have provided some sample values to help you understand them)

  • Index : This starts from 0 and increments by 1
  • account_id : This is your account id (alpha-numeric)
  • placed_by : This is your account id
  • order_id : 15 digit numeric character
  • exchange_order_id : 16 digit numeric character
  • parent_order_id : None
  • status : COMPLETE / etc.
  • status_message : None
  • status_message_raw : None
  • order_timestamp : 2025-05-02 14:24:58
  • exchange_update_timestamp : 2025-05-02 14:24:58
  • exchange_timestamp : 2025-05-02 14:24:58
  • variety : regular
  • modified : False
  • exchange : NFO
  • tradingsymbol : NIFTY2550824200PE
  • instrument_token : 9881346
  • order_type : MARKET
  • transaction_type : BUY / SELL
  • validity : DAY
  • validity_ttl : 0
  • product : MIS
  • quantity : 75 (This is the ordered quantity)
  • disclosed_quantity : 0
  • price : 0
  • trigger_price : 0
  • average_price : 127.55 (This is the price at which the order was executed be that be buy or sell)
  • filled_quantity : 75 (This the actual quantity that was executed)
  • pending_quantity : 0
  • cancelled_quantity : 0
  • market_protection : 0
  • meta : {}
  • tag : None
  • guild : 01XoMy73mJub4XT

Fetching Order Details

This will fetch you the latest quantity from the order book.

Just replace “quantity” with other variable and you can fetch whatever you want.