@backtest/framework
Version:
Backtesting trading strategies in TypeScript / JavaScript
43 lines • 2.71 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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");
function importFileCSV(base, quote, interval, path) {
return __awaiter(this, void 0, void 0, function* () {
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 = yield (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