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

[type] getHistoricalRates result can be a string #153

Closed dawadam closed 10 months ago

dawadam commented 1 year ago

When using format "csv", result of getHistoricalRates methode is string, but result type not.

Leo4815162342 commented 1 year ago

@dawadam what version of package are you using? can you share the exact script you're running?

dawadam commented 1 year ago

I'm using the latest version, but it works now. Probably a typing error.

        const since = 1690848000000
        const h24 = 60 * 1000 * 60 * 24 * 5
        //
        const testConfigRequest: Config = {
            instrument: 'eurusd',
            dates: {
                from: since,
                to: since + h24,
            },
            timeframe: 'm1',
            format: "csv"
        }

        const test: string = await getHistoricalRates(testConfigRequest)

Why ConfigCsvItem interface and others are not exported ?

Leo4815162342 commented 1 year ago

@dawadam there is an expoerted csv-based config: CurrentRatesConfigCsv

import { CurrentRatesConfigCsv } from 'dukascopy-node';

if you are on one of the latest version of typescript (4.9+) you can use 'satisfies' keyword that preserves "narrowness" of the input config and allows for proper inference of the output type:

const testConfigRequest = {
    instrument: 'eurusd',
    dates: {
      from: since,
      to: since + h24,
    },
    timeframe: 'm1',
    format: 'csv',
  } satisfies CurrentRatesConfigCsv;
  const test = await getHistoricalRates(testConfigRequest);
      //^ const test: string

or with Config

  const since = 1690848000000;
  const h24 = 60 * 1000 * 60 * 24 * 5;
  //
  const testConfigRequest = {
    instrument: 'eurusd',
    dates: {
      from: since,
      to: since + h24,
    },
    timeframe: 'm1',
    format: 'csv',
  } satisfies Config;
  const test = await getHistoricalRates(testConfigRequest)
      //^ const test: string
Screenshot 2023-08-14 at 15 09 30