mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-23 19:45:15 +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) {
|
selectBot({ commit }, botId: string) {
|
||||||
commit('selectBot', botId);
|
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) {
|
if (state.refreshing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -160,33 +177,24 @@ export default function createBotStore(store) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
startRefresh({ getters, state, dispatch, commit }, runNow: boolean) {
|
startRefresh({ state, dispatch, commit }) {
|
||||||
console.log('starting refresh');
|
|
||||||
// Start refresh timer
|
|
||||||
if (getters.hasBots !== true) {
|
|
||||||
console.log('Not logged in.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log('Starting automatic refresh.');
|
console.log('Starting automatic refresh.');
|
||||||
if (runNow) {
|
dispatch('allRefreshFrequent');
|
||||||
dispatch('refreshFrequent', false);
|
|
||||||
dispatch('refreshSlow', true);
|
|
||||||
}
|
|
||||||
if (state.autoRefresh) {
|
|
||||||
if (!state.refreshInterval) {
|
if (!state.refreshInterval) {
|
||||||
// Set interval for refresh
|
// Set interval for refresh
|
||||||
const refreshInterval = window.setInterval(() => {
|
const refreshInterval = window.setInterval(() => {
|
||||||
dispatch('refreshFrequent');
|
dispatch('allRefreshFrequent');
|
||||||
}, 5000);
|
}, 5000);
|
||||||
commit('setRefreshInterval', refreshInterval);
|
commit('setRefreshInterval', refreshInterval);
|
||||||
}
|
}
|
||||||
|
dispatch('allRefreshSlow', false);
|
||||||
if (!state.refreshIntervalSlow) {
|
if (!state.refreshIntervalSlow) {
|
||||||
const refreshIntervalSlow = window.setInterval(() => {
|
const refreshIntervalSlow = window.setInterval(() => {
|
||||||
dispatch('refreshSlow', false);
|
dispatch('allRefreshSlow', false);
|
||||||
}, 60000);
|
}, 60000);
|
||||||
commit('setRefreshIntervalSlow', refreshIntervalSlow);
|
commit('setRefreshIntervalSlow', refreshIntervalSlow);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
stopRefresh({ state, commit }: { state: FTMultiBotState; commit: any }) {
|
stopRefresh({ state, commit }: { state: FTMultiBotState; commit: any }) {
|
||||||
console.log('Stopping automatic refresh.');
|
console.log('Stopping automatic refresh.');
|
||||||
|
|
|
@ -45,7 +45,11 @@ import { showAlert } from '../alerts';
|
||||||
export enum BotStoreGetters {
|
export enum BotStoreGetters {
|
||||||
botName = 'botName',
|
botName = 'botName',
|
||||||
isBotOnline = 'isBotOnline',
|
isBotOnline = 'isBotOnline',
|
||||||
|
|
||||||
autoRefresh = 'autoRefresh',
|
autoRefresh = 'autoRefresh',
|
||||||
|
refreshNow = 'refreshNow',
|
||||||
|
refreshing = 'refreshing',
|
||||||
|
|
||||||
openTrades = 'openTrades',
|
openTrades = 'openTrades',
|
||||||
openTradeCount = 'openTradeCount',
|
openTradeCount = 'openTradeCount',
|
||||||
tradeDetail = 'tradeDetail',
|
tradeDetail = 'tradeDetail',
|
||||||
|
@ -152,6 +156,15 @@ export function createBotSubStore(botId: string) {
|
||||||
[BotStoreGetters.autoRefresh](state: FtbotStateType): boolean {
|
[BotStoreGetters.autoRefresh](state: FtbotStateType): boolean {
|
||||||
return state.autoRefresh;
|
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) {
|
[BotStoreGetters.plotConfig](state: FtbotStateType) {
|
||||||
return state.customPlotConfig[state.plotConfigName] || { ...EMPTY_PLOTCONFIG };
|
return state.customPlotConfig[state.plotConfigName] || { ...EMPTY_PLOTCONFIG };
|
||||||
},
|
},
|
||||||
|
@ -301,6 +314,9 @@ export function createBotSubStore(botId: string) {
|
||||||
setAutoRefresh(state: FtbotStateType, newRefreshValue: boolean) {
|
setAutoRefresh(state: FtbotStateType, newRefreshValue: boolean) {
|
||||||
state.autoRefresh = newRefreshValue;
|
state.autoRefresh = newRefreshValue;
|
||||||
},
|
},
|
||||||
|
setRefreshing(state, refreshing: boolean) {
|
||||||
|
state.refreshing = refreshing;
|
||||||
|
},
|
||||||
updateRefreshRequired(state: FtbotStateType, refreshRequired: boolean) {
|
updateRefreshRequired(state: FtbotStateType, refreshRequired: boolean) {
|
||||||
state.refreshRequired = refreshRequired;
|
state.refreshRequired = refreshRequired;
|
||||||
},
|
},
|
||||||
|
@ -421,7 +437,7 @@ export function createBotSubStore(botId: string) {
|
||||||
commit('updateRefreshRequired', refreshRequired);
|
commit('updateRefreshRequired', refreshRequired);
|
||||||
},
|
},
|
||||||
[BotStoreActions.setAutoRefresh]({ dispatch, commit }, newRefreshValue) {
|
[BotStoreActions.setAutoRefresh]({ dispatch, commit }, newRefreshValue) {
|
||||||
// commit('setAutoRefresh', newRefreshValue);
|
commit('setAutoRefresh', newRefreshValue);
|
||||||
// TODO: Investigate this -
|
// TODO: Investigate this -
|
||||||
// this ONLY works if ReloadControl is only visible once,otherwise it triggers twice
|
// this ONLY works if ReloadControl is only visible once,otherwise it triggers twice
|
||||||
if (newRefreshValue) {
|
if (newRefreshValue) {
|
||||||
|
@ -435,7 +451,7 @@ export function createBotSubStore(botId: string) {
|
||||||
commit('setIsBotOnline', refreshRequired);
|
commit('setIsBotOnline', refreshRequired);
|
||||||
},
|
},
|
||||||
[BotStoreActions.refreshOnce]({ dispatch }) {
|
[BotStoreActions.refreshOnce]({ dispatch }) {
|
||||||
dispatch('getVersion');
|
dispatch(BotStoreActions.getVersion);
|
||||||
},
|
},
|
||||||
async [BotStoreActions.refreshSlow]({ dispatch, getters, state }, forceUpdate = false) {
|
async [BotStoreActions.refreshSlow]({ dispatch, getters, state }, forceUpdate = false) {
|
||||||
if (state.refreshing && !forceUpdate) {
|
if (state.refreshing && !forceUpdate) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ export interface FtbotStateType {
|
||||||
ping: string;
|
ping: string;
|
||||||
isBotOnline: boolean;
|
isBotOnline: boolean;
|
||||||
autoRefresh: boolean;
|
autoRefresh: boolean;
|
||||||
|
refreshing: boolean;
|
||||||
version: string;
|
version: string;
|
||||||
lastLogs: LogLine[];
|
lastLogs: LogLine[];
|
||||||
refreshRequired: boolean;
|
refreshRequired: boolean;
|
||||||
|
@ -62,6 +63,7 @@ const state = (): FtbotStateType => {
|
||||||
ping: '',
|
ping: '',
|
||||||
isBotOnline: false,
|
isBotOnline: false,
|
||||||
autoRefresh: false,
|
autoRefresh: false,
|
||||||
|
refreshing: false,
|
||||||
version: '',
|
version: '',
|
||||||
lastLogs: [],
|
lastLogs: [],
|
||||||
refreshRequired: true,
|
refreshRequired: true,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user