import requests import json import shutil import time class Credentials(object): requestUrl = "https://hosted.datascopeapi.reuters.com/RestApi/v1/Authentication/RequestToken" requestHeaders={ "Prefer":"respond-async", "Content-Type":"application/json" } requestBody={ "Credentials": { "Username": "myUserName", "Password": "myPassword" } } def __init__(self, uname,pwd): self.requestBody['Credentials']['Username'] = uname self.requestBody['Credentials']['Password'] = pwd usr = 'usr' pwd = 'pwd' c = Credentials (usr,pwd) filePath = "C:/" fileNameRoot = "Python_Test3" start_time = time.time() r1 = requests.post(c.requestUrl, json=c.requestBody,headers=c.requestHeaders) if r1.status_code == 200 : jsonResponse = json.loads(r1.text.encode('ascii', 'ignore')) token = jsonResponse["value"] print ('Authentication token (valid 24 hours):') print (token) else: print ('Please replace myUserName and myPassword with valid credentials, then repeat the request') print('check point #0') print("--- %s seconds ---" % (time.time() - start_time)) requestUrl='https://hosted.datascopeapi.reuters.com/RestApi/v1/Extractions/ExtractRaw' requestHeaders={ "Prefer":"respond-async; wait=0", "Content-Type":"application/json", "Authorization": "token " + token, } requestBody={ "ExtractionRequest": { "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.TickHistoryTimeAndSalesExtractionRequest", "ContentFieldNames": [ "Trade - Price", "Trade - Volume", "Trade - Exchange Time" ], "IdentifierList": { "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.InstrumentIdentifierList", "InstrumentIdentifiers": [{ "Identifier": "SXFM7", "IdentifierType": "Ric" }], "ValidationOptions": { "AllowHistoricalInstruments": "true" }, "UseUserPreferencesForValidationOptions": "false", }, "Condition": { "MessageTimeStampIn": "GmtUtc", "ApplyCorrectionsAndCancellations": "false", "ReportDateRangeType": "Range", "QueryStartDate": "2017-05-30T01:00:00.000Z", "QueryEndDate": "2017-06-02T23:59:00.000Z", "DisplaySourceRIC": "true" } } } r2 = requests.post(requestUrl, json=requestBody,headers=requestHeaders) print (r2.status_code) requestUrl = r2.headers["location"] requestHeaders={ "Prefer":"respond-async", "Content-Type":"application/json", "Authorization":"token " + token } print('check point #1') print("--- %s seconds ---" % (time.time() - start_time)) r3 = requests.get(requestUrl,headers=requestHeaders) #When the status of the request is 200 the extraction is complete, we display the jobId and the extraction notes print ('response status = ' + str(r3.status_code)) print('check point #2') print("--- %s seconds ---" % (time.time() - start_time))