CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage. -- % of retail investor accounts lose money when trading CFDs with this provider. You should consider whether you understand how CFDs work and whether you can afford to take the high risk of losing your money.

Access token keeps expiring

Good morning team,

Hopefully everyone are safe!

I keep getting token expirations on daily basis. I am creating tokens to query my investor account and my Darwin status but it is not working properly.

This morning, when I tried creating a new token from scratch, I get:
Annotation 2020-03-30 092720

Besides that, is there query limitation on the API? Is one query per minute is too much? Do you have some sort of throttling on your end? Do you check the source IP address? I am querying two different accounts one after the other with one second wait time.

Please let me know what could cause this sort of problem.

Roy

Good morning @meshulro,

The access token for accessing all the APIs (investor account, trading …) expires after one hour. Therefore, I’d recommend to renew it each hour using the Refresh Token grant (https://help.darwinex.com/api-walkthrough#refresh3)

There are limits established for each API, for each account and global limitations for everyone. In your case, for the Investor Account Info, the limits applying are the following:

  • 20 requests / minute to all the Investor account info API
  • 50 requests / minute to all APIs
  • 5 request / second to this API for everyone.
    There should not be any problem doing one query per minute, but I’d recommend to apply some sort of retry logic just in case.

About the error happening this morning, we have restarted the API Manager after finding many failed attempts trying to get new access tokens. Could you try again?

Thanks for asking and use our API

2 Likes

Thank you Jesus for your quick response.

I see in the example you are using curl. Do you have exprience to implement this call from C++?

1 Like

Hi @meshulro,

In C++ you can achieve this using libcurl :+1:

Hi @meshulro,
Almost any language can be used for accessing our APIs. My great workmate @integracore2 suggests an option but many libraries for using REST apis can be found over internet: restbed, cpprestsdk, ffead-cpp, … Let us know if you find difficulties using any existing C++ library for trying to renew the token.

1 Like

Ok, I am just surprised this step is requeired as I only use this API to query the latest investor account PnL, that is, a read only query. So, not sure this one hour lifetime is an overhead.

A pleasure to see you here again @meshulro!

Tokens with longer validity are offered for the DARWIN data APIs only. Investor accounts include information specific to the user, hence the restriction in the validity of the token. @jesusbc should correct me if I’m wrong.

You are right,@bianka. We are considering the information about investor accounts as something important and private to the owner of the investor account. We could have implemented additional kind of tokens with different expiry times and/or roles, but it could have added complexity to the usage of the API.