Merge pull request #693 from xxRockOnxx/feat/trading-loading-status

Show CandleChartContainer loading status
This commit is contained in:
Matthias 2022-03-04 06:47:51 +01:00 committed by GitHub
commit 0acf5889e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 3 deletions

View File

@ -64,7 +64,13 @@
:theme="getChartTheme" :theme="getChartTheme"
> >
</CandleChart> </CandleChart>
<label v-else style="margin: auto auto; font-size: 1.5rem">No data available</label> <div v-else class="m-auto">
<b-spinner v-if="isLoadingDataset" label="Spinning" />
<div v-else style="font-size: 1.5rem">
{{ noDatasetText }}
</div>
</div>
</div> </div>
</div> </div>
<transition name="fade" mode="in-out"> <transition name="fade" mode="in-out">
@ -85,6 +91,7 @@ import {
PlotConfig, PlotConfig,
PairCandlePayload, PairCandlePayload,
PairHistoryPayload, PairHistoryPayload,
LoadingStatus,
} from '@/types'; } from '@/types';
import CandleChart from '@/components/charts/CandleChart.vue'; import CandleChart from '@/components/charts/CandleChart.vue';
import PlotConfigurator from '@/components/charts/PlotConfigurator.vue'; import PlotConfigurator from '@/components/charts/PlotConfigurator.vue';
@ -131,8 +138,12 @@ export default class CandleChartContainer extends Vue {
@ftbot.Action setPlotConfigName; @ftbot.Action setPlotConfigName;
@ftbot.Getter [BotStoreGetters.candleDataStatus]!: LoadingStatus;
@ftbot.Getter [BotStoreGetters.candleData]!: PairHistory; @ftbot.Getter [BotStoreGetters.candleData]!: PairHistory;
@ftbot.Getter [BotStoreGetters.historyStatus]!: LoadingStatus;
@ftbot.Getter [BotStoreGetters.history]!: PairHistory; @ftbot.Getter [BotStoreGetters.history]!: PairHistory;
@ftbot.Getter [BotStoreGetters.selectedPair]!: string; @ftbot.Getter [BotStoreGetters.selectedPair]!: string;
@ -160,6 +171,32 @@ export default class CandleChartContainer extends Vue {
return this.dataset ? this.dataset.columns : []; return this.dataset ? this.dataset.columns : [];
} }
get isLoadingDataset(): boolean {
if (this.historicView) {
return this.historyStatus === 'loading';
}
return this.candleDataStatus === 'loading';
}
get noDatasetText(): string {
const status = this.historicView ? this.historyStatus : this.candleDataStatus;
switch (status) {
case 'loading':
return 'Loading...';
case 'success':
return 'No data available';
case 'error':
return 'Failed to load data';
default:
return 'Unknown';
}
}
get hasDataset(): boolean { get hasDataset(): boolean {
return !!this.dataset; return !!this.dataset;
} }
@ -172,6 +209,10 @@ export default class CandleChartContainer extends Vue {
} }
this.plotConfigName = getPlotConfigName(); this.plotConfigName = getPlotConfigName();
this.plotConfig = getCustomPlotConfig(this.plotConfigName); this.plotConfig = getCustomPlotConfig(this.plotConfigName);
if (!this.hasDataset) {
this.refresh();
}
} }
plotConfigChanged() { plotConfigChanged() {

View File

@ -36,6 +36,7 @@ import {
DeleteTradeResponse, DeleteTradeResponse,
BlacklistResponse, BlacklistResponse,
ForceSellPayload, ForceSellPayload,
LoadingStatus,
} from '@/types'; } from '@/types';
import { import {
@ -90,12 +91,14 @@ export enum BotStoreGetters {
pairlist = 'pairlist', pairlist = 'pairlist',
balance = 'balance', balance = 'balance',
detailTradeId = 'detailTradeId', detailTradeId = 'detailTradeId',
historyStatus = 'historyStatus',
history = 'history', history = 'history',
lastLogs = 'lastLogs', lastLogs = 'lastLogs',
performanceStats = 'performanceStats', performanceStats = 'performanceStats',
dailyStats = 'dailyStats', dailyStats = 'dailyStats',
strategy = 'strategy', strategy = 'strategy',
strategyList = 'strategyList', strategyList = 'strategyList',
candleDataStatus = 'candleDataStatus',
candleData = 'candleData', candleData = 'candleData',
backtestRunning = 'backtestRunning', backtestRunning = 'backtestRunning',
backtestStep = 'backtestStep', backtestStep = 'backtestStep',
@ -310,9 +313,15 @@ export function createBotSubStore(botId: string, botName: string) {
[BotStoreGetters.strategyList](state: FtbotStateType): string[] { [BotStoreGetters.strategyList](state: FtbotStateType): string[] {
return state.strategyList; return state.strategyList;
}, },
[BotStoreGetters.candleDataStatus](state: FtbotStateType): LoadingStatus {
return state.candleDataStatus;
},
[BotStoreGetters.candleData](state: FtbotStateType): PairHistory | {} { [BotStoreGetters.candleData](state: FtbotStateType): PairHistory | {} {
return state.candleData; return state.candleData;
}, },
[BotStoreGetters.historyStatus](state: FtbotStateType): LoadingStatus {
return state.historyStatus;
},
// TODO: Type me // TODO: Type me
[BotStoreGetters.history](state: FtbotStateType) { [BotStoreGetters.history](state: FtbotStateType) {
return state.history; return state.history;
@ -406,9 +415,15 @@ export function createBotSubStore(botId: string, botName: string) {
updatePairs(state: FtbotStateType, pairlist: string[]) { updatePairs(state: FtbotStateType, pairlist: string[]) {
state.pairlist = pairlist; state.pairlist = pairlist;
}, },
setCandleDataStatus(state: FtbotStateType, loading: LoadingStatus) {
state.candleDataStatus = loading;
},
updatePairCandles(state: FtbotStateType, { pair, timeframe, data }) { updatePairCandles(state: FtbotStateType, { pair, timeframe, data }) {
state.candleData = { ...state.candleData, [`${pair}__${timeframe}`]: data }; state.candleData = { ...state.candleData, [`${pair}__${timeframe}`]: data };
}, },
setHistoryStatus(state: FtbotStateType, loading: LoadingStatus) {
state.historyStatus = loading;
},
updatePairHistory(state: FtbotStateType, { pair, timeframe, data }) { updatePairHistory(state: FtbotStateType, { pair, timeframe, data }) {
// Intentionally drop the previous state here. // Intentionally drop the previous state here.
state.history = { [`${pair}__${timeframe}`]: data }; state.history = { [`${pair}__${timeframe}`]: data };
@ -621,6 +636,7 @@ export function createBotSubStore(botId: string, botName: string) {
}, },
[BotStoreActions.getPairCandles]({ commit }, payload: PairCandlePayload) { [BotStoreActions.getPairCandles]({ commit }, payload: PairCandlePayload) {
if (payload.pair && payload.timeframe) { if (payload.pair && payload.timeframe) {
commit('setCandleDataStatus', 'loading');
return api return api
.get('/pair_candles', { .get('/pair_candles', {
params: { ...payload }, params: { ...payload },
@ -631,8 +647,12 @@ export function createBotSubStore(botId: string, botName: string) {
timeframe: payload.timeframe, timeframe: payload.timeframe,
data: result.data, data: result.data,
}); });
commit('setCandleDataStatus', 'success');
}) })
.catch(console.error); .catch((err) => {
console.error(err);
commit('setCandleDataStatus', 'error');
});
} }
// Error branchs // Error branchs
const error = 'pair or timeframe not specified'; const error = 'pair or timeframe not specified';
@ -643,6 +663,7 @@ export function createBotSubStore(botId: string, botName: string) {
}, },
[BotStoreActions.getPairHistory]({ commit }, payload: PairHistoryPayload) { [BotStoreActions.getPairHistory]({ commit }, payload: PairHistoryPayload) {
if (payload.pair && payload.timeframe && payload.timerange) { if (payload.pair && payload.timeframe && payload.timerange) {
commit('setHistoryStatus', 'loading');
return api return api
.get('/pair_history', { .get('/pair_history', {
params: { ...payload }, params: { ...payload },
@ -655,8 +676,12 @@ export function createBotSubStore(botId: string, botName: string) {
timerange: payload.timerange, timerange: payload.timerange,
data: result.data, data: result.data,
}); });
commit('setHistoryStatus', 'success');
}) })
.catch(console.error); .catch((err) => {
console.error(err);
commit('setHistoryStatus', 'error');
});
} }
// Error branchs // Error branchs
const error = 'pair or timeframe or timerange not specified'; const error = 'pair or timeframe or timerange not specified';

View File

@ -15,6 +15,7 @@ import {
BacktestSteps, BacktestSteps,
LogLine, LogLine,
SysInfoResponse, SysInfoResponse,
LoadingStatus,
} from '@/types'; } from '@/types';
export interface FtbotStateType { export interface FtbotStateType {
@ -40,8 +41,10 @@ export interface FtbotStateType {
selectedPair: string; selectedPair: string;
// TODO: type me // TODO: type me
candleData: {}; candleData: {};
candleDataStatus: LoadingStatus;
// TODO: type me // TODO: type me
history: {}; history: {};
historyStatus: LoadingStatus;
strategyPlotConfig?: PlotConfig; strategyPlotConfig?: PlotConfig;
customPlotConfig: PlotConfigStorage; customPlotConfig: PlotConfigStorage;
plotConfigName: string; plotConfigName: string;
@ -83,7 +86,9 @@ const state = (): FtbotStateType => {
detailTradeId: undefined, detailTradeId: undefined,
selectedPair: '', selectedPair: '',
candleData: {}, candleData: {},
candleDataStatus: 'loading',
history: {}, history: {},
historyStatus: 'loading',
strategyPlotConfig: undefined, strategyPlotConfig: undefined,
customPlotConfig: {}, customPlotConfig: {},
plotConfigName: getPlotConfigName(), plotConfigName: getPlotConfigName(),

View File

@ -237,3 +237,5 @@ export interface DeleteTradeResponse {
export interface UiVersion { export interface UiVersion {
version: string; version: string;
} }
export type LoadingStatus = 'loading' | 'success' | 'error';