From 8b8693ae72d9e199df9432e3910a6c06ad16154b Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 23 Jun 2020 07:09:58 +0200 Subject: [PATCH] Get PlotConfig from backend --- src/components/ftbot/CandleChart.vue | 28 +++++++++------------------- src/store/modules/ftbot.ts | 11 +++++++++++ src/types/types.ts | 5 +++++ src/views/Graphs.vue | 14 +++++++++----- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/components/ftbot/CandleChart.vue b/src/components/ftbot/CandleChart.vue index 0829c41d..bdb21a2d 100644 --- a/src/components/ftbot/CandleChart.vue +++ b/src/components/ftbot/CandleChart.vue @@ -14,23 +14,6 @@ import 'echarts'; const MARGINLEFT = '5%'; const MARGINRIGHT = '4%'; -// TODO plotConfig should come from the backend, or be configurable via UI -const plotConfig = { - // eslint-disable-next-line @typescript-eslint/camelcase - main_plot: { - tema: { color: 'orange' }, - }, - subplots: { - MACD: { - macd: { color: 'blue' }, - macdsignal: { color: 'orange' }, - }, - RSI: { - rsi: { color: 'red' }, - }, - }, -}; - export default { name: 'CandleChart', components: { 'v-chart': ECharts }, @@ -47,6 +30,13 @@ export default { type: Object, required: true, }, + plotConfig: { + type: Object, + required: false, + default() { + return {}; + }, + }, }, data() { @@ -88,9 +78,9 @@ export default { series: [], }; - if ('subplots' in plotConfig) { + if ('subplots' in this.plotConfig) { let plotIndex = 2; - Object.entries(plotConfig.subplots).forEach(([key, value]) => { + Object.entries(this.plotConfig.subplots).forEach(([key, value]) => { subPlots.legend.push(key); // define yaxis subPlots.yaxis.push({ diff --git a/src/store/modules/ftbot.ts b/src/store/modules/ftbot.ts index e83ebdba..a93475c3 100644 --- a/src/store/modules/ftbot.ts +++ b/src/store/modules/ftbot.ts @@ -7,6 +7,7 @@ import { DailyPayload, Trade, PairHistoryPayload, + PlotConfig, } from '@/types'; import { showAlert } from './alerts'; @@ -35,6 +36,7 @@ export default { pairlistMethods: [], detailTradeId: null, history: {}, + plotConfig: {}, }, getters: { [BotStoreGetters.openTrades](state) { @@ -93,6 +95,9 @@ export default { updatePairHistory(state, { pair, timeframe, data }) { state.history = { ...state.history, [`${pair}__${timeframe}`]: data }; }, + updatePlotConfig(state, plotConfig: PlotConfig) { + state.plotConfig = plotConfig; + }, }, actions: { ping({ commit, rootState }) { @@ -143,6 +148,12 @@ export default { reject(error); }); }, + getPlotConfig({ commit }) { + return api + .get('/plot_config') + .then((result) => commit('updatePlotConfig', result.data)) + .catch(console.error); + }, getPerformance({ commit }) { return api .get('/performance') diff --git a/src/types/types.ts b/src/types/types.ts index 96b4ae4f..e8a31069 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -143,3 +143,8 @@ export interface PairHistoryPayload { timeframe: string; limit: number; } + +export interface PlotConfig { + main_plot?: object; + subplots?: object; +} diff --git a/src/views/Graphs.vue b/src/views/Graphs.vue index 0c921c20..c2983664 100644 --- a/src/views/Graphs.vue +++ b/src/views/Graphs.vue @@ -7,14 +7,14 @@
- + +