Leo4815162342 / dukascopy-node

✨ Download historical price tick data for Crypto, Stocks, ETFs, CFDs, Forex via CLI and Node.js ✨
https://dukascopy-node.app
MIT License
350 stars 66 forks source link

Unable to fetch partial days #163

Closed ivnnv closed 10 months ago

ivnnv commented 10 months ago

Hi, Im trying to fetch data from some timeranges that are not "full days" as all the examples shown, so something like this doesnt seems to work:

const { getHistoricalRates } = require("dukascopy-node");

(async () => {
  const historicalRates = await getHistoricalRates({
    instrument: "audusd",
    dates: {
      from: new Date("2019-06-09 08:24"), // it does work with just  "2019-06-09"
      to: new Date("2019-06-09 18:24"),   // it does work with just  "2019-06-10"
    },
    timeframe: "m1",
  });
  console.log(historicalRates);
})();

Link to runkit

Is this true? workaround seems to fetch the full days between the needed ranges but ideally this should be managed internally

Leo4815162342 commented 10 months ago

@ivnnv 2019-06-09 (June 9th 2019) was Sunday which is not a trading day on forex markets. For that date, Dukascopy has data only after 2019-06-09 21:00 UTC.

This means that within range between 2019-06-09 08:24 and 2019-06-09 18:24 there is no data, that is why you are receiving an empty array.

However, when requesting data between 2019-06-09 and 2019-06-10, dukascopy-node will convert it to something likes this 2019-06-09 00:00 - 2019-06-10 00:00, and since the only available starting point for this date is 21:00 , it will fetch the data for a range of 2019-06-09 21:00 - 2019-06-10 00:00 - which is 3 hours, or 180 minute candles, which is exactly the output you're getting.

ivnnv commented 10 months ago

Hi, sorry I didnt checked the date was indeed, Sunday, it works exactly as expected on date range: 2019-06-07 11:24 2019-06-07 11:26 and returns as expected, only two records.

Thanks for checking and the detailed explanation tho. 👍🏽