UNPKG

quant-zero

Version:

Node-Quant is a powerful Node.js package for developing and testing quantitative trading strategies in cryptocurrency markets, offering tools for backtesting and performance analysis.

37 lines (32 loc) 1.04 kB
import fs from 'fs' import path from 'path' import { CryptoPair, TimeFrame } from '@/types' import exchange from '@/exchange' export default async function downloadPairData( pair: CryptoPair, timeFrame: TimeFrame, dataLength: number, dataFolderPath: string, ) { const fileName = `${pair.replace('/', '_')}_${dataLength}_${timeFrame}.json` const filePath = path.join(dataFolderPath, fileName) if (fs.existsSync(filePath)) { console.log( `Data for ${pair} with length ${dataLength} already exists. Returning existing data.`, ) const existingData = fs.readFileSync(filePath, 'utf-8') return { path: filePath, data: JSON.parse(existingData) } } console.log(`Installing ${dataLength} candles for ${pair}.`) const fetchedData = await exchange.fetchOHLCV( pair, timeFrame, undefined, dataLength, { paginate: true, }, ) fs.writeFileSync(filePath, JSON.stringify(fetchedData, null, 2)) return { path: filePath, data: fetchedData } }