mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
load position from the manifest
This commit is contained in:
parent
b22996a4ee
commit
d99a5a78e0
|
@ -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) {
|
||||||
setPositionHistory(data);
|
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) => {
|
fetchKLines(props.basePath, props.runID, props.symbol, currentInterval).then((data) => {
|
||||||
setData(removeDuplicatedKLines(data));
|
setData(removeDuplicatedKLines(data));
|
||||||
})
|
})
|
||||||
|
@ -362,17 +369,18 @@ const TradingViewChart = (props) => {
|
||||||
series.setData(data);
|
series.setData(data);
|
||||||
series.setMarkers(markers);
|
series.setMarkers(markers);
|
||||||
|
|
||||||
const lineSeries = chart.current.addLineSeries();
|
if (positionHistory) {
|
||||||
const costLine = positionAverageCostHistoryToLineData(currentInterval, positionHistory);
|
const lineSeries = chart.current.addLineSeries();
|
||||||
lineSeries.setData(costLine);
|
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 baseLineSeries = chart.current.addLineSeries({
|
||||||
|
priceScaleId: 'left',
|
||||||
|
color: '#98338C',
|
||||||
|
});
|
||||||
|
const baseLine = positionBaseHistoryToLineData(currentInterval, positionHistory)
|
||||||
|
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