UNPKG

@backtest/framework

Version:

Backtesting trading strategies in TypeScript / JavaScript

32 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.importFileCSV = importFileCSV; const prisma_historical_data_1 = require("../../helpers/prisma-historical-data"); const common_1 = require("../common"); const csv_1 = require("../../helpers/csv"); const error_1 = require("../../helpers/error"); async function importFileCSV(base, quote, interval, path) { if (!base) { throw new error_1.BacktestError('Base name (ex: BTC in BTCUSDT or APPL in APPL/USD) is required', error_1.ErrorCode.MissingInput); } if (!quote) { throw new error_1.BacktestError('Quote name (ex: USDT in BTCUSDT or USD in APPL/USD) is required', error_1.ErrorCode.MissingInput); } if (!interval || !(0, common_1.isValidInterval)(interval)) { throw new error_1.BacktestError(`Interval is required. Use one of ${(0, common_1.getIntervals)().join(' ')}`, error_1.ErrorCode.MissingInput); } if (!path) { throw new error_1.BacktestError('Path to CSV file is required', error_1.ErrorCode.MissingInput); } const historicalDataSets = await (0, prisma_historical_data_1.getAllCandleMetaData)(); const isHistoricalDataPresent = historicalDataSets.some((meta) => meta.name === `${base + quote}-${interval}`); if (isHistoricalDataPresent) { throw new error_1.BacktestError(`Historical data already found for ${base + quote} with ${interval} interval.`, error_1.ErrorCode.Conflict); } let filePath = path === null || path === void 0 ? void 0 : path.trim(); if ((filePath.startsWith(`"`) && filePath.endsWith(`"`)) || (filePath.startsWith(`'`) && filePath.endsWith(`'`))) { filePath = filePath.substring(1, filePath.length - 1); } return (0, csv_1.importCSV)({ interval, base: base.toUpperCase(), quote: quote.toUpperCase(), path: filePath }); } //# sourceMappingURL=import-csv.js.map