diff --git a/src/store/modules/ftbot/index.ts b/src/store/modules/ftbot/index.ts index 7dbcd8ec..bc3ea02e 100644 --- a/src/store/modules/ftbot/index.ts +++ b/src/store/modules/ftbot/index.ts @@ -23,6 +23,7 @@ import { Lock, RunModes, TradeResponse, + StrategyBacktestResult, } from '@/types'; import { @@ -48,6 +49,7 @@ export enum BotStoreGetters { isTrading = 'isTrading', isWebserverMode = 'isWebserverMode', refreshRequired = 'refreshRequired', + selectedBacktestResult = 'selectedBacktestResult', } export default { @@ -110,6 +112,9 @@ export default { [BotStoreGetters.refreshRequired](state: FtbotStateType): boolean { return state.refreshRequired; }, + [BotStoreGetters.selectedBacktestResult](state): StrategyBacktestResult { + return state.backtestHistory[state.selectedBacktestResultKey]; + }, }, mutations: { updateRefreshRequired(state: FtbotStateType, refreshRequired: boolean) { @@ -190,7 +195,7 @@ export default { storeCustomPlotConfig(plotConfig); state.availablePlotConfigNames = getAllPlotConfigNames(); }, - updateBacktestRunning(state, running: boolean) { + updateBacktestRunning(state: FtbotStateType, running: boolean) { state.backtestRunning = running; }, updateBacktestResult(state, backtestResult: BacktestResult) { @@ -199,8 +204,12 @@ export default { Object.entries(backtestResult.strategy).forEach(([key, strat]) => { const xxx = `${key}_${strat.total_trades}_${strat.profit_total.toFixed(3)}`; state.backtestHistory[xxx] = strat; + state.selectedBacktestResultKey = xxx; }); }, + setBacktestResultKey(state: FtbotStateType, key: string) { + state.selectedBacktestResultKey = key; + }, }, actions: { ping({ commit, rootState }) { diff --git a/src/store/modules/ftbot/state.ts b/src/store/modules/ftbot/state.ts index 8e88a4f1..87a74e5c 100644 --- a/src/store/modules/ftbot/state.ts +++ b/src/store/modules/ftbot/state.ts @@ -44,6 +44,7 @@ export interface FtbotStateType { currentLocks?: LockResponse; backtestRunning: boolean; backtestResult?: BacktestResult; + selectedBacktestResultKey: string; backtestHistory: Record; } const state: FtbotStateType = { @@ -76,6 +77,7 @@ const state: FtbotStateType = { // backtesting backtestRunning: false, backtestResult: undefined, + selectedBacktestResultKey: '', backtestHistory: {}, }; diff --git a/src/types/backtest.ts b/src/types/backtest.ts index 555e96ff..01b1675f 100644 --- a/src/types/backtest.ts +++ b/src/types/backtest.ts @@ -96,7 +96,7 @@ export interface StrategyBacktestResult { /** Start time of the backtest run */ backtest_run_start_ts: number; - /** ENd time of the backtest run */ + /** End time of the backtest run */ backtest_run_end_ts: number; } diff --git a/src/views/Backtesting.vue b/src/views/Backtesting.vue index 387aac70..2124d3a7 100644 --- a/src/views/Backtesting.vue +++ b/src/views/Backtesting.vue @@ -145,14 +145,16 @@
- - {{ key }} {{ strat.total_trades }} {{ formatPercent(strat.profit_total) }} - + + + {{ key }} {{ strat.total_trades }} {{ formatPercent(strat.profit_total) }} + +
@@ -172,23 +174,26 @@ v-if="hasBacktestResult && btFormMode == 'visualize'" class="container-fluid row text-center w-100 mt-2" > - - - +

Graph will always show the latest values for the selected strategy.

+
+ + + +
@@ -215,6 +220,7 @@ import { import { getCustomPlotConfig, getPlotConfigName } from '@/shared/storage'; import { formatPercent } from '@/shared/formatters'; +import { BotStoreGetters } from '@/store/modules/ftbot'; const ftbot = namespace('ftbot'); @Component({ @@ -274,6 +280,8 @@ export default class Backtesting extends Vue { @ftbot.State backtestHistory!: StrategyBacktestResult[]; + @ftbot.Getter [BotStoreGetters.selectedBacktestResult]!: StrategyBacktestResult; + @ftbot.State history; // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -297,9 +305,9 @@ export default class Backtesting extends Vue { return Object.keys(this.backtestResult).length !== 0; } - get selectedBacktestResult(): StrategyBacktestResult { - return this.backtestResult.strategy[this.strategy] || {}; - } + // get selectedBacktestResult(): StrategyBacktestResult { + // return this.backtestResult.strategy[this.strategy] || {}; + // } get timeframe(): string { try {