question

Upvotes
Accepted
1 0 0 0

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

#technologyrdprefinitiv-data-libraries
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
Accepted
1.4k 3 2 4

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.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ok clear so can you confirm it works also for https://api.refinitiv.com/data/quantitative-analytics/v1/async-cva


Upvote
11.1k 22 6 9

@ariele.zeidman Thanks for your question. Have you seen the multiple endpoint samples available on the RD lib git here? There are a number of different endpoints covered with code here. What endpoint are you looking to hit? Let me know if these help you.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.