Store backtest step + progress

This commit is contained in:
Matthias 2021-03-11 19:20:12 +01:00
parent 823e144bcb
commit 019d368b41
4 changed files with 43 additions and 6 deletions

View File

@ -24,6 +24,7 @@ import {
RunModes, RunModes,
TradeResponse, TradeResponse,
StrategyBacktestResult, StrategyBacktestResult,
BacktestStatus,
} from '@/types'; } from '@/types';
import { import {
@ -195,8 +196,11 @@ export default {
storeCustomPlotConfig(plotConfig); storeCustomPlotConfig(plotConfig);
state.availablePlotConfigNames = getAllPlotConfigNames(); state.availablePlotConfigNames = getAllPlotConfigNames();
}, },
updateBacktestRunning(state: FtbotStateType, running: boolean) { updateBacktestRunning(state: FtbotStateType, backtestStatus: BacktestStatus) {
state.backtestRunning = running; state.backtestRunning = backtestStatus.running;
state.backtestProgress = backtestStatus.progress;
state.backtestStep = backtestStatus.step;
state.backtestTradeCount = backtestStatus.trade_count || 0;
}, },
updateBacktestResult(state, backtestResult: BacktestResult) { updateBacktestResult(state, backtestResult: BacktestResult) {
state.backtestResult = backtestResult; state.backtestResult = backtestResult;
@ -602,14 +606,14 @@ export default {
async startBacktest({ commit }, payload) { async startBacktest({ commit }, payload) {
try { try {
const result = await api.post('/backtest', payload); const result = await api.post('/backtest', payload);
commit('updateBacktestRunning', result.data.running); commit('updateBacktestRunning', result.data);
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
}, },
async pollBacktest({ commit }) { async pollBacktest({ commit }) {
const result = await api.get('/backtest'); const result = await api.get('/backtest');
commit('updateBacktestRunning', result.data.running); commit('updateBacktestRunning', result.data);
if (result.data.running === false && result.data.backtest_result) { if (result.data.running === false && result.data.backtest_result) {
commit('updateBacktestResult', result.data.backtest_result); commit('updateBacktestResult', result.data.backtest_result);
} }

View File

@ -12,6 +12,7 @@ import {
ProfitInterface, ProfitInterface,
BacktestResult, BacktestResult,
StrategyBacktestResult, StrategyBacktestResult,
BacktestSteps,
} from '@/types'; } from '@/types';
export interface FtbotStateType { export interface FtbotStateType {
@ -44,10 +45,14 @@ export interface FtbotStateType {
pairlist: string[]; pairlist: string[];
currentLocks?: LockResponse; currentLocks?: LockResponse;
backtestRunning: boolean; backtestRunning: boolean;
backtestProgress: number;
backtestStep: BacktestSteps;
backtestTradeCount: number;
backtestResult?: BacktestResult; backtestResult?: BacktestResult;
selectedBacktestResultKey: string; selectedBacktestResultKey: string;
backtestHistory: Record<string, StrategyBacktestResult>; backtestHistory: Record<string, StrategyBacktestResult>;
} }
const state: FtbotStateType = { const state: FtbotStateType = {
version: '', version: '',
lastLogs: [], lastLogs: [],
@ -77,6 +82,9 @@ const state: FtbotStateType = {
currentLocks: undefined, currentLocks: undefined,
// backtesting // backtesting
backtestRunning: false, backtestRunning: false,
backtestProgress: 0.0,
backtestStep: BacktestSteps.none,
backtestTradeCount: 0,
backtestResult: undefined, backtestResult: undefined,
selectedBacktestResultKey: '', selectedBacktestResultKey: '',
backtestHistory: {}, backtestHistory: {},

View File

@ -124,3 +124,22 @@ export interface BacktestResult {
strategy: Record<string, StrategyBacktestResult>; strategy: Record<string, StrategyBacktestResult>;
strategy_comparison: Array<Record<string, string | number>>; strategy_comparison: Array<Record<string, string | number>>;
} }
export enum BacktestSteps {
startup,
dataload,
analyze,
convert,
backtest,
none = '',
}
export interface BacktestStatus {
status: string;
running: boolean;
status_msg: string;
step: BacktestSteps;
progress: number;
trade_count?: number;
backtest_result?: BacktestResult;
}

View File

@ -2,7 +2,9 @@
<div class="container-fluid"> <div class="container-fluid">
<div class="mb-2"> <div class="mb-2">
<h2 class="mt-3 d-inline">Backtesting</h2> <h2 class="mt-3 d-inline">Backtesting</h2>
<small v-show="backtestRunning" class="bt-running-label">Backtest running</small> <small v-show="backtestRunning" class="bt-running-label"
>Backtest running: {{ backtestStep }} {{ formatPercent(backtestProgress) }}</small
>
</div> </div>
<div class="container"> <div class="container">
<div class="row mx-5 d-flex flex-wrap justify-content-center mb-4"> <div class="row mx-5 d-flex flex-wrap justify-content-center mb-4">
@ -296,7 +298,7 @@ export default class Backtesting extends Vue {
'1y', '1y',
]; ];
showLeftBar = true; showLeftBar = false;
selectedTimeframe = ''; selectedTimeframe = '';
@ -320,6 +322,10 @@ export default class Backtesting extends Vue {
@ftbot.State backtestRunning!: boolean; @ftbot.State backtestRunning!: boolean;
@ftbot.State backtestStep!: string;
@ftbot.State backtestProgress!: number;
@ftbot.State backtestHistory!: StrategyBacktestResult[]; @ftbot.State backtestHistory!: StrategyBacktestResult[];
@ftbot.State selectedBacktestResultKey!: string; @ftbot.State selectedBacktestResultKey!: string;