mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
Merge pull request #622 from c9s/feature/backtest-report
fix: back-test report: load position from the manifest
This commit is contained in:
commit
1094f0768b
|
@ -40,7 +40,7 @@ const ReportDetails = (props: ReportDetailsProps) => {
|
||||||
<div>
|
<div>
|
||||||
{
|
{
|
||||||
reportSummary.symbols.map((symbol: string) => {
|
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"]}/>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,10 +77,9 @@ const parsePosition = () => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchPositionHistory = (basePath, runID) => {
|
const fetchPositionHistory = (basePath, runID, filename) => {
|
||||||
// TODO: load the filename from the manifest
|
|
||||||
return fetch(
|
return fetch(
|
||||||
`${basePath}/${runID}/bollmaker:ETHUSDT-position.tsv`,
|
`${basePath}/${runID}/${filename}`,
|
||||||
)
|
)
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((data) => tsvParse(data, parsePosition()))
|
.then((data) => tsvParse(data, parsePosition()))
|
||||||
|
@ -300,17 +299,25 @@ const TradingViewChart = (props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
const fetchers = [];
|
||||||
const ordersFetcher = fetchOrders(props.basePath, props.runID, (orders) => {
|
const ordersFetcher = fetchOrders(props.basePath, props.runID, (orders) => {
|
||||||
const markers = ordersToMarkets(currentInterval, orders);
|
const markers = ordersToMarkets(currentInterval, orders);
|
||||||
setOrders(orders);
|
setOrders(orders);
|
||||||
setMarkers(markers);
|
setMarkers(markers);
|
||||||
});
|
});
|
||||||
|
fetchers.push(ordersFetcher);
|
||||||
|
|
||||||
const positionHistoryFetcher = fetchPositionHistory(props.basePath, props.runID).then((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);
|
setPositionHistory(data);
|
||||||
});
|
});
|
||||||
|
fetchers.push(positionHistoryFetcher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Promise.all([ordersFetcher, positionHistoryFetcher]).then(() => {
|
Promise.all(fetchers).then(() => {
|
||||||
fetchKLines(props.basePath, props.runID, props.symbol, currentInterval).then((data) => {
|
fetchKLines(props.basePath, props.runID, props.symbol, currentInterval).then((data) => {
|
||||||
setData(removeDuplicatedKLines(data));
|
setData(removeDuplicatedKLines(data));
|
||||||
})
|
})
|
||||||
|
@ -362,6 +369,7 @@ const TradingViewChart = (props) => {
|
||||||
series.setData(data);
|
series.setData(data);
|
||||||
series.setMarkers(markers);
|
series.setMarkers(markers);
|
||||||
|
|
||||||
|
if (positionHistory) {
|
||||||
const lineSeries = chart.current.addLineSeries();
|
const lineSeries = chart.current.addLineSeries();
|
||||||
const costLine = positionAverageCostHistoryToLineData(currentInterval, positionHistory);
|
const costLine = positionAverageCostHistoryToLineData(currentInterval, positionHistory);
|
||||||
lineSeries.setData(costLine);
|
lineSeries.setData(costLine);
|
||||||
|
@ -372,7 +380,7 @@ const TradingViewChart = (props) => {
|
||||||
});
|
});
|
||||||
const baseLine = positionBaseHistoryToLineData(currentInterval, positionHistory)
|
const baseLine = positionBaseHistoryToLineData(currentInterval, positionHistory)
|
||||||
baseLineSeries.setData(baseLine);
|
baseLineSeries.setData(baseLine);
|
||||||
|
}
|
||||||
|
|
||||||
const volumeData = klinesToVolumeData(data);
|
const volumeData = klinesToVolumeData(data);
|
||||||
const volumeSeries = chart.current.addHistogramSeries({
|
const volumeSeries = chart.current.addHistogramSeries({
|
||||||
|
@ -394,7 +402,7 @@ const TradingViewChart = (props) => {
|
||||||
chart.current.remove();
|
chart.current.remove();
|
||||||
setData(null);
|
setData(null);
|
||||||
};
|
};
|
||||||
}, [props.runID, currentInterval, data])
|
}, [props.runID, props.reportSummary, currentInterval, data])
|
||||||
|
|
||||||
// see:
|
// see:
|
||||||
// https://codesandbox.io/s/9inkb?file=/src/styles.css
|
// https://codesandbox.io/s/9inkb?file=/src/styles.css
|
||||||
|
|
Loading…
Reference in New Issue
Block a user