Why am not seeing anything in the response.text for this TickHistoryMarketDepthExtractionRequest

Jwan622
Jwan622 Newcomer
edited March 10 in DSS
def get_futures_tick_data(ticker, query_start_date, query_end_date):
    """
    Fetches historical tick-by-tick futures data from Refinitiv.

    :param ticker: The specific futures contract RIC (e.g., "BTCJ4" for April 2024 Bitcoin Futures)
    :param query_start_date: Start date in ISO format (e.g., "2025-03-01T09:30:00Z")
    :param query_end_date: End date in ISO format (e.g., "2025-03-16T16:00:00Z")
    :return: JSON response containing futures tick data
    """

    json_blob = {
        "ExtractionRequest": {
            "@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.TickHistoryMarketDepthExtractionRequest",
            "IdentifierList": {
                "@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.InstrumentIdentifierList",
                "InstrumentIdentifiers": [{
                    "Identifier": ticker,
                    "IdentifierType": "Ric",
                }],
                "ValidationOptions": None,
                "UseUserPreferencesForValidationOptions": False
            },
            "Condition": {
                "View": "RawMarketByPrice",
                "MessageTimeStampIn": "GmtUtc",
                "ReportDateRangeType": "Range",
                "DisplaySourceRIC": "true",
                "DateRangeTimeZone": "UTC",
                "QueryStartDate": query_start_date,
                "QueryEndDate": query_end_date,
            }
        }
    }

    post_url = URL_BASE + "/Extractions/ExtractRaw"
    response = requests.post(post_url, headers = {
        "Authorization": f"Token {REFINITIV_AUTH_TOKEN}",
        "Content-Type": "application/json"
    }, json = json_blob)

    if response.status_code != 200:
        raise ValueError(f"Failed to fetch tick data: {response.status_code} - {response.text}")

    job_id = response.json().get("JobId")
    if not job_id:
        raise ValueError("No JobId returned. Check request parameters.")

    # Fetch extracted data
    data_url = f"{URL_BASE}/Extractions/RawExtractionResults('{job_id}')/$value"

    data_response = requests.get(data_url, headers = {
        "Authorization": f"Token {REFINITIV_AUTH_TOKEN}"
    }, stream = True)

    data_response.raise_for_status()

    return data_response


def preview_response(response, num_lines=5):
    """
    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


# Example usage:
if __name__ == "__main__":
    # intraday_data = get_embargo_info("FCX")
    # if intraday_data:
    #     print(json.dumps(intraday_data, indent=4))

    # get_sp500()
    # tick_history = get_tick_history("CORZ.NYO", "2025-03-03T09:30:00Z", "2025-03-04T09:30:00Z")
    # preview_response(tick_history)
    tick_data = get_futures_tick_data("0#BTC:", "2025-03-01T09:30:00Z", "2025-03-05T16:00:00Z")
    preview_response(tick_data)

It doen'st work for futures. I want BTC and the ES mini and the Nasdaq. If I put in "AAPL.ARC" it works and I see the data. What can I do to see order book data for these futures? Please show me. I want the order book data updates for futures.

Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Jwan622

    Thank you for reaching out to us.

    The 0#BTC: is a chain RIC so the request should use the "ChainRIC" as an identifierType.

                   "InstrumentIdentifiers": [{
    "Identifier": "0#BTC:",
    "IdentifierType": "ChainRIC"
    }],
  • Jwan622
    Jwan622 Newcomer

    @Jirapongse What is a chain ric? I think I know what it is but… how do I get all the underlying rics of a chain ric? Is there any way for me to get a list of all the rics in a chainric?

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Jwan622

    Typically. chain RICs are prefixed with "0#". A "chain RIC" refers to a collection of individual RICs that are linked together,

    Some requests support the "IdentifierType": "ChainRIC" so you can use chain RICs directly in the request messages.

    To expand it, you can use the TermsAndConditionsExtractionRequest with the Extractions/ExtractWithNotes endpoint

    {
    "ExtractionRequest": {
    "@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.TermsAndConditionsExtractionRequest",
    "ContentFieldNames": [
    "RIC"
    ],
    "IdentifierList": {
    "@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.InstrumentIdentifierList",
    "InstrumentIdentifiers": [
    {
    "Identifier": "0#BTC:",
    "IdentifierType": "ChainRIC"
    }
    ],
    "ValidationOptions": {
    "AllowHistoricalInstruments": true
    }
    }
    }
    }

    Otherwise, you can also use the Historical Chain Constituents Search.