Obtaining Market Data

View as MarkdownOpen in Claude

Market data can be obtained through a GET request to the /iserver/marketdata/snapshot endpoint. This endpoint requires a comma-separated list of conids, which are Contract IDs. These can be identified through a GET request to the /trsrv/stocks/ endpoint. The fields indicate which data fields should be returned.

See this for more info on Contract IDs.

See this for more info on the market data endpoint.

The first request to the /iserver/marketdata/snapshot endpoint will not return any data. Therefore, the endpoint must be hit at least twice to return the desired market data. The initial response will return the requested conids.

1import requests
2
3conids = "265598,8314"
4fields = "31,7059,84,88,86,85"
5
6url = "https://localhost:5000/v1/api/iserver/marketdata/snapshot"
7
8params = {
9 "conids": conids,
10 "fields": fields
11}
12
13response = requests.get(url, params=params)
14
15print(response.status_code)
16print(response.json())