frequi_origin/src/views/Graphs.vue

208 lines
5.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>
2020-07-01 04:41:59 +00:00
<div v-if="!strategyPlotConfig && dataset" class="container-fluid">
2020-06-23 18:37:14 +00:00
<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">
2020-06-30 19:00:29 +00:00
<b-form-select id="FieldSel" :options="subplots" v-model="selField" :select-size="4">
</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-30 19:00:29 +00:00
<div class="col-mb-3 ml-2">
<b-button variant="primary" @click="loadPlotConfig">Load</b-button>
</div>
<div class="col-mb-3 ml-2">
<b-button variant="primary" @click="savePlotConfig">Save</b-button>
</div>
2020-06-29 05:21:27 +00:00
<div class="col-mb-3 ml-2">
2020-06-30 06:07:34 +00:00
<b-button variant="primary" @click="showConfig = !showConfig">Show</b-button>
</div>
<div class="col-mb-5 ml-2" v-if="showConfig">
<b-textarea id="TextArea" v-model="plotConfigJson"> </b-textarea>
2020-06-29 05:21:27 +00:00
</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-30 19:00:29 +00:00
import { loadCustomPlotConfig } from '../shared/storage';
import { PlotConfig, EMPTY_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
2020-06-30 19:00:29 +00:00
customPlotConfig: PlotConfig = { ...EMPTY_PLOTCONFIG };
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-30 19:00:29 +00:00
@ftbot.Mutation
saveCustomPlotConfig;
2020-06-30 06:07:34 +00:00
showConfig = false;
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
2020-06-30 19:00:29 +00:00
this.customPlotConfig = loadCustomPlotConfig();
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)
2020-06-30 06:09:55 +00:00
return Object.keys(this.selectedPlotConfig.subplots);
2020-06-23 18:37:14 +00:00
}
2020-06-30 06:07:34 +00:00
get plotConfigJson() {
return JSON.stringify(this.selectedPlotConfig, null, 2);
}
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(this.customPlotConfig);
const plotConfig = this.customPlotConfig;
if (this.plotOption === 'main_plot') {
2020-06-30 06:07:34 +00:00
console.log(`Adding ${this.selColumn} to MainPlot`);
console.log(plotConfig);
2020-06-23 19:18:57 +00:00
plotConfig[this.plotOption][this.selColumn] = { color: this.selColor };
} else {
2020-06-30 06:07:34 +00:00
console.log(`Adding ${this.selColumn} to ${this.selField}`);
2020-06-23 19:18:57 +00:00
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-30 19:00:29 +00:00
savePlotConfig() {
this.saveCustomPlotConfig(this.customPlotConfig);
}
loadPlotConfig() {
this.customPlotConfig = loadCustomPlotConfig();
console.log(this.customPlotConfig);
console.log('loading config');
}
2020-06-22 06:05:03 +00:00
}
2020-06-17 18:38:25 +00:00
</script>
<style scoped></style>