diff --git a/apps/backtest-report/components/TradingViewChart.tsx b/apps/backtest-report/components/TradingViewChart.tsx index 5fd4d6c79..5a6937f4c 100644 --- a/apps/backtest-report/components/TradingViewChart.tsx +++ b/apps/backtest-report/components/TradingViewChart.tsx @@ -6,6 +6,7 @@ import {Button} from '@mantine/core'; // const createChart = dynamic(() => import('lightweight-charts')); import {createChart, CrosshairMode} from 'lightweight-charts'; import {ReportSummary} from "../types"; +import moment from "moment"; const parseKline = () => { return (d : any) => { @@ -209,9 +210,10 @@ const removeDuplicatedKLines = (klines: Array): Array => { return newK; } -function fetchKLines(basePath: string, runID: string, symbol: string, interval: string) { +function fetchKLines(basePath: string, runID: string, symbol: string, interval: string, startTime: Date, endTime: Date) { + var duration = [moment(startTime).format('YYYYMMDD'), moment(endTime).format('YYYYMMDD')]; return fetch( - `${basePath}/${runID}/klines/${symbol}-${interval}.tsv`, + `${basePath}/shared/klines_${duration.join('-')}/${symbol}-${interval}.tsv`, ) .then((response) => response.text()) .then((data) => tsvParse(data, parseKline())) @@ -399,7 +401,7 @@ const TradingViewChart = (props: TradingViewChartProps) => { } } - const kLinesFetcher = fetchKLines(props.basePath, props.runID, props.symbol, currentInterval).then((klines) => { + const kLinesFetcher = fetchKLines(props.basePath, props.runID, props.symbol, currentInterval, new Date(props.reportSummary.startTime), new Date(props.reportSummary.endTime)).then((klines) => { chartData.klines = removeDuplicatedKLines(klines as Array) }); fetchers.push(kLinesFetcher); diff --git a/pkg/cmd/backtest.go b/pkg/cmd/backtest.go index 92205c3ce..5d1a706c5 100644 --- a/pkg/cmd/backtest.go +++ b/pkg/cmd/backtest.go @@ -291,8 +291,14 @@ var BacktestCmd = &cobra.Command{ // reportDir = filepath.Join(reportDir, backtestSessionName) reportDir = filepath.Join(reportDir, runID) } + if err := util.SafeMkdirAll(reportDir); err != nil { + return err + } - kLineDataDir := filepath.Join(reportDir, "klines") + startTimeStr := startTime.Format("20060102") + endTimeStr := endTime.Format("20060102") + kLineSubDir := strings.Join([]string{"klines", "_", startTimeStr, "-", endTimeStr}, "") + kLineDataDir := filepath.Join(outputDirectory, "shared", kLineSubDir) if err := util.SafeMkdirAll(kLineDataDir); err != nil { return err }