Getting time and sales data. No data in the 200 response
What am I doing wrong?
I'm trying to follow this: https://developers.lseg.com/en/article-catalog/article/using-tick-history-in-r-language-part-3
def preview_response(response, num_lines=100): """ Prints the first few lines of a streamed Refinitiv API response. :param response: The streamed API response. :param num_lines: Number of lines to preview. """ print("Previewing first few lines of response:...") for i, line in enumerate(response.iter_lines(decode_unicode=True)): if line: print(line) # Print each line of data if i >= num_lines - 1: # Stop after num_lines break def get_time_and_sales(ticker, query_start_date, query_end_date): """ Retrieves time and sales data for a given ticker from Refinitiv. This method fetches historical time and sales data which includes trade information such as price, volume, and timestamp for each trade. Args: ticker (str): The RIC identifier for the instrument (e.g., "AAPL.O") query_start_date (str): Start date in ISO format (e.g., "2024-03-01T09:30:00Z") query_end_date (str): End date in ISO format (e.g., "2024-03-01T16:00:00Z") Returns: requests.Response: A streaming response containing the time and sales data in CSV format Example: response = get_time_and_sales("AAPL.O", "2024-03-01T09:30:00Z", "2024-03-01T16:00:00Z") # Process the response as needed """ logger.info(f"Fetching time and sales data for {ticker} from {query_start_date} to {query_end_date}...") json_blob = { "ExtractionRequest": { "@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.TickHistoryTimeAndSalesExtractionRequest", "ContentFieldNames": [ "Trade - Price", "Trade - Volume", "Trade - Exchange Time" ], "IdentifierList": { "@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.InstrumentIdentifierList", "InstrumentIdentifiers": [ { "Identifier": f"{ticker}", "IdentifierType": "Ric" } ], }, "Condition": { "MessageTimeStampIn": "GmtUtc", "ReportDateRangeType": "Range", "QueryStartDate": query_start_date, "QueryEndDate": query_end_date }, } } post_url = URL_BASE + "/Extractions/ExtractRaw" # Make the request directly instead of using post_request_with_auth to include Content-Type header request_response = requests.post( post_url, headers={ "Authorization": f"Token {REFINITIV_AUTH_TOKEN}", "Content-Type": "application/json", "Prefer": "respond-async" }, json=json_blob ) # Check for errors and log the response for debugging if request_response.status_code != 200: logger.error(f"Error response: {request_response.status_code} - {request_response.text}") request_response.raise_for_status() job_id = request_response.json()["JobId"] logger.info(f"Time and sales data extraction job started with ID: {job_id}") data_response = requests.get( URL_BASE + f"/Extractions/RawExtractionResults('{job_id}')/$value", headers={ "Authorization": f"Token {REFINITIV_AUTH_TOKEN}", "Prefer": "respond-async" } ) data_response.raise_for_status() logger.info(f"Time and sales data retrieved successfully for {ticker}") return data_response # Example usage: if __name__ == "__main__": t_s_data = get_time_and_sales(symbol, start_date, end_date) preview_response(t_s_data)
Answers
-
The 200 response will contact the JobId and Notes. For example:
HTTP 200 OK
{
"@odata.context": "https://selectapi.datascope.refinitiv.com/RestApi/v1/$metadata#RawExtractionResults/$entity",
"JobId": "0x05806ed296dc2064",
"Notes": [
"Extraction Services Version 15.0.42358 (01a7f7ea050d), Built May 20 2021 18:20:45\nUser ID: 9008895\nExtraction ID: 2000000276543637\nSchedule: 0x079cfda70adcdd0c (ID = 0x0000000000000000)\nInput List (2 items): (ID = 0x079cfda70adcdd0c) Created: 06/30/2021 09:15:46 Last Modified: 06/30/2021 09:15:46\nReport Template (3 fields): _OnD_0x079cfda70adcdd0c (ID = 0x079cfda70afcdd0c) Created: 06/30/2021 09:14:12 Last Modified: 06/30/2021 09:14:12\nSchedule dispatched via message queue (0x079cfda70adcdd0c), Data source identifier (6E0CE43BA1044BF58F63D9D50AB9DCFF)\nSchedule Time: 06/30/2021 09:14:12\nProcessing started at 06/30/2021 09:14:12\nProcessing completed successfully at 06/30/2021 09:15:47\nExtraction finished at 06/30/2021 08:15:47 UTC, with servers: tm04n03, TRTH (87.507 secs)\nInstrument <RIC,AAPL.O> expanded to 1 RIC: AAPL.O.\nInstrument <RIC,IBM.N> expanded to 1 RIC: IBM.N.\nTotal instruments after instrument expansion = 2\n\nQuota Message: INFO: Tick History Cash Quota Count Before Extraction: 3190; Instruments Approved for Extraction: 1; Tick History Cash Quota Count After Extraction: 3190, 638% of Limit; Tick History Cash Quota Limit: 500\nManifest: #RIC,Domain,Start,End,Status,Count\nManifest: AAPL.O,Market Price,2017-09-28T23:02:04.589932217Z,2017-09-29T10:59:52.746759914Z,Active,157\nManifest: IBM.N,Market Price,,,Inactive,0\n"
]
}
The JobId can be used to download a file and the Notes contains the extraction's information.
You need to print the Notes to verify what the problem is.
request_response.json()["Notes"]
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 684 Datastream
- 1.4K DSS
- 614 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 248 ETA
- 552 WebSocket API
- 37 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 639 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 26 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 191 TREP Infrastructure
- 228 TRKD
- 915 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 91 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛