Fix daily chart not loading properly

This commit is contained in:
Matthias 2022-04-22 20:02:50 +02:00
parent 8a0b852912
commit 3ab4aed5f4
4 changed files with 100 additions and 92 deletions

View File

@ -8,7 +8,7 @@
</template>
<script lang="ts">
import { ref, defineComponent, computed, ComputedRef } from '@vue/composition-api';
import { defineComponent, computed, ComputedRef } from '@vue/composition-api';
import ECharts from 'vue-echarts';
// import { EChartsOption } from 'echarts';
@ -26,6 +26,7 @@ import {
import { DailyReturnValue } from '@/types';
import { useSettingsStore } from '@/stores/settings';
import { EChartsOption } from 'echarts';
use([
BarChart,
@ -60,21 +61,20 @@ export default defineComponent({
setup(props) {
const settingsStore = useSettingsStore();
const absoluteMin: ComputedRef<number> = computed(() =>
const absoluteMin = computed(() =>
props.dailyStats.data.reduce(
(min, p) => (p.abs_profit < min ? p.abs_profit : min),
props.dailyStats.data[0]?.abs_profit,
),
);
const absoluteMax: ComputedRef<number> = computed(() =>
const absoluteMax = computed(() =>
props.dailyStats.data.reduce(
(max, p) => (p.abs_profit > max ? p.abs_profit : max),
props.dailyStats.data[0]?.abs_profit,
),
);
// : Ref<EChartsOption>
const dailyChartOptions = ref({
const dailyChartOptions: ComputedRef<EChartsOption> = computed(() => {
return {
title: {
text: 'Daily profit',
show: props.showTitle,
@ -100,7 +100,6 @@ export default defineComponent({
xAxis: [
{
type: 'category',
inverse: true,
},
],
visualMap: [
@ -156,6 +155,7 @@ export default defineComponent({
yAxisIndex: 1,
},
],
};
});
return {

View File

@ -492,12 +492,15 @@ export function createBotSubStore(botId: string, botName: string) {
return Promise.reject(error);
}
},
getDaily(payload: DailyPayload = {}) {
async getDaily(payload: DailyPayload = {}) {
const { timescale = 20 } = payload;
return api
.get('/daily', { params: { timescale } })
.then((result) => (this.dailyStats = result.data))
.catch(console.error);
try {
const { data } = await api.get<DailyReturnValue>('/daily', { params: { timescale } });
this.dailyStats = data;
return Promise.resolve(data);
} catch (error) {
return Promise.reject(error);
}
},
getState() {
return api

View File

@ -103,8 +103,8 @@ export const useBotStore = defineStore('wrapper', {
return result;
},
allDailyStatsAllBots: (state): DailyReturnValue => {
// Return aggregated daily stats for all bots - sorted ascending.
const resp: Record<string, DailyRecord> = {};
Object.entries(state.botStores).forEach(([, botStore]) => {
botStore.dailyStats?.data?.forEach((d) => {
if (!resp[d.date]) {
@ -125,7 +125,7 @@ export const useBotStore = defineStore('wrapper', {
stake_currency: 'USDT',
// eslint-disable-next-line @typescript-eslint/camelcase
fiat_display_currency: 'USD',
data: Object.values(resp),
data: Object.values(resp).sort((a, b) => (a.date > b.date ? 1 : -1)),
};
return dailyReturn;
},
@ -286,10 +286,15 @@ export const useBotStore = defineStore('wrapper', {
}
});
},
allGetDaily(payload: DailyPayload) {
async allGetDaily(payload: DailyPayload) {
const updates: Promise<any>[] = [];
this.allBotStores.forEach((e) => {
e.getDaily(payload);
if (e.isBotOnline) {
updates.push(e.getDaily(payload));
}
});
await Promise.all(updates);
},
async forceSellMulti(forcesellPayload: MultiForcesellPayload) {
return this.botStores[forcesellPayload.botId].forceexit(forcesellPayload);

View File

@ -177,8 +177,8 @@ export default defineComponent({
};
});
onMounted(() => {
botStore.allGetDaily({ timescale: 30 });
onMounted(async () => {
await botStore.allGetDaily({ timescale: 30 });
botStore.activeBot.getTrades();
botStore.activeBot.getOpenTrades();
botStore.activeBot.getProfit();