Merge pull request #713 from andycheng123/improve/share-kline

improve: share klines tsv
This commit is contained in:
Yo-An Lin 2022-06-16 07:33:43 +08:00 committed by GitHub
commit 4ef10d1dc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import {Button} from '@mantine/core';
// const createChart = dynamic(() => import('lightweight-charts')); // const createChart = dynamic(() => import('lightweight-charts'));
import {createChart, CrosshairMode} from 'lightweight-charts'; import {createChart, CrosshairMode} from 'lightweight-charts';
import {ReportSummary} from "../types"; import {ReportSummary} from "../types";
import moment from "moment";
const parseKline = () => { const parseKline = () => {
return (d : any) => { return (d : any) => {
@ -209,9 +210,10 @@ const removeDuplicatedKLines = (klines: Array<KLine>): Array<KLine> => {
return newK; 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( return fetch(
`${basePath}/${runID}/klines/${symbol}-${interval}.tsv`, `${basePath}/shared/klines_${duration.join('-')}/${symbol}-${interval}.tsv`,
) )
.then((response) => response.text()) .then((response) => response.text())
.then((data) => tsvParse(data, parseKline())) .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<KLine>) chartData.klines = removeDuplicatedKLines(klines as Array<KLine>)
}); });
fetchers.push(kLinesFetcher); fetchers.push(kLinesFetcher);

View File

@ -291,8 +291,14 @@ var BacktestCmd = &cobra.Command{
// reportDir = filepath.Join(reportDir, backtestSessionName) // reportDir = filepath.Join(reportDir, backtestSessionName)
reportDir = filepath.Join(reportDir, runID) 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 { if err := util.SafeMkdirAll(kLineDataDir); err != nil {
return err return err
} }