Function: get_marketdepth(symbol, mdtype, fields, maxrows=10, subscribe=False)

Description:

Fetch a full market depth (order book) table for a given instrument from ICE Data Services. Returns bid and ask levels side by side, showing price, size, and other requested fields at each depth level. Useful for building order book views, liquidity analysis, or pre-trade analytics.

Function Signature:

get_marketdepth(symbol: str, mdtype: str, fields: Union[str, List[str]],
                maxrows: int = 10, subscribe: bool = False) -> tuple

Parameters:

Name Type Required Default Description
symbol str Yes - A single instrument symbol in ICE format (e.g. 'BRN 1!-ICE', 'msft'). Max 1 symbol per request.
mdtype str Yes - Market depth type for the symbol. Pass an empty string '' to use the symbol's default type. Use get_marketdepth_types(symbol) to discover valid types.
fields str or List[str] Yes - One or more depth fields to return. Use get_marketdepth_fields() to see all available fields. Common fields: 'Price', 'Size', 'MMID'.
maxrows int No 10 Maximum number of depth levels to return. Defaults to 10.
subscribe bool No False If True, keeps the request alive so subsequent calls for the same symbol/mdtype execute faster.

Helper functions

Before calling get_marketdepth(), two helper functions let you discover valid inputs:

  • get_marketdepth_types(symbol) - returns all market depth types available for a given symbol (e.g. 'NASDAQ - Order Book', 'Arca - Order Book'). Pass an empty string '' as mdtype to use the symbol's default type.
  • get_marketdepth_fields() - returns all fields available for use with get_marketdepth(). Available fields include: MMID, Price, Size, Date, Time, Order ID, Orders, Exchange ID, Broker ID, Min Quantity, Min Increment, Min Balance Remaining.
  • clear_marketdepth_subscriptions() - clears all market depth subscriptions kept alive by get_marketdepth(subscribe=True).

Default behavior and internals

  • Each row in the result represents one depth level: row 0 is the best Bid/Ask, row 1 is the next level, and so on.
  • Every requested field is returned twice, once for each side, as Bid.<field> and Ask.<field> columns. For example, requesting 'Price' returns both Bid.Price and Ask.Price.
  • Passing an empty string for mdtype uses the symbol's default market depth type.

Return

Returns a tuple of tuples. The first tuple is the header row (blank first cell, then alternating Bid/Ask field columns). Each following tuple is one depth level with its values. None indicates no value available.

Notes

  • Max 1 symbol per request.
  • Request rate limit: 10 requests/sec.
  • Symbols must match ICE format (e.g. 'BRN 1!-ICE', 'msft').
  • Field names are case-insensitive, but best practice is to match the casing returned by get_marketdepth_fields().