mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-11 02:33:51 +00:00
Add inteligent refresh logic that only refreshes when needed
closes #108
This commit is contained in:
parent
aa1b881072
commit
9265a6de53
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div>
|
||||
<button class="btn btn-secondary btn-sm" @click="refreshAll()">Refresh all</button>
|
||||
<button class="btn btn-secondary btn-sm" @click="refreshAll(true)">Refresh all</button>
|
||||
|
||||
<b-form-checkbox v-model="autoRefreshLoc" class="float-right" size="sm" switch
|
||||
>AutoRefresh</b-form-checkbox
|
||||
|
@ -21,7 +21,7 @@ export default class ReloadControl extends Vue {
|
|||
created() {
|
||||
if (this.loggedIn) {
|
||||
this.refreshOnce();
|
||||
this.refreshAll();
|
||||
this.refreshAll(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,10 +68,10 @@ export default class ReloadControl extends Vue {
|
|||
this.refreshFrequent();
|
||||
}, 5000);
|
||||
}
|
||||
this.refreshSlow();
|
||||
this.refreshSlow(true);
|
||||
if (this.autoRefresh) {
|
||||
this.refreshIntervalSlow = window.setInterval(() => {
|
||||
this.refreshSlow();
|
||||
this.refreshSlow(false);
|
||||
}, 60000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import Vue from 'vue';
|
|||
import Vuex from 'vuex';
|
||||
|
||||
import userService from '@/shared/userService';
|
||||
import ftbotModule from './modules/ftbot';
|
||||
import ftbotModule, { BotStoreGetters } from './modules/ftbot';
|
||||
import alertsModule from './modules/alerts';
|
||||
import layoutModule from './modules/layout';
|
||||
|
||||
|
@ -56,22 +56,26 @@ export default new Vuex.Store({
|
|||
refreshOnce({ dispatch }) {
|
||||
dispatch('ftbot/getVersion');
|
||||
},
|
||||
refreshAll({ dispatch }) {
|
||||
refreshAll({ dispatch }, forceUpdate = false) {
|
||||
dispatch('refreshFrequent');
|
||||
dispatch('refreshSlow');
|
||||
dispatch('refreshSlow', forceUpdate);
|
||||
dispatch('ftbot/getDaily');
|
||||
dispatch('ftbot/getBalance');
|
||||
/* white/blacklist might be refreshed more often as they are not expensive on the backend */
|
||||
dispatch('ftbot/getWhitelist');
|
||||
dispatch('ftbot/getBlacklist');
|
||||
},
|
||||
refreshSlow({ dispatch }) {
|
||||
// Refresh data that's needed "from time to time"
|
||||
// dispatch('ftbot/getDaily');
|
||||
dispatch('ftbot/getPerformance');
|
||||
dispatch('ftbot/getProfit');
|
||||
dispatch('ftbot/getTrades');
|
||||
refreshSlow({ dispatch, commit, getters }, forceUpdate = false) {
|
||||
// Refresh data only when needed
|
||||
if (forceUpdate || getters[`ftbot/${BotStoreGetters.refreshRequired}`]) {
|
||||
dispatch('ftbot/getPerformance');
|
||||
dispatch('ftbot/getProfit');
|
||||
dispatch('ftbot/getTrades');
|
||||
commit('ftbot/updateRefreshRequired', false);
|
||||
}
|
||||
},
|
||||
refreshFrequent({ dispatch }) {
|
||||
dispatch('refreshSlow', false);
|
||||
// Refresh data that's needed in near realtime
|
||||
dispatch('ftbot/getOpenTrades');
|
||||
dispatch('ftbot/getState');
|
||||
|
|
|
@ -42,6 +42,7 @@ export enum BotStoreGetters {
|
|||
timeframe = 'timeframe',
|
||||
isTrading = 'isTrading',
|
||||
isWebserverMode = 'isWebserverMode',
|
||||
refreshRequired = 'refreshRequired',
|
||||
}
|
||||
|
||||
export default {
|
||||
|
@ -49,6 +50,7 @@ export default {
|
|||
state: {
|
||||
version: '',
|
||||
lastLogs: '',
|
||||
refreshRequired: true,
|
||||
trades: [],
|
||||
openTrades: [],
|
||||
tradeCount: 0,
|
||||
|
@ -113,8 +115,14 @@ export default {
|
|||
[BotStoreGetters.isWebserverMode](state): boolean {
|
||||
return state.botState.runmode === RunModes.WEBSERVER;
|
||||
},
|
||||
[BotStoreGetters.refreshRequired](state): boolean {
|
||||
return state.refreshRequired;
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
updateRefreshRequired(state, refreshRequired: boolean) {
|
||||
state.refreshRequired = refreshRequired;
|
||||
},
|
||||
updateTrades(state, trades) {
|
||||
state.trades = trades.trades;
|
||||
state.tradeCount = trades.trades_count;
|
||||
|
@ -220,10 +228,24 @@ export default {
|
|||
.then((result) => commit('updateLocks', result.data))
|
||||
.catch(console.error);
|
||||
},
|
||||
getOpenTrades({ commit }) {
|
||||
getOpenTrades({ commit, state }) {
|
||||
return api
|
||||
.get('/status')
|
||||
.then((result) => commit('updateOpenTrades', result.data))
|
||||
.then((result) => {
|
||||
// Check if trade-id's are different in this call, then trigger a full refresh
|
||||
if (
|
||||
Array.isArray(state.openTrades) &&
|
||||
Array.isArray(result.data) &&
|
||||
(state.openTrades.length !== result.data.length ||
|
||||
!state.openTrades.every((val, index) => val.trade_id === result.data[index].trade_id))
|
||||
) {
|
||||
// Open trades changed, so we should refresh now.
|
||||
commit('updateRefreshRequired', true);
|
||||
// dispatch('refreshSlow', null, { root: true });
|
||||
}
|
||||
|
||||
commit('updateOpenTrades', result.data);
|
||||
})
|
||||
.catch(console.error);
|
||||
},
|
||||
getPairCandles({ commit }, payload: PairCandlePayload) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user