diff --git a/src/components/ftbot/CandleChart.vue b/src/components/ftbot/CandleChart.vue index 2eb0671f..b95dce04 100644 --- a/src/components/ftbot/CandleChart.vue +++ b/src/components/ftbot/CandleChart.vue @@ -75,8 +75,8 @@ export default class CandleChart extends Vue { const colLow = this.dataset.columns.findIndex((el) => el === 'low'); const colClose = this.dataset.columns.findIndex((el) => el === 'close'); const colVolume = this.dataset.columns.findIndex((el) => el === 'volume'); - const colBuy = this.dataset.columns.findIndex((el) => el === 'buy'); - const colSell = this.dataset.columns.findIndex((el) => el === 'sell'); + const colBuyData = this.dataset.columns.findIndex((el) => el === '_buy_signal_open'); + const colSellData = this.dataset.columns.findIndex((el) => el === '_sell_signal_open'); // Plot data const options: echarts.EChartOption = { @@ -237,7 +237,6 @@ export default class CandleChart extends Vue { type: 'scatter', symbol: 'triangle', symbolSize: 8, - data: this.buyData, xAxisIndex: 0, yAxisIndex: 0, itemStyle: { @@ -245,13 +244,12 @@ export default class CandleChart extends Vue { }, encode: { x: 0, - y: 1, + y: colBuyData, }, }, { name: 'Sell', type: 'scatter', - data: this.sellData, symbol: 'diamond', symbolSize: 8, xAxisIndex: 0, @@ -261,13 +259,13 @@ export default class CandleChart extends Vue { }, encode: { x: 0, - y: 1, + y: colSellData, }, }, ], }; - this.createSignalData(colDate, colOpen, colBuy, colSell); + // this.createSignalData(colDate, colOpen, colBuy, colSell); // This will be merged into final plot config // const subPlots = { @@ -386,21 +384,21 @@ export default class CandleChart extends Vue { return options; } - createSignalData(colDate: number, colOpen: number, colBuy: number, colSell: number): void { - // Calculate Buy and sell Series - if (!this.signalsCalculated) { - // Generate Buy and sell array (using open rate to display marker) - for (let i = 0, len = this.dataset.data.length; i < len; i += 1) { - if (this.dataset.data[i][colBuy] === 1) { - this.buyData.push([this.dataset.data[i][colDate], this.dataset.data[i][colOpen]]); - } - if (this.dataset.data[i][colSell] === 1) { - this.sellData.push([this.dataset.data[i][colDate], this.dataset.data[i][colOpen]]); - } - } - this.signalsCalculated = true; - } - } + // createSignalData(colDate: number, colOpen: number, colBuy: number, colSell: number): void { + // Calculate Buy and sell Series + // if (!this.signalsCalculated) { + // // Generate Buy and sell array (using open rate to display marker) + // for (let i = 0, len = this.dataset.data.length; i < len; i += 1) { + // if (this.dataset.data[i][colBuy] === 1) { + // this.buyData.push([this.dataset.data[i][colDate], this.dataset.data[i][colOpen]]); + // } + // if (this.dataset.data[i][colSell] === 1) { + // this.sellData.push([this.dataset.data[i][colDate], this.dataset.data[i][colOpen]]); + // } + // } + // this.signalsCalculated = true; + // } + // } } diff --git a/src/store/modules/ftbot.ts b/src/store/modules/ftbot.ts index b6afdf36..1d131cd7 100644 --- a/src/store/modules/ftbot.ts +++ b/src/store/modules/ftbot.ts @@ -6,6 +6,7 @@ import { Logs, DailyPayload, Trade, + PairCandlePayload, PairHistoryPayload, PlotConfig, EMPTY_PLOTCONFIG, @@ -38,6 +39,7 @@ export default { pairlistMethods: [], detailTradeId: null, candleData: {}, + history: {}, plotConfig: {}, customPlotConfig: { ...EMPTY_PLOTCONFIG }, }, @@ -98,6 +100,10 @@ export default { updatePairCandles(state, { pair, timeframe, data }) { state.candleData = { ...state.candleData, [`${pair}__${timeframe}`]: data }; }, + updatePairHistory(state, { pair, timeframe, data }) { + // Intentionally drop the previous state here. + state.history = { [`${pair}__${timeframe}`]: data }; + }, updatePlotConfig(state, plotConfig: PlotConfig) { state.plotConfig = plotConfig; }, @@ -133,11 +139,11 @@ export default { .then((result) => commit('updateOpenTrades', result.data)) .catch(console.error); }, - getPairCandles({ commit }, payload: PairHistoryPayload) { + getPairCandles({ commit }, payload: PairCandlePayload) { if (payload.pair && payload.timeframe && payload.limit) { return api .get('/pair_candles', { - params: { pair: payload.pair, timeframe: payload.timeframe, limit: payload.limit }, + params: { ...payload }, }) .then((result) => { commit('updatePairCandles', { @@ -155,6 +161,30 @@ export default { reject(error); }); }, + getPairHistory({ commit }, payload: PairHistoryPayload) { + if (payload.pair && payload.timeframe && payload.limit && payload.timerange) { + return api + .get('/pair_history', { + params: { ...payload }, + timeout: 10000, + }) + .then((result) => { + commit('updatePairHistory', { + pair: payload.pair, + timeframe: payload.timeframe, + timerange: payload.timerange, + data: result.data, + }); + }) + .catch(console.error); + } + // Error branchs + const error = 'pair or timeframe or timerange not specified'; + console.error(error); + return new Promise((resolve, reject) => { + reject(error); + }); + }, getPlotConfig({ commit }) { return api .get('/plot_config') diff --git a/src/types/types.ts b/src/types/types.ts index 38a6e010..9d633548 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -138,13 +138,18 @@ export interface ClosedTrade extends Trade { open_order_id?: string; } -export interface PairHistoryPayload { +export interface PairCandlePayload { pair: string; timeframe: string; limit: number; } +export interface PairHistoryPayload extends PairCandlePayload { + timerange: string; +} + export interface PairHistory { + pair: string; columns: string[]; data: number[]; length: number; diff --git a/src/views/Graphs.vue b/src/views/Graphs.vue index 3e9a8949..27a9949c 100644 --- a/src/views/Graphs.vue +++ b/src/views/Graphs.vue @@ -1,6 +1,10 @@