From 52ab11b37694c1fdfda1de2bc312e96813442d50 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 2 Sep 2021 20:04:48 +0200 Subject: [PATCH] Add multitrade getter --- src/store/modules/botStoreWrapper.ts | 25 +++++++++++++++++-------- src/types/trades.ts | 4 ++++ src/views/Dashboard.vue | 4 ++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/store/modules/botStoreWrapper.ts b/src/store/modules/botStoreWrapper.ts index 4a835d59..99b9d5b8 100644 --- a/src/store/modules/botStoreWrapper.ts +++ b/src/store/modules/botStoreWrapper.ts @@ -1,4 +1,4 @@ -import { BotDescriptor, BotDescriptors } from '@/types'; +import { BotDescriptor, BotDescriptors, MultiClosedTrades } from '@/types'; import { AxiosInstance } from 'axios'; import { BotStoreActions, BotStoreGetters, createBotSubStore } from './ftbot'; @@ -13,13 +13,14 @@ interface FTMultiBotState { export enum MultiBotStoreGetters { hasBots = 'hasBots', botCount = 'botCount', + nextBotId = 'nextBotId', selectedBot = 'selectedBot', selectedBotObj = 'selectedBotObj', allAvailableBots = 'allAvailableBots', allAvailableBotsList = 'allAvailableBotsList', allIsBotOnline = 'allIsBotOnline', - nextBotId = 'nextBotId', allAutoRefresh = 'allAutoRefresh', + allClosedTrades = 'allClosedTrades', } export default function createBotStore(store) { @@ -39,6 +40,14 @@ export default function createBotStore(store) { [MultiBotStoreGetters.botCount](state: FTMultiBotState): number { return Object.keys(state.availableBots).length; }, + [MultiBotStoreGetters.nextBotId](state: FTMultiBotState): string { + let botCount = Object.keys(state.availableBots).length; + + while (`ftbot.${botCount}` in state.availableBots) { + botCount += 1; + } + return `ftbot.${botCount}`; + }, [MultiBotStoreGetters.selectedBot](state: FTMultiBotState): string { return state.selectedBot; }, @@ -65,13 +74,13 @@ export default function createBotStore(store) { }); return result; }, - [MultiBotStoreGetters.nextBotId](state: FTMultiBotState): string { - let botCount = Object.keys(state.availableBots).length; + [MultiBotStoreGetters.allClosedTrades](state: FTMultiBotState, getters): MultiClosedTrades { + const result = {}; - while (`ftbot.${botCount}` in state.availableBots) { - botCount += 1; - } - return `ftbot.${botCount}`; + getters.allAvailableBotsList.forEach((e) => { + result[e] = getters[`${e}/closedTrades`]; + }); + return result; }, }; // Autocreate getters from botStores diff --git a/src/types/trades.ts b/src/types/trades.ts index bfa5f7c9..f5580913 100644 --- a/src/types/trades.ts +++ b/src/types/trades.ts @@ -79,3 +79,7 @@ export interface TradeResponse { /** Total trade count */ total_trades: number; } + +export interface MultiClosedTrades { + [key: string]: ClosedTrade; +} diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue index 2b4a5ca9..a8f88f7c 100644 --- a/src/views/Dashboard.vue +++ b/src/views/Dashboard.vue @@ -147,8 +147,10 @@ import { ProfitInterface, DailyPayload, BotState, + MultiClosedTrades, } from '@/types'; import { BotStoreGetters } from '@/store/modules/ftbot'; +import { MultiBotStoreGetters } from '@/store/modules/botStoreWrapper'; const ftbot = namespace('ftbot'); const layoutNs = namespace('layout'); @@ -167,6 +169,8 @@ const layoutNs = namespace('layout'); export default class Dashboard extends Vue { @ftbot.Getter closedTrades!: Trade[]; + @ftbot.Getter [MultiBotStoreGetters.allClosedTrades]!: MultiClosedTrades; + @ftbot.Getter [BotStoreGetters.dailyStats]!: DailyReturnValue; @ftbot.Getter [BotStoreGetters.openTrades]!: Array;