frequi_origin/src/views/Graphs.vue

175 lines
4.9 KiB
Vue
Raw Normal View History

2020-06-17 18:38:25 +00:00
<template>
2020-06-20 06:52:43 +00:00
<div class="container-fluid">
<div class="row mb-2">
<div class="col-mb-2">
<b-form-select :options="whitelist" v-model="pair" @change="refresh"> </b-form-select>
</div>
2020-06-23 18:37:14 +00:00
<div class="col-mb-2">
<b-checkbox v-model="strategyPlotConfig">Use strategy plot_config</b-checkbox>
</div>
</div>
<div v-if="!strategyPlotConfig" class="container-fluid">
<div class="row">
<label class="h3">Plot config builder</label>
</div>
<div class="row">
<div class="col-mb-3">
<b-form-group label-cols="auto" label="Choose column" label-for="columnSelector">
<b-form-select id="columnSelector" :options="dataset.columns" v-model="selColumn">
</b-form-select>
</b-form-group>
</div>
<div class="col-mb-3 ml-2">
2020-06-23 19:18:57 +00:00
<b-form-group label-cols="auto" label="Plot Section" label-for="FieldSel">
<b-form-radio v-model="plotOption" name="plot_section" value="main_plot">
Main Plot
</b-form-radio>
<b-form-radio v-model="plotOption" name="plot_section" value="subplots">
Subplots
</b-form-radio>
</b-form-group>
</div>
<div class="col-mb-3 ml-2" v-if="plotOption == 'subplots'">
<b-form-group label-cols="auto" label="Target field" label-for="FieldSel">
<b-form-select id="FieldSel" :options="subplots" v-model="selField"> </b-form-select>
2020-06-23 18:37:14 +00:00
</b-form-group>
</div>
2020-06-29 05:21:27 +00:00
<div class="col-mb-3 ml-2" v-if="plotOption == 'subplots'">
<b-form-group label-cols="auto" label="New subplot" label-for="newSubplot">
<b-form-input class="addPlot" id="newSubplot" v-model="newSubplotName"></b-form-input>
<b-button id="FieldSel" @click="addSubplot">+</b-button>
</b-form-group>
</div>
2020-06-23 19:18:57 +00:00
<div class="col-mb-3 ml-2">
<b-form-group label-cols="auto" label="Color" label-for="colsel">
<b-form-input id="colsel" v-model="selColor"></b-form-input>
</b-form-group>
</div>
2020-06-23 18:37:14 +00:00
<div class="col-mb-3 ml-2">
<b-button variant="primary" @click="addBar">Add</b-button>
</div>
2020-06-29 05:21:27 +00:00
<div class="col-mb-3 ml-2">
<b-button variant="primary">Show</b-button>
</div>
2020-06-23 18:37:14 +00:00
</div>
2020-06-20 06:52:43 +00:00
</div>
<div class="row">
2020-06-23 18:37:14 +00:00
<CandleChart
:pair="pair"
:timeframe="timeframe"
:dataset="dataset"
:plotConfig="selectedPlotConfig"
>
2020-06-23 05:09:58 +00:00
</CandleChart>
2020-06-20 06:52:43 +00:00
</div>
2020-06-17 18:38:25 +00:00
</div>
</template>
2020-06-22 06:05:03 +00:00
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { namespace } from 'vuex-class';
2020-06-17 18:38:25 +00:00
import CandleChart from '@/components/ftbot/CandleChart.vue';
2020-06-23 19:18:57 +00:00
import randomColor from '../shared/randomColor';
2020-06-29 05:21:27 +00:00
import { PlotConfig } from '../store/types';
2020-06-17 18:38:25 +00:00
2020-06-22 06:05:03 +00:00
const ftbot = namespace('ftbot');
@Component({
components: { CandleChart },
})
export default class Graphs extends Vue {
pair = 'XRP/USDT';
timeframe = '5m';
2020-06-23 18:37:14 +00:00
strategyPlotConfig = false;
selColumn = '';
selField = '';
2020-06-29 05:21:27 +00:00
newSubplotName = '';
2020-06-23 19:18:57 +00:00
plotOption = 'main_plot';
2020-06-23 18:37:14 +00:00
2020-06-23 19:18:57 +00:00
selColor = randomColor();
// Custom plot config - manually changed by user.
2020-06-29 05:21:27 +00:00
// eslint-disable-next-line @typescript-eslint/camelcase
customPlotConfig: PlotConfig = { main_plot: {}, subplots: {} };
2020-06-23 18:37:14 +00:00
2020-06-22 06:05:03 +00:00
@ftbot.State history;
@ftbot.State whitelist;
2020-06-23 05:09:58 +00:00
@ftbot.State plotConfig;
2020-06-22 06:05:03 +00:00
@ftbot.Action
public getPairHistory;
@ftbot.Action
public getWhitelist;
2020-06-23 05:09:58 +00:00
@ftbot.Action
public getPlotConfig;
2020-06-17 18:38:25 +00:00
mounted() {
2020-06-20 06:52:43 +00:00
this.getWhitelist();
this.refresh();
2020-06-23 19:18:57 +00:00
// eslint-disable-next-line @typescript-eslint/camelcase
this.customPlotConfig = this.plotConfig || { main_plot: {}, subplots: {} };
2020-06-22 06:05:03 +00:00
}
2020-06-23 18:37:14 +00:00
get selectedPlotConfig() {
return this.strategyPlotConfig ? this.plotConfig : this.customPlotConfig;
}
2020-06-22 06:05:03 +00:00
get dataset() {
return this.history[`${this.pair}__${this.timeframe}`];
}
2020-06-23 19:18:57 +00:00
get subplots() {
// Subplot keys (for selection window)
return Object.keys(this.plotConfig.subplots);
2020-06-23 18:37:14 +00:00
}
2020-06-22 06:05:03 +00:00
refresh() {
this.getPairHistory({ pair: this.pair, timeframe: this.timeframe, limit: 500 });
2020-06-23 05:09:58 +00:00
this.getPlotConfig();
2020-06-22 06:05:03 +00:00
}
2020-06-23 18:37:14 +00:00
addBar() {
2020-06-23 19:18:57 +00:00
console.log(`Adding ${this.selColumn} to ${this.selField}`);
console.log(this.customPlotConfig);
const plotConfig = this.customPlotConfig;
if (this.plotOption === 'main_plot') {
plotConfig[this.plotOption][this.selColumn] = { color: this.selColor };
} else {
plotConfig[this.plotOption][this.selField][this.selColumn] = { color: this.selColor };
}
this.customPlotConfig = { ...plotConfig };
// Reset random color
this.selColor = randomColor();
console.log(this.customPlotConfig);
2020-06-23 18:37:14 +00:00
}
2020-06-29 05:21:27 +00:00
addSubplot() {
this.customPlotConfig.subplots = {
...this.customPlotConfig.subplots,
[this.newSubplotName]: {},
};
this.selField = this.newSubplotName;
this.newSubplotName = '';
console.log(this.customPlotConfig);
}
2020-06-22 06:05:03 +00:00
}
2020-06-17 18:38:25 +00:00
</script>
<style scoped></style>