Conditionally show Trade OR backtest points

This commit is contained in:
Matthias 2021-04-24 20:01:37 +02:00
parent 916fd67f9c
commit 8a3451e4cf
3 changed files with 19 additions and 8 deletions

View File

@ -10,10 +10,10 @@
<b-collapse id="nav-collapse" is-nav> <b-collapse id="nav-collapse" is-nav>
<b-navbar-nav> <b-navbar-nav>
<b-nav-item to="/trade">Trade</b-nav-item> <b-nav-item v-if="!canRunBacktest" to="/trade">Trade</b-nav-item>
<!-- <b-nav-item to="/graph">Graph</b-nav-item> --> <!-- <b-nav-item to="/graph">Graph</b-nav-item> -->
<b-nav-item to="/dashboard">Dashboard</b-nav-item> <b-nav-item v-if="!canRunBacktest" to="/dashboard">Dashboard</b-nav-item>
<b-nav-item to="/backtest">Backtest</b-nav-item> <b-nav-item v-if="canRunBacktest" to="/backtest">Backtest</b-nav-item>
<BootswatchThemeSelect /> <BootswatchThemeSelect />
</b-navbar-nav> </b-navbar-nav>
<!-- Right aligned nav items --> <!-- Right aligned nav items -->
@ -76,10 +76,14 @@ export default class NavBar extends Vue {
@ftbot.Action ping; @ftbot.Action ping;
@ftbot.Action getState;
@ftbot.Getter [BotStoreGetters.botName]: string; @ftbot.Getter [BotStoreGetters.botName]: string;
@ftbot.Getter [BotStoreGetters.openTradeCount]: number; @ftbot.Getter [BotStoreGetters.openTradeCount]: number;
@ftbot.Getter [BotStoreGetters.canRunBacktest]!: boolean;
@layoutNs.Getter [LayoutGetters.getLayoutLocked]: boolean; @layoutNs.Getter [LayoutGetters.getLayoutLocked]: boolean;
@layoutNs.Action [LayoutActions.resetDashboardLayout]; @layoutNs.Action [LayoutActions.resetDashboardLayout];
@ -95,6 +99,11 @@ export default class NavBar extends Vue {
mounted() { mounted() {
this.ping(); this.ping();
this.pingInterval = window.setInterval(this.ping, 60000); this.pingInterval = window.setInterval(this.ping, 60000);
if (this.loggedIn) {
// Query botstate - this will enable / disable certain modes
this.getState();
}
} }
beforeDestroy() { beforeDestroy() {

View File

@ -51,6 +51,7 @@ export enum BotStoreGetters {
isWebserverMode = 'isWebserverMode', isWebserverMode = 'isWebserverMode',
refreshRequired = 'refreshRequired', refreshRequired = 'refreshRequired',
selectedBacktestResult = 'selectedBacktestResult', selectedBacktestResult = 'selectedBacktestResult',
canRunBacktest = 'canRunBacktest',
} }
export default { export default {
@ -116,6 +117,10 @@ export default {
[BotStoreGetters.selectedBacktestResult](state: FtbotStateType): StrategyBacktestResult { [BotStoreGetters.selectedBacktestResult](state: FtbotStateType): StrategyBacktestResult {
return state.backtestHistory[state.selectedBacktestResultKey]; return state.backtestHistory[state.selectedBacktestResultKey];
}, },
[BotStoreGetters.canRunBacktest](state: FtbotStateType): boolean {
/** Determines if bot runs in webserver mode */
return state.botState?.runmode === RunModes.WEBSERVER;
},
}, },
mutations: { mutations: {
updateRefreshRequired(state: FtbotStateType, refreshRequired: boolean) { updateRefreshRequired(state: FtbotStateType, refreshRequired: boolean) {

View File

@ -274,7 +274,6 @@ import {
BotState, BotState,
PairHistoryPayload, PairHistoryPayload,
PlotConfig, PlotConfig,
RunModes,
StrategyBacktestResult, StrategyBacktestResult,
} from '@/types'; } from '@/types';
@ -357,6 +356,8 @@ export default class Backtesting extends Vue {
@ftbot.Getter [BotStoreGetters.selectedBacktestResult]!: StrategyBacktestResult; @ftbot.Getter [BotStoreGetters.selectedBacktestResult]!: StrategyBacktestResult;
@ftbot.Getter [BotStoreGetters.canRunBacktest]!: boolean;
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ftbot.Action getPairHistory!: (payload: PairHistoryPayload) => void; @ftbot.Action getPairHistory!: (payload: PairHistoryPayload) => void;
@ -376,10 +377,6 @@ export default class Backtesting extends Vue {
formatPercent = formatPercent; formatPercent = formatPercent;
get canRunBacktest() {
return this.botState?.runmode === RunModes.WEBSERVER;
}
get hasBacktestResult() { get hasBacktestResult() {
return this.backtestHistory ? Object.keys(this.backtestHistory).length !== 0 : false; return this.backtestHistory ? Object.keys(this.backtestHistory).length !== 0 : false;
} }