pinia: botgetters

This commit is contained in:
Matthias 2022-04-17 10:28:48 +02:00
parent 24d7fb7104
commit 8aef54aa17

View File

@ -16,6 +16,8 @@ import {
SysInfoResponse, SysInfoResponse,
LoadingStatus, LoadingStatus,
BacktestHistoryEntry, BacktestHistoryEntry,
RunModes,
EMPTY_PLOTCONFIG,
} from '@/types'; } from '@/types';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
@ -69,6 +71,53 @@ export const useBotStore = defineStore('ftbot', {
sysinfo: {} as SysInfoResponse, 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: {}, actions: {},
}); });