Update code from RDP to RD

Hello,

can you please help us to update this code snippet we used to play with rdp but not working anymore with rd.

if (response.status["http_status_code"] == 202):

#getting the status of the calculation ('not started', 'running', 'succeeded')

status_url = "https://api.refinitiv.com" + response.headers["location"]

status_endpoint = rdp.Endpoint(session, status_url)

status = "not_started"

while(status != "succeeded" and status != "failed"):

status_response = status_endpoint.send_request(method = rdp.Endpoint.RequestMethod.GET)

status = status_response.data.raw["status"]

time.sleep(1)


#when the status changes to 'succeeded', use the 'resourcelocation' url to retrieve the response

response_url = "https://api.refinitiv.com" + status_response.data.raw["resourceLocation"]

print(response_url)

respone_endpoint = rdp.Endpoint(session, response_url)

response = respone_endpoint.send_request(method = rdp.Endpoint.RequestMethod.GET)


print(response.data.raw)

import pandas as pd


headers_name = [h['name'] for h in response.data.raw['headers']]

df = pd.DataFrame(data=response.data.raw['data'], columns=headers_name)

df

Best Answer

  • pf
    pf
    Answer ✓

    Hi @ariele.zeidman ,

    I understand that code snippet implements a retry to get a result on http status code 202 until status is 'succeedeed' or 'failed', based on 'location' and 'resoureceLcoation' response's headers, so I assume you're requesting /data/quantitative-analytics/v1/async-financial-contracts endpoint.
    Could you confirm this ?

    If it's the case, rd lib implement the workflow for you, so you just have to send your request using rd.content.ipa.financial_contracts.xxx API.

    If you provide the code that provide your response, we'll be able to provide the suitable code to do the same without havind to test http_status_code 202.

Answers