PYTHON API Extraction Not Yielding Results

SamGarcia
SamGarcia LSEG
edited March 21 in TRTH

Hi Team,

Hoping for your help in checking the code of the client below, for some reason, they are not receiving any results when querying for MarketDepth:

Code:

def ExtractRaw(token, json_payload):
    try:
        outputfilepath = str(_outputFilePath + _outputFileName + str(os.getpid()) + '.csv.gz')
        if os.path.exists(outputfilepath):
            print(f"File {outputfilepath} already exists. Loading data from local file.")
            df = pd.read_csv(outputfilepath, compression='gzip')
        else:   
          _extractRawURL="https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/ExtractRaw"
          _header={}
          _header['Prefer']='respond-async'
          _header['Content-Type']='application/json; odata.metadata=minimal'
          _header['Accept-Charset']='UTF-8'
          _header['Authorization']='Token'+token
 
          resp=post(_extractRawURL,data=None,json=json_payload,headers=_header)
 
          if resp.status_code!=200:
              if resp.status_code!=202:
                  message="Error: Status Code:"+str(resp.status_code)+" Message:"+resp.text
                  raise Exception(message)
 
              _location=resp.headers['Location']
              print("Get Status from "+str(_location))
              _jobID=""
 
              while True:
                  resp=get(_location,headers=_header)
                  _pollstatus = int(resp.status_code)
 
                  if _pollstatus==200:
                      break
                  else:
                      print("Status:"+str(resp.headers['Status']))
                  sleep(_retryInterval) #wait for _retyInterval period and re-request the status to check if it already completed
 
          json_resp = loads(resp.text)
          _jobID = json_resp.get('JobId')
 
          _getResultURL = str("https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/RawExtractionResults(/'" + _jobID + "\')/$value")
          print("Retrieve result from "+_getResultURL)
          resp=get(_getResultURL,headers=_header,stream=True)
          response_content = resp.content  # This retrieves the response content as bytes
          response_size = len(response_content)  # Calculate the size in bytes
          print(f"Size of response: {response_size} bytes")
Screenshot 2025-03-20 073955.png

Answers

  • Hi @SamGarcia ,

    I have tried the request you're using and got the result properly

    1.extraction request, got http 202 response

    image.png

    2.From that, retrieve the result and got http 200 response with data

    image.png

    Could you please try printing the response status code and text (if any) for more information.

  • Hi @SamGarcia ,

    I've tried running the code you've posted and got the result properly with the content returned. It would be great if we can see the response you got in more detail (status code and its content)

    image.png

    Here's the resources related to Tick History

    I hope this helps and please let me know in case you have any further questions.

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @SamGarcia

    The _getResultURL variable should look like this:

    _getResultURL = str("https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/RawExtractionResults('" + _jobID + "')/$value")
    
  • onionw
    onionw Newcomer

    Hello All,

    is that possible that is related to my account permission? I am still not able to fetch data via python code. I have changed _getResultURL as suggested.

    these are cases:
    1.   "Identifier": "0#LCO:",  "IdentifierType": "ChainRIC", "QueryStartDate": "2025-03-13T04:30:00.000Z", my py code get data,

    2.  "Identifier": "0#LCO:",  "IdentifierType": "ChainRIC", "QueryStartDate": "2023-03-13T04:30:00.000Z", my py code cannot get data,

    please let me know how to debug further? how to fix it?

    image.png image.png
  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @onionw

    When the extraction is completed and the status code is 200. The response will contain the JobId and Notes.

    image.png

    You need to print the Notes so we can check the extraction information. The code should be like this:

    image.png
  • onionw
    onionw Newcomer

    Hello, this is output. looks like permission issue? is that something you can help

    Send Login requestStatus: 200{'@odata.context': 'https://selectapi.datascope.refinitiv.com/RestApi/v1/$metadata#RawExtractionResults/$entity', 'JobId': '0x0952bf3b65baf18f', 'Notes': ["Extraction Services Version 18.3.1.48082 (0d5e6bbb8e4a), Built Jan 10 2025 19:16:51\nUser ID: 9038901\nExtraction ID: 2000000884346978\nCorrelation ID: CiD/9038901/AAAAAA.0952bf3b65aaf18f/RA\nSchedule: 0x0952bf3b65baf18f (ID = 0x0000000000000000)\nInput List (1 items): (ID = 0x0952bf3b65baf18f) Created: 21-03-2025 10:11:01 Last Modified: 21-03-2025 10:11:01\nReport Template (4 fields): _OnD_0x0952bf3b65baf18f (ID = 0x0952bf3b65caf18f) Created: 21-03-2025 10:10:57 Last Modified: 21-03-2025 10:10:57\nSchedule dispatched via message queue (0x0952bf3b65baf18f)\nSchedule Time: 21-03-2025 10:10:58\nProcessing started at 21-03-2025 10:10:58\nProcessing completed successfully at 21-03-2025 10:11:02\nExtraction finished at 21-03-2025 10:11:02 UTC, with servers: xc09rbjpQ08\nInstrument <CHR,0#LCO:> expanded to 84 RIC instances: LCOF0 to LCOZ9.\nTotal instruments after instrument expansion = 84\n\n\n(CHR,0#LCO:,IEU,LCOTOT) row suppressed for lack of 'Distribution Rights - Tick History never allowed for PE 0' permission.\nYour request was truncated due to your Contract Entitlement\nReport suppressed because no instruments are permitted\n"]}Getting result from: https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/RawExtractionResults('0x0952bf3b65baf18f')/$valueSize of response: 0 bytesError: Response content is empty.

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @onionw

    Sorry. I can't modify the permission.

    Please contact your LSEG account team or sales team directly to verify your account's permission.