Fix cum-profit chart not updating

This commit is contained in:
Matthias 2022-08-13 15:35:31 +02:00
parent 4cda6b9581
commit 44c6299c10

View File

@ -18,7 +18,7 @@ import {
} from 'echarts/components'; } from 'echarts/components';
import { ClosedTrade, CumProfitData, CumProfitDataPerDate } from '@/types'; import { ClosedTrade, CumProfitData, CumProfitDataPerDate } from '@/types';
import { defineComponent, ref, computed, watch } from 'vue'; import { defineComponent, computed, ComputedRef } from 'vue';
import { useSettingsStore } from '@/stores/settings'; import { useSettingsStore } from '@/stores/settings';
use([ use([
@ -49,12 +49,10 @@ export default defineComponent({
}, },
setup(props) { setup(props) {
const settingsStore = useSettingsStore(); const settingsStore = useSettingsStore();
const botList = ref<string[]>([]); // const botList = ref<string[]>([]);
const cumulativeData = ref<{ date: number; profit: any }[]>([]); // const cumulativeData = ref<{ date: number; profit: any }[]>([]);
const calcCumulativeData = () => { const cumulativeData: ComputedRef<{ date: number; profit: number }[]> = computed(() => {
console.log('trades');
botList.value = [];
const res: CumProfitData[] = []; const res: CumProfitData[] = [];
const resD: CumProfitDataPerDate = {}; const resD: CumProfitDataPerDate = {};
const closedTrades = props.trades const closedTrades = props.trades
@ -79,16 +77,12 @@ export default defineComponent({
resD[trade.close_timestamp][trade.botId] = profit; resD[trade.close_timestamp][trade.botId] = profit;
} }
} }
// console.log(trade.close_date, profit);
res.push({ date: trade.close_timestamp, profit, [trade.botId]: 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]) => { return 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) => {
@ -96,10 +90,7 @@ export default defineComponent({
// }); // });
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 = {