mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
use promise.all to handle multiple fetch instances
This commit is contained in:
parent
76949ed4f2
commit
e196d7dfb1
|
@ -30,7 +30,7 @@ const ReportDetails = (props: ReportDetailsProps) => {
|
|||
}, [props.runID])
|
||||
|
||||
return <Container>
|
||||
<h2>Back-test Run ${props.runID}</h2>
|
||||
<h2>Back-test Run {props.runID}</h2>
|
||||
<div>
|
||||
<TradingViewChart basePath={props.basePath} runID={props.runID} intervals={["1m", "5m", "1h"]}/>
|
||||
</div>
|
||||
|
|
|
@ -84,10 +84,6 @@ const fetchPositionHistory = (basePath, runID, setter) => {
|
|||
)
|
||||
.then((response) => response.text())
|
||||
.then((data) => tsvParse(data, parsePosition()))
|
||||
// .then((data) => tsvParse(data))
|
||||
.then((data) => {
|
||||
setter(data);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("failed to fetch orders", e)
|
||||
});
|
||||
|
@ -216,9 +212,6 @@ function fetchKLines(basePath, runID, symbol, interval, setter) {
|
|||
.then((response) => response.text())
|
||||
.then((data) => tsvParse(data, parseKline()))
|
||||
// .then((data) => tsvParse(data))
|
||||
.then((data) => {
|
||||
setter(removeDuplicatedKLines(data));
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("failed to fetch klines", e)
|
||||
});
|
||||
|
@ -306,16 +299,23 @@ const TradingViewChart = (props) => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!data || !orders || !markers || !positionHistory) {
|
||||
fetchKLines(props.basePath, props.runID, 'ETHUSDT', currentInterval, setData).then(() => {
|
||||
fetchOrders(props.basePath, props.runID, (orders) => {
|
||||
setOrders(orders);
|
||||
if (!data) {
|
||||
const ordersFetcher = fetchOrders(props.basePath, props.runID, (orders) => {
|
||||
const markers = ordersToMarkets(currentInterval, orders);
|
||||
setOrders(orders);
|
||||
setMarkers(markers);
|
||||
});
|
||||
|
||||
const positionHistoryFetcher = fetchPositionHistory(props.basePath, props.runID).then((data) => {
|
||||
setPositionHistory(data);
|
||||
});
|
||||
|
||||
Promise.all([ordersFetcher, positionHistoryFetcher]).then(() => {
|
||||
fetchKLines(props.basePath, props.runID, 'ETHUSDT', currentInterval).then((data) => {
|
||||
setData(removeDuplicatedKLines(data));
|
||||
})
|
||||
});
|
||||
|
||||
const markers = ordersToMarkets(currentInterval, orders);
|
||||
setMarkers(markers);
|
||||
});
|
||||
fetchPositionHistory(props.basePath, props.runID, setPositionHistory)
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ const TradingViewChart = (props) => {
|
|||
return () => {
|
||||
chart.current.remove();
|
||||
};
|
||||
}, [chart.current, props.runID, data, currentInterval])
|
||||
}, [props.runID, currentInterval, data])
|
||||
|
||||
// see:
|
||||
// https://codesandbox.io/s/9inkb?file=/src/styles.css
|
||||
|
|
Loading…
Reference in New Issue
Block a user