Merge pull request #622 from c9s/feature/backtest-report

fix: back-test report: load position from the manifest
This commit is contained in:
Yo-An Lin 2022-05-18 02:38:02 +08:00 committed by GitHub
commit 1094f0768b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 19 deletions

View File

@ -40,7 +40,7 @@ const ReportDetails = (props: ReportDetailsProps) => {
<div>
{
reportSummary.symbols.map((symbol: string) => {
return <TradingViewChart basePath={props.basePath} runID={props.runID} symbol={symbol} intervals={["1m", "5m", "1h"]}/>
return <TradingViewChart basePath={props.basePath} runID={props.runID} reportSummary={reportSummary} symbol={symbol} intervals={["1m", "5m", "1h"]}/>
})
}

View File

@ -77,10 +77,9 @@ const parsePosition = () => {
};
}
const fetchPositionHistory = (basePath, runID) => {
// TODO: load the filename from the manifest
const fetchPositionHistory = (basePath, runID, filename) => {
return fetch(
`${basePath}/${runID}/bollmaker:ETHUSDT-position.tsv`,
`${basePath}/${runID}/${filename}`,
)
.then((response) => response.text())
.then((data) => tsvParse(data, parsePosition()))
@ -300,17 +299,25 @@ const TradingViewChart = (props) => {
}
if (!data) {
const fetchers = [];
const ordersFetcher = fetchOrders(props.basePath, props.runID, (orders) => {
const markers = ordersToMarkets(currentInterval, orders);
setOrders(orders);
setMarkers(markers);
});
fetchers.push(ordersFetcher);
const positionHistoryFetcher = fetchPositionHistory(props.basePath, props.runID).then((data) => {
setPositionHistory(data);
});
if (props.reportSummary && props.reportSummary.manifests && props.reportSummary.manifests.length === 1) {
const manifest = props.reportSummary?.manifests[0];
if (manifest && manifest.type === "strategyProperty" && manifest.strategyProperty === "position") {
const positionHistoryFetcher = fetchPositionHistory(props.basePath, props.runID, manifest.filename).then((data) => {
setPositionHistory(data);
});
fetchers.push(positionHistoryFetcher);
}
}
Promise.all([ordersFetcher, positionHistoryFetcher]).then(() => {
Promise.all(fetchers).then(() => {
fetchKLines(props.basePath, props.runID, props.symbol, currentInterval).then((data) => {
setData(removeDuplicatedKLines(data));
})
@ -362,17 +369,18 @@ const TradingViewChart = (props) => {
series.setData(data);
series.setMarkers(markers);
const lineSeries = chart.current.addLineSeries();
const costLine = positionAverageCostHistoryToLineData(currentInterval, positionHistory);
lineSeries.setData(costLine);
const baseLineSeries = chart.current.addLineSeries({
priceScaleId: 'left',
color: '#98338C',
});
const baseLine = positionBaseHistoryToLineData(currentInterval, positionHistory)
baseLineSeries.setData(baseLine);
if (positionHistory) {
const lineSeries = chart.current.addLineSeries();
const costLine = positionAverageCostHistoryToLineData(currentInterval, positionHistory);
lineSeries.setData(costLine);
const baseLineSeries = chart.current.addLineSeries({
priceScaleId: 'left',
color: '#98338C',
});
const baseLine = positionBaseHistoryToLineData(currentInterval, positionHistory)
baseLineSeries.setData(baseLine);
}
const volumeData = klinesToVolumeData(data);
const volumeSeries = chart.current.addHistogramSeries({
@ -394,7 +402,7 @@ const TradingViewChart = (props) => {
chart.current.remove();
setData(null);
};
}, [props.runID, currentInterval, data])
}, [props.runID, props.reportSummary, currentInterval, data])
// see:
// https://codesandbox.io/s/9inkb?file=/src/styles.css