frequi_origin/src/views/Backtesting.vue

83 lines
2.2 KiB
Vue
Raw Normal View History

2020-07-26 11:44:34 +00:00
<template>
<div class="container-fluid">
<div class="row mb-2">
<TimeRangeSelect v-model="timerange"></TimeRangeSelect>
</div>
2020-07-26 17:35:56 +00:00
<div class="row">
<b-button variant="primary" :disabled="backtestRunning" @click="clickBacktest">
Start backtest
</b-button>
<b-button variant="primary" :disabled="backtestRunning" @click="pollBacktest">
Load backtest result
</b-button>
</div>
<div v-if="hasBacktestResult" class="text-center w-100 mt-5">
<BacktestResultView
:strategy="strategy"
:backtest-result="backtestResult.strategy ? backtestResult.strategy[strategy] : {}"
/>
</div>
2020-07-26 11:44:34 +00:00
</div>
</template>
<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator';
import { namespace } from 'vuex-class';
import TimeRangeSelect from '@/components/ftbot/TimeRangeSelect.vue';
2020-07-26 17:35:56 +00:00
import BacktestResultView from '@/components/ftbot/BacktestResultView.vue';
import { BacktestPayload, BacktestResult } from '@/types';
2020-07-26 11:44:34 +00:00
const ftbot = namespace('ftbot');
@Component({
2020-07-26 17:35:56 +00:00
components: { BacktestResultView, TimeRangeSelect },
2020-07-26 11:44:34 +00:00
})
2020-07-26 17:35:56 +00:00
export default class Backtesting extends Vue {
2020-07-26 11:44:34 +00:00
pair = 'XRP/USDT';
2020-07-26 17:35:56 +00:00
pollInterval: number | null = null;
2020-07-26 11:44:34 +00:00
timeframe = '5m';
2020-07-26 17:35:56 +00:00
strategy = 'BinHV45';
2020-07-26 11:44:34 +00:00
timeframems = 300000;
@ftbot.State backtestRunning!: boolean;
2020-07-26 17:35:56 +00:00
@ftbot.State backtestResult!: BacktestResult;
2020-07-26 11:44:34 +00:00
timerange = '';
2020-07-26 17:35:56 +00:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@ftbot.Action startBacktest!: (payload: BacktestPayload) => void;
2020-07-26 11:44:34 +00:00
@ftbot.Action pollBacktest!: () => void;
2020-07-26 17:35:56 +00:00
get hasBacktestResult() {
return Object.keys(this.backtestResult).length !== 0;
}
2020-07-26 11:44:34 +00:00
clickBacktest() {
console.log('Backtesting');
const btPayload: BacktestPayload = {
2020-07-26 17:35:56 +00:00
strategy: this.strategy,
2020-07-26 11:44:34 +00:00
timerange: this.timerange,
};
this.startBacktest(btPayload);
}
@Watch('backtestRunning')
backtestRunningChanged() {
if (this.backtestRunning === true) {
2020-07-26 17:35:56 +00:00
this.pollInterval = window.setInterval(this.pollBacktest, 1000);
2020-07-26 11:44:34 +00:00
} else if (this.pollInterval) {
clearInterval(this.pollInterval);
this.pollInterval = null;
}
}
}
</script>
<style scoped></style>