Scheduled price extraction for currencies

AnuragShetty
AnuragShetty Newcomer
edited June 4 in DSS

Trying to extract scheduled price data for CNH and CNY identifiers , i was able to successfully extract EOD pricing for these identifiers but facing error when trying to extract the prices at specific time of day, please find below the API query details along with URL and error message

Code

from ayx import Alteryx
import pandas as pd
import requests
from datetime import datetime
import html

a = Alteryx.read('#1')

token_url = "https://selectapi.datascope.refinitiv.com/RestApi/v1/Authentication/RequestToken"
payload = "{\r\n "Credentials": {\r\n "Username": "9038135",\r\n "Password": "*********"\r\n }\r\n}"
scheduled_price_url="https://selectapi.datascope.refinitiv.com/restapi/v1/Extractions/Schedules"

headers = {
'Prefer': 'respond-async',
'Content-Type': 'application/json'
}

PROXY = {
'http':'http://proxy.jpmchase.net:10443'
, 'https':'http://proxy.jpmchase.net:10443'
}

try:
response = requests.request("POST", token_url, headers=headers, data=payload,proxies = PROXY,verify=False)
print("Successfully connected")
data=response.json()
token=data.get("value")
scheduled_price_header={
'Prefer': 'respond-async',
'Content-Type': 'application/json',
"Authorization": "Token "+token
}

body={
"Name": "TEST Sample EOD Extraction",
"TimeZone": "Coordinated Universal Time",
"Recurrence":
{
"@odata.type": "#DataScope.Select.Api.Extractions.Schedules.SingleRecurrence",
"ExtractionDateTime": "2025-06-03T12:35:00.000",
"IsImmediate": "TRUE"
},
"Trigger":
{
"@odata.type": "#DataScope.Select.Api.Extractions.Schedules.ImmediateTrigger",
"LimitReportToTodaysData": "FALSE"
},
"IdentifierList": {
"@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.InstrumentIdentifierList",
"InstrumentIdentifiers": [
{ "Identifier":"CNH=", "IdentifierType":"Ric" },
{ "Identifier":"CNY=", "IdentifierType":"Ric" },
],
},
"ValidationOptions": None,
"UseUserPreferencesForValidationOptions": "FALSE",
"Condition": None
}

response_close_price=requests.request("POST", scheduled_price_url, headers=scheduled_price_header,json=body, proxies = PROXY,verify=False).json()
print(response_close_price)

except requests.RequestException as e:
print(f"Couldnt connect : {e}")

results=[]
for item in response_close_price.get('Contents'):
identifier=item.get('RIC')
trade_date=item.get('Trade Date')
close_price=item.get('Universal Close Price')
results.extend([{'Identifier':identifier,'Trade Date':trade_date,
'Universal Close Price':close_price}])

results_df=pd.DataFrame(results)

Alteryx.write(results_df, 1)

Answers