async function main(fetchFn, csvFn, csvHeaders) {
    const config = JSON.parse(fs.readFileSync(argv.keyFile))
    const exchangeId = argv.exchange
        , exchangeClass = ccxt[exchangeId]
        , exchange = new exchangeClass(config)

    const {startDate, endDate} = getRequestDates()

    const totalDaysDifference = differenceInDays(endDate, startDate)

    let history = [];

    for(let i = 0; i < totalDaysDifference; i++) {
        history = history.concat(await fetchFn(exchange, addDays(startDate, i), addDays(startDate, i+1)))
    }

    const uniqueHistory = deDuplicateHistory(history)
    uniqueHistory.sort((a,b) => b.date - a.date)
    const csvLines = uniqueHistory.reduce((a,c) => {
        a.push(csvFn(c))
        return a
    }, csvHeaders)

    if(argv.outFile !== undefined) {
        fs.writeFileSync(argv.outFile, csvLines.join('\n'))
        console.log('Data written to file ' + argv.outFile)
    }
    else {
        csvLines.forEach(line => console.log(line))
    }
}
@param {{(exchange: *, start: Date, end: Date) => Promise<[]>}} fetchFn
@param {{(history: *) => string}} csvFn
@param {string[]} csvHeaders