question

Upvotes
Accepted
1 2 0 1

Sample Python script for Quota Checker

Need a sample python script which can perform Quota Checks.

To obtain the quota information through API, please refer to:

<https://hosted.datascopeapi.reuters.com/RestApi.Help/Context/Operation?ctx=Quota&opn=GetQuotaInformation&sce=Quota - Get Quota Information.primary&stp=1&tab=3>

Example

API Request:

GET call
URL https://hosted.datascopeapi.reuters.com/RestApi/v1/Quota/GetQuotaInformation

Headers:

Authorization: Token <your_auth_token_goes_here>

Prefer: respond-async

API Response:

HTTP/1.1 200 OK

{

"@odata.context": "https://hosted.datascopeapi.reuters.com/RestApi/v1/$metadata#Collection(ThomsonReuters.Dss.Api.Quota.Quota)",

"value": [

{

"Count": 1000,

"Limit": 12000,

"Category": {

"Code": "Cash"

}

},

{

"Count": 1500,

"Limit": 12000,

"Category": {

"Code": "Futures"

}

}

]

}

tick-history-rest-apiapi-limits
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.

1 Answer

· Write an Answer
Upvotes
Accepted
11.3k 26 9 14

Hi @Vishy,

You can modify the TRTH_Get_Latest_Schedule_Files.py script in the TRTH Python Code Samples to perform Quota Information request.

- Add REST API call for GetQuotaInformation endpoint.

#Get Quota Information
def getQuotaInformation( token ):
    getQuotaUrl = baseUrl + "Quota/GetQuotaInformation"
    requestHeaders["Authorization"] = "token " + token
    r = requests.get( getQuotaUrl, headers=requestHeaders )
    if (r.status_code==200):
        jsonResponse = json.loads(r.text.encode('ascii', 'ignore'))
        return jsonResponse["value"]
    else:
        print ("ERROR: could not retrieve quota information")
        print ("Status code: ", r.status_code, "\nResponse:\n", r.text)
        sys.exit()

- Modify Main function to call the getQuotaInformation function and print output.

if __name__ == "__main__":
    try:
        token = getAuthenticationToken( myUsername, myPassword )
        print ("Token:\n", token, "\n")

        quotaInfo = getQuotaInformation( token )
        for quota in quotaInfo:
            print (quota)
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.