question

Upvotes
Accepted
3 1 1 1

#Step 4: poll the status of the request using received location URL, and get the jobId and extraction notes

###Step 3: send an on demand extraction request using the received token


requestUrl='https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/ExtractRaw'


requestHeaders={

'Prefer':'respond-async',

'Content-Type':'application/json',

'Authorization': 'token ' + token

}


requestBody={

"ExtractionRequest": {

"@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.TickHistoryTimeAndSalesExtractionRequest",

"ContentFieldNames": [

"Trade - Price",

"Trade - Volume",

"Trade - Exchange Time"

],

'IdentifierList': {

'@odata.type': '#DataScope.Select.Api.Extractions.ExtractionRequests.InstrumentIdentifierList',

'InstrumentIdentifiers': instrumentList,

},

'Condition': {

"MessageTimeStampIn": "GmtUtc",

"ApplyCorrectionsAndCancellations": "false",

"ReportDateRangeType": "Range",

"QueryStartDate": "2016-09-29T00:00:00.000Z",

"QueryEndDate": "2016-09-29T12:00:00.000Z",

"DisplaySourceRIC": "true"

}

}

}


print('sending the extraction request for the list of option RICs')

r3 = requests.post(requestUrl, json=requestBody, headers=requestHeaders)


#Display the response status, and the location url to use to get the status of the extraction request

#Initial response status after approximately 30 seconds wait will be 202

print ('response status from the extraction request = ' + str(r3.status_code))


#If there is a client side or server side error, display the error information and exit

if r3.status_code >= 400 :

print(r3.text.encode('ascii', 'ignore'))

sys.exit()


#Step 4: poll the status of the request using received location URL, and get the jobId and extraction notes


requestUrl = r3.headers['location']


requestHeaders={

'Prefer': 'respond-async',

'Content-Type': 'application/json',

'Authorization': 'token ' + token

}


r4 = requests.get(requestUrl, headers=requestHeaders)


#The extraction may take a long time for large content sets

#While the extraction is being processed on the server the request status we receive is 202

#We're polling the service for the status every 30 seconds until the status is 200


while r4.status_code == 202 :

r4 = requests.get(requestUrl, headers=requestHeaders)

print (str(dt.datetime.now()) + ' Server is still processing the extraction. Checking the status again in 30 seconds')

time.sleep(30)


---run the code and then the error code as below, please help.


sending the extraction request for the list of option RICs
response status from the extraction request = 200


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-36-ed1cf426d309> in <module>
     46 #Step 4: poll the status of the request using received location URL, and get the jobId and extraction notes
     47 
---> 48 requestUrl = r3.headers['location']
     49 
     50 requestHeaders={

C:\ProgramData\Anaconda3\lib\site-packages\requests\structures.py in __getitem__(self, key)
     50 
     51     def __getitem__(self, key):
---> 52         return self._store[key.lower()][1]
     53 
     54     def __delitem__(self, key):

KeyError: 'location'
#producttick-history-rest-api
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.

@georgelocw

Hi,

Thank you for your participation in the forum.

Is the reply below satisfactory in answering your question?

If yes please click the 'Accept' text next to the reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

@georgelocw

Hi,

Please be informed that a reply has been verified as correct in answering the question, and marked as such.

Thanks,

AHS

1 Answer

· Write an Answer
Upvotes
Accepted
79.2k 251 52 74

@georgelocw

Thank you for reaching out to us.

If the status code is 200, there is no need to poll for the status of the request.

Please check the sample code in the LSEG Tick History Python Code Samples.

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.