mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-13 03:33:50 +00:00
parent
5d94fe5f9c
commit
20d3b80d41
|
@ -52,53 +52,54 @@ export default defineComponent({
|
||||||
const botList = ref<string[]>([]);
|
const botList = ref<string[]>([]);
|
||||||
const cumulativeData = ref<{ date: number; profit: any }[]>([]);
|
const cumulativeData = ref<{ date: number; profit: any }[]>([]);
|
||||||
|
|
||||||
watch(
|
const calcCumulativeData = () => {
|
||||||
() => props.trades,
|
console.log('trades');
|
||||||
() => {
|
botList.value = [];
|
||||||
botList.value = [];
|
const res: CumProfitData[] = [];
|
||||||
const res: CumProfitData[] = [];
|
const resD: CumProfitDataPerDate = {};
|
||||||
const resD: CumProfitDataPerDate = {};
|
const closedTrades = props.trades
|
||||||
const closedTrades = props.trades
|
.slice()
|
||||||
.slice()
|
.sort((a, b) => (a.close_timestamp > b.close_timestamp ? 1 : -1));
|
||||||
.sort((a, b) => (a.close_timestamp > b.close_timestamp ? 1 : -1));
|
let profit = 0.0;
|
||||||
let profit = 0.0;
|
|
||||||
|
|
||||||
for (let i = 0, len = closedTrades.length; i < len; i += 1) {
|
for (let i = 0, len = closedTrades.length; i < len; i += 1) {
|
||||||
const trade = closedTrades[i];
|
const trade = closedTrades[i];
|
||||||
|
|
||||||
if (trade.close_timestamp && trade[props.profitColumn]) {
|
if (trade.close_timestamp && trade[props.profitColumn]) {
|
||||||
profit += trade[props.profitColumn];
|
profit += trade[props.profitColumn];
|
||||||
if (!resD[trade.close_timestamp]) {
|
if (!resD[trade.close_timestamp]) {
|
||||||
// New timestamp
|
// New timestamp
|
||||||
resD[trade.close_timestamp] = { profit, [trade.botId]: profit };
|
resD[trade.close_timestamp] = { profit, [trade.botId]: profit };
|
||||||
|
} else {
|
||||||
|
// Add to existing profit
|
||||||
|
resD[trade.close_timestamp].profit += trade[props.profitColumn];
|
||||||
|
if (resD[trade.close_timestamp][trade.botId]) {
|
||||||
|
resD[trade.close_timestamp][trade.botId] += trade[props.profitColumn];
|
||||||
} else {
|
} else {
|
||||||
// Add to existing profit
|
resD[trade.close_timestamp][trade.botId] = profit;
|
||||||
resD[trade.close_timestamp].profit += trade[props.profitColumn];
|
|
||||||
if (resD[trade.close_timestamp][trade.botId]) {
|
|
||||||
resD[trade.close_timestamp][trade.botId] += trade[props.profitColumn];
|
|
||||||
} else {
|
|
||||||
resD[trade.close_timestamp][trade.botId] = profit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// console.log(trade.close_date, profit);
|
|
||||||
res.push({ date: trade.close_timestamp, profit, [trade.botId]: profit });
|
|
||||||
if (!botList.value.includes(trade.botId)) {
|
|
||||||
botList.value.push(trade.botId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// console.log(trade.close_date, profit);
|
||||||
|
res.push({ date: trade.close_timestamp, profit, [trade.botId]: profit });
|
||||||
|
if (!botList.value.includes(trade.botId)) {
|
||||||
|
botList.value.push(trade.botId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// console.log(resD);
|
}
|
||||||
|
// console.log(resD);
|
||||||
|
|
||||||
cumulativeData.value = Object.entries(resD).map(([k, v]) => {
|
cumulativeData.value = Object.entries(resD).map(([k, v]) => {
|
||||||
const obj = { date: parseInt(k, 10), profit: v.profit };
|
const obj = { date: parseInt(k, 10), profit: v.profit };
|
||||||
// TODO: The below could allow "lines" per bot"
|
// TODO: The below could allow "lines" per bot"
|
||||||
// this.botList.forEach((botId) => {
|
// this.botList.forEach((botId) => {
|
||||||
// obj[botId] = v[botId];
|
// obj[botId] = v[botId];
|
||||||
// });
|
// });
|
||||||
return obj;
|
return obj;
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
);
|
watch([props.trades], calcCumulativeData);
|
||||||
|
// Initial call
|
||||||
|
calcCumulativeData();
|
||||||
|
|
||||||
const chartOptions = computed((): EChartsOption => {
|
const chartOptions = computed((): EChartsOption => {
|
||||||
const chartOptionsLoc: EChartsOption = {
|
const chartOptionsLoc: EChartsOption = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user