mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-10 18:23:50 +00:00
move refreshing logic to subbots
This commit is contained in:
parent
9d682da2ca
commit
be4b90f5a3
|
@ -141,7 +141,24 @@ export default function createBotStore(store) {
|
|||
selectBot({ commit }, botId: string) {
|
||||
commit('selectBot', botId);
|
||||
},
|
||||
async refreshFull({ dispatch, state, commit }, forceUpdate = false) {
|
||||
allRefreshFrequent({ dispatch, getters }) {
|
||||
console.log('dispatching all frequent refreshes');
|
||||
getters.allAvailableBotsList.forEach((e) => {
|
||||
if (getters[`${e}/${BotStoreGetters.autoRefresh}`]) {
|
||||
console.log('refreshing ', e);
|
||||
dispatch(`${e}/${BotStoreActions.refreshFrequent}`);
|
||||
}
|
||||
});
|
||||
},
|
||||
allRefreshSlow({ dispatch, getters }) {
|
||||
console.log('dispatching all slow refreshes');
|
||||
getters.allAvailableBotsList.forEach((e) => {
|
||||
if (getters[`${e}/${BotStoreGetters.autoRefresh}`]) {
|
||||
dispatch(`${e}/${BotStoreActions.refreshSlow}`);
|
||||
}
|
||||
});
|
||||
},
|
||||
async refreshxxFull({ commit, dispatch, getters, state }, forceUpdate = false) {
|
||||
if (state.refreshing) {
|
||||
return;
|
||||
}
|
||||
|
@ -160,32 +177,23 @@ export default function createBotStore(store) {
|
|||
}
|
||||
},
|
||||
|
||||
startRefresh({ getters, state, dispatch, commit }, runNow: boolean) {
|
||||
console.log('starting refresh');
|
||||
// Start refresh timer
|
||||
if (getters.hasBots !== true) {
|
||||
console.log('Not logged in.');
|
||||
return;
|
||||
}
|
||||
startRefresh({ state, dispatch, commit }) {
|
||||
console.log('Starting automatic refresh.');
|
||||
if (runNow) {
|
||||
dispatch('refreshFrequent', false);
|
||||
dispatch('refreshSlow', true);
|
||||
dispatch('allRefreshFrequent');
|
||||
|
||||
if (!state.refreshInterval) {
|
||||
// Set interval for refresh
|
||||
const refreshInterval = window.setInterval(() => {
|
||||
dispatch('allRefreshFrequent');
|
||||
}, 5000);
|
||||
commit('setRefreshInterval', refreshInterval);
|
||||
}
|
||||
if (state.autoRefresh) {
|
||||
if (!state.refreshInterval) {
|
||||
// Set interval for refresh
|
||||
const refreshInterval = window.setInterval(() => {
|
||||
dispatch('refreshFrequent');
|
||||
}, 5000);
|
||||
commit('setRefreshInterval', refreshInterval);
|
||||
}
|
||||
if (!state.refreshIntervalSlow) {
|
||||
const refreshIntervalSlow = window.setInterval(() => {
|
||||
dispatch('refreshSlow', false);
|
||||
}, 60000);
|
||||
commit('setRefreshIntervalSlow', refreshIntervalSlow);
|
||||
}
|
||||
dispatch('allRefreshSlow', false);
|
||||
if (!state.refreshIntervalSlow) {
|
||||
const refreshIntervalSlow = window.setInterval(() => {
|
||||
dispatch('allRefreshSlow', false);
|
||||
}, 60000);
|
||||
commit('setRefreshIntervalSlow', refreshIntervalSlow);
|
||||
}
|
||||
},
|
||||
stopRefresh({ state, commit }: { state: FTMultiBotState; commit: any }) {
|
||||
|
|
|
@ -45,7 +45,11 @@ import { showAlert } from '../alerts';
|
|||
export enum BotStoreGetters {
|
||||
botName = 'botName',
|
||||
isBotOnline = 'isBotOnline',
|
||||
|
||||
autoRefresh = 'autoRefresh',
|
||||
refreshNow = 'refreshNow',
|
||||
refreshing = 'refreshing',
|
||||
|
||||
openTrades = 'openTrades',
|
||||
openTradeCount = 'openTradeCount',
|
||||
tradeDetail = 'tradeDetail',
|
||||
|
@ -152,6 +156,15 @@ export function createBotSubStore(botId: string) {
|
|||
[BotStoreGetters.autoRefresh](state: FtbotStateType): boolean {
|
||||
return state.autoRefresh;
|
||||
},
|
||||
[BotStoreGetters.refreshNow](state, getters, rootState, rootGetters): boolean {
|
||||
const bgRefresh = rootGetters['uiSettings/backgroundSync'];
|
||||
const selectedBot = rootGetters['ftbot/selectedBot'];
|
||||
if ((selectedBot === botId || bgRefresh) && getters.autoRefresh) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
[BotStoreGetters.plotConfig](state: FtbotStateType) {
|
||||
return state.customPlotConfig[state.plotConfigName] || { ...EMPTY_PLOTCONFIG };
|
||||
},
|
||||
|
@ -301,6 +314,9 @@ export function createBotSubStore(botId: string) {
|
|||
setAutoRefresh(state: FtbotStateType, newRefreshValue: boolean) {
|
||||
state.autoRefresh = newRefreshValue;
|
||||
},
|
||||
setRefreshing(state, refreshing: boolean) {
|
||||
state.refreshing = refreshing;
|
||||
},
|
||||
updateRefreshRequired(state: FtbotStateType, refreshRequired: boolean) {
|
||||
state.refreshRequired = refreshRequired;
|
||||
},
|
||||
|
@ -421,7 +437,7 @@ export function createBotSubStore(botId: string) {
|
|||
commit('updateRefreshRequired', refreshRequired);
|
||||
},
|
||||
[BotStoreActions.setAutoRefresh]({ dispatch, commit }, newRefreshValue) {
|
||||
// commit('setAutoRefresh', newRefreshValue);
|
||||
commit('setAutoRefresh', newRefreshValue);
|
||||
// TODO: Investigate this -
|
||||
// this ONLY works if ReloadControl is only visible once,otherwise it triggers twice
|
||||
if (newRefreshValue) {
|
||||
|
@ -435,7 +451,7 @@ export function createBotSubStore(botId: string) {
|
|||
commit('setIsBotOnline', refreshRequired);
|
||||
},
|
||||
[BotStoreActions.refreshOnce]({ dispatch }) {
|
||||
dispatch('getVersion');
|
||||
dispatch(BotStoreActions.getVersion);
|
||||
},
|
||||
async [BotStoreActions.refreshSlow]({ dispatch, getters, state }, forceUpdate = false) {
|
||||
if (state.refreshing && !forceUpdate) {
|
||||
|
|
|
@ -20,6 +20,7 @@ export interface FtbotStateType {
|
|||
ping: string;
|
||||
isBotOnline: boolean;
|
||||
autoRefresh: boolean;
|
||||
refreshing: boolean;
|
||||
version: string;
|
||||
lastLogs: LogLine[];
|
||||
refreshRequired: boolean;
|
||||
|
@ -62,6 +63,7 @@ const state = (): FtbotStateType => {
|
|||
ping: '',
|
||||
isBotOnline: false,
|
||||
autoRefresh: false,
|
||||
refreshing: false,
|
||||
version: '',
|
||||
lastLogs: [],
|
||||
refreshRequired: true,
|
||||
|
|
Loading…
Reference in New Issue
Block a user