Dealing with Errors and Empty Data
When downloading historical price data for stocks and other instruments using dukascopy-node
, it is important to be aware that the library is dependent on external datafeed servers that may return empty responses or errors.
By default, dukascopy-node
will throw an error if a request errors out, and will not make any retries if a request returns an empty response. However, the library provides built-in mechanisms to help you handle these situations.
Retrying Failed Requests
If a request for data errors out, you can use the --retries
parameter (or retryCount
for Node.js) to retry the request. The parameter specifies the number of retries to attempt before the library throws an error.
npx dukascopy-node -i usdcad -from 2023-05-11 -to 2023-05-12 -t tick -f csv --retries 15
Retrying Empty Responses
Sometimes a request returns a successful response, but with empty data. In such cases, you can use the --retry-on-empty
parameter (or retryOnEmpty
for Node.js) to retry the request until the response is no longer empty. This parameter works in conjunction with the --retries
parameter and will also throw an error if the maximum number of retries is exhausted.
npx dukascopy-node -i usdcad -from 2023-05-11 -to 2023-05-12 -t tick -f csv --retries 15 --retry-on-empty
Handling Exhausted Retries
If you do not want an error to be thrown when the maximum number of retries is exhausted, you can use the --no-fail-after-retries
parameter (or failAfterRetryCount
for Node.js). This parameter prevents the library from throwing an error when the maximum number of retries is exhausted, and instead returns an empty response.
npx dukascopy-node -i usdcad -from 2023-05-11 -to 2023-05-12 -t tick -f csv --retries 15 --retry-on-empty --no-fail-after-retries