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)

Best Answer

Answers

  • Hello @AnuragShetty

    I am not sure what you are trying to do in this code. If your intention is to extract the data for an asset at a particular time (intraday extraction), then please use On-Demand extraction - IntradayPricing Extraction Request.

    You can how this on demand extraction is used in the following repo on GitHub -

    https://github.com/LSEG-API-Samples/Example.DataScope.Python.EarlyPartialReport

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @AnuragShetty

    Please also refer to the answer on this discussion.

    You need to check if you would like to use the immediate scheduled extraction or on-demand extraction. You can't specify instruments (InstrumentIdentifiers) directly in a scheduled extraction request message.

  • Hello @Jirapongse , Thank you so much for the reply, we are picking this item back up now so appreciate the help. One question i had is where do we get the List Id and ReportTemplateID for my request? My request is to extract CNH and CNY prices on a daily basis as of 4:30 PM SGT.

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @AnuragShetty

    You can get the List ID and ReportTemplateID from the DSS Web UI or the REST API.

    From the DSS Web UI, you can select the required instrument list or required report template. The ID will be displayed in the URL.

    image.png image.png

    From the API, you can get all instrument IDs or report templates, or search it by its name.

    Use the following endpoints to list all instrument lists or report templates.

    • Instrument: GET https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/InstrumentLists
    • Report Template: GET https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/ReportTemplates

    Use the following endpoints to search it by its name.

    • Instrument: GET https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/InstrumentListGetByName(ListName='<list_name>')
    • Report Template: GET https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/ReportTemplateGetByName(Name='<report_name>')
  • Hello @Jirapa_Singnoi

    I tried setting up my code to get the price at 8:30 AM UTC but it doesnt seem to work, could you please help me with it

    Code

    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_3",
    "TimeZone": "Coordinated Universal Time",
    "Recurrence":
    {
    "@odata .type": "#DataScope.Select.Api.Extractions.Schedules.SingleRecurrence",
    "ExtractionDateTime": "2025-08-08T08:30:00.000Z",
    "IsImmediate": "TRUE"
    },
    "Trigger":
    {
    "@odata .type": "#DataScope.Select.Api.Extractions.Schedules.ImmediateTrigger",
    "LimitReportToTodaysData": "TRUE"
    },

    "ListId": "0x097f476f72eb43f0",
    "ReportTemplateId": "0x097a61595a9b3b46"

    }

    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}")

    End of Code

    Also it seems to throw an error that scheduled already exists and i need to rename it every time i run, maybe this is a one time thing and i need to write some more code to get the actual price could you please help

    image.png
  • Jirapongse
    Jirapongse ✭✭✭✭✭

    Why don't you use on-demand extractions instead of immediate extractions to get data?

    On-demand extractions are more suitable to this use case.

    Please refer to the REST API Tutorial 2: On Demand End of Day Extraction tutorial for more information.

  • Hi @Jirapongse , Agreed we had actually setup our whole process around EOD pricing template but our end user need the spot rates at exactly 4:30 SGT hence we were exploring this template , there is i believe Elektron template which gives spot rate at 4:00PM SGT but again the end users are insisting on getting the rates at 4:30 PM SGT daily,

    After i create this schedule how do i extract the data

  • Thank you, the article you provided was super helpful, I am able to create schedule on GUI and extract using API