From 8aef54aa173d6b09accb193cc57420e22ab68e4d Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 17 Apr 2022 10:28:48 +0200 Subject: [PATCH] pinia: botgetters --- src/stores/ftbot.ts | 51 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/stores/ftbot.ts b/src/stores/ftbot.ts index 5d8fac94..3d79ec6c 100644 --- a/src/stores/ftbot.ts +++ b/src/stores/ftbot.ts @@ -16,6 +16,8 @@ import { SysInfoResponse, LoadingStatus, BacktestHistoryEntry, + RunModes, + EMPTY_PLOTCONFIG, } from '@/types'; import { defineStore } from 'pinia'; @@ -69,6 +71,53 @@ export const useBotStore = defineStore('ftbot', { sysinfo: {} as SysInfoResponse, }; }, - getters: {}, + getters: { + version: (state) => state.botState?.version || state.version, + botApiVersion: (state) => state.botState?.api_version || 1.0, + stakeCurrency: (state) => state.botState?.stake_currency || '', + stakeCurrencyDecimals: (state) => state.botState?.stake_currency_decimals || 3, + canRunBacktest: (state) => state.botState?.runmode === RunModes.WEBSERVER, + isWebserverMode: (state) => state.botState?.runmode === RunModes.WEBSERVER, + selectedBacktestResult: (state) => state.backtestHistory[state.selectedBacktestResultKey], + shortAllowed: (state) => state.botState?.short_allowed || false, + isTrading: (state) => + state.botState?.runmode === RunModes.LIVE || state.botState?.runmode === RunModes.DRY_RUN, + timeframe: (state) => state.botState?.timeframe || '', + closedTrades: (state) => { + return state.trades + .filter((item) => !item.is_open) + .sort((a, b) => + // Sort by close timestamp, then by tradeid + b.close_timestamp && a.close_timestamp + ? b.close_timestamp - a.close_timestamp + : b.trade_id - a.trade_id, + ); + }, + tradeDetail: (state) => { + let dTrade = state.openTrades.find((item) => item.trade_id === state.detailTradeId); + if (!dTrade) { + dTrade = state.trades.find((item) => item.trade_id === state.detailTradeId); + } + return dTrade; + }, + plotConfig: (state) => state.customPlotConfig[state.plotConfigName] || { ...EMPTY_PLOTCONFIG }, + refreshNow: (state) => { + // TODO: This might need to be done differently + + // const bgRefresh = rootGetters['uiSettings/backgroundSync']; + // const selectedBot = rootGetters[`${StoreModules.ftbot}/selectedBot`]; + // if ( + // (selectedBot === botId || bgRefresh) && + // getters.autoRefresh && + // getters.isBotOnline && + // getters.botStatusAvailable && + // !getters.isWebserverMode + // ) { + // return true; + // } + return false; + }, + botName: (state) => state.botState?.bot_name || 'freqtrade', + }, actions: {}, });