Live Market Data

View as MarkdownOpen in Claude

Users may request market data using get_market_data_snapshot() to retrieve available market data.
The request currently supports [tickPrice, tickSize, tickString, tickGeneric, tickNews, and tickOptionCompution](/tws-api/doc/market-data-live/top-of-book-l-1/receive-live-data) data.

get_market_data_snapshot(

contract: [Contract Object](/tws-api/doc/contracts-financial-instruments/the-contract-object). Contract to retrieve market data for.

generic_tick_list: String. String containing comma-separate values to determine addition data to retrieve.

Default: Automatically sends an empty string, returning only the basic data such as Last, Bid, and Ask. See [Available Tick Types](/tws-api/doc/market-data-live/available-tick-types/introduction) for more details.

snapshot: Boolean. Determine if a single snapshot should be returned or if data should be continuously updated until the timeout threshold has been reached.

Default: Set to True, returning a snapshot of data as soon as possible.

timeout: Integer. Uses default timeout value passed to TWSSyncClass.

)

contract = Contract()
contract.symbol = "AAPL"
contract.secType = "STK"
contract.exchange = "SMART"
contract.primaryExchange = "NASDAQ"
contract.currency = "USD"
market_data = app.get_market_data_snapshot(contract, "225,232", False)

Data returned by get_market_data_snapshot() is delivered as a json dictionary object, separating data into “price” and “size” tags. Values are then returned as the affiliated tick types alongside any price or attribute data.

Response Object

{

{TickType}: Integer, Float String. The value of the tag. Can include price values (Float), Size values (Decimal), or direct information (string).

}

{'BID': 276.17, 'BID_SIZE': Decimal('900'), 'ASK': 276.2, 'ASK_SIZE': Decimal('300'), 'LAST_TIMESTAMP': '1764009996', 'LAST': 276.18, 'LAST_SIZE': Decimal('100'), 'VOLUME': Decimal('271511')}