mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-27 05:25:17 +00:00
Move refresh actions to subBotStore
This commit is contained in:
parent
ea71dcc190
commit
b23c122629
|
@ -165,36 +165,7 @@ export default function createBotStore(store) {
|
||||||
commit('setRefreshing', false);
|
commit('setRefreshing', false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async refreshSlow({ dispatch, getters, state }, forceUpdate = false) {
|
|
||||||
if (state.refreshing && !forceUpdate) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Refresh data only when needed
|
|
||||||
if (forceUpdate || getters[`${BotStoreGetters.refreshRequired}`]) {
|
|
||||||
const updates: Promise<AxiosInstance>[] = [];
|
|
||||||
updates.push(dispatch('getPerformance'));
|
|
||||||
updates.push(dispatch('getProfit'));
|
|
||||||
updates.push(dispatch('getTrades'));
|
|
||||||
/* white/blacklist might be refreshed more often as they are not expensive on the backend */
|
|
||||||
updates.push(dispatch('getWhitelist'));
|
|
||||||
updates.push(dispatch('getBlacklist'));
|
|
||||||
|
|
||||||
await Promise.all(updates);
|
|
||||||
dispatch('setRefreshRequired', false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
refreshFrequent({ dispatch }, slow = true) {
|
|
||||||
if (slow) {
|
|
||||||
dispatch('refreshSlow', false);
|
|
||||||
}
|
|
||||||
// Refresh data that's needed in near realtime
|
|
||||||
dispatch('getOpenTrades');
|
|
||||||
dispatch('getState');
|
|
||||||
dispatch('getLocks');
|
|
||||||
},
|
|
||||||
refreshOnce({ dispatch }) {
|
|
||||||
dispatch('getVersion');
|
|
||||||
},
|
|
||||||
startRefresh({ getters, state, dispatch, commit }, runNow: boolean) {
|
startRefresh({ getters, state, dispatch, commit }, runNow: boolean) {
|
||||||
console.log('starting refresh');
|
console.log('starting refresh');
|
||||||
// Start refresh timer
|
// Start refresh timer
|
||||||
|
@ -205,23 +176,23 @@ export default function createBotStore(store) {
|
||||||
console.log('Starting automatic refresh.');
|
console.log('Starting automatic refresh.');
|
||||||
if (runNow) {
|
if (runNow) {
|
||||||
dispatch('refreshFrequent', false);
|
dispatch('refreshFrequent', false);
|
||||||
|
dispatch('refreshSlow', true);
|
||||||
}
|
}
|
||||||
if (state.autoRefresh && !state.refreshInterval) {
|
if (state.autoRefresh) {
|
||||||
|
if (!state.refreshInterval) {
|
||||||
// Set interval for refresh
|
// Set interval for refresh
|
||||||
const refreshInterval = window.setInterval(() => {
|
const refreshInterval = window.setInterval(() => {
|
||||||
dispatch('refreshFrequent');
|
dispatch('refreshFrequent');
|
||||||
}, 5000);
|
}, 5000);
|
||||||
commit('setRefreshInterval', refreshInterval);
|
commit('setRefreshInterval', refreshInterval);
|
||||||
}
|
}
|
||||||
if (runNow) {
|
if (!state.refreshIntervalSlow) {
|
||||||
dispatch('refreshSlow', true);
|
|
||||||
}
|
|
||||||
if (state.autoRefresh && !state.refreshIntervalSlow) {
|
|
||||||
const refreshIntervalSlow = window.setInterval(() => {
|
const refreshIntervalSlow = window.setInterval(() => {
|
||||||
dispatch('refreshSlow', false);
|
dispatch('refreshSlow', 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.');
|
||||||
|
|
|
@ -37,7 +37,8 @@ import {
|
||||||
getAllPlotConfigNames,
|
getAllPlotConfigNames,
|
||||||
storePlotConfigName,
|
storePlotConfigName,
|
||||||
} from '@/shared/storage';
|
} from '@/shared/storage';
|
||||||
import axios from 'axios';
|
import axios, { AxiosInstance } from 'axios';
|
||||||
|
|
||||||
import state, { FtbotStateType } from './state';
|
import state, { FtbotStateType } from './state';
|
||||||
import { showAlert } from '../alerts';
|
import { showAlert } from '../alerts';
|
||||||
|
|
||||||
|
@ -89,6 +90,9 @@ export enum BotStoreGetters {
|
||||||
export enum BotStoreActions {
|
export enum BotStoreActions {
|
||||||
ping = 'ping',
|
ping = 'ping',
|
||||||
setRefreshRequired = 'setRefreshRequired',
|
setRefreshRequired = 'setRefreshRequired',
|
||||||
|
refreshSlow = 'refreshSlow',
|
||||||
|
refreshFrequent = 'refreshFrequent',
|
||||||
|
refreshOnce = 'refreshOnce',
|
||||||
setDetailTrade = 'setDetailTrade',
|
setDetailTrade = 'setDetailTrade',
|
||||||
setSelectedPair = 'setSelectedPair',
|
setSelectedPair = 'setSelectedPair',
|
||||||
getTrades = 'getTrades',
|
getTrades = 'getTrades',
|
||||||
|
@ -406,6 +410,37 @@ export function createBotSubStore(botId: string) {
|
||||||
[BotStoreActions.setRefreshRequired]({ commit }, refreshRequired: boolean) {
|
[BotStoreActions.setRefreshRequired]({ commit }, refreshRequired: boolean) {
|
||||||
commit('updateRefreshRequired', refreshRequired);
|
commit('updateRefreshRequired', refreshRequired);
|
||||||
},
|
},
|
||||||
|
[BotStoreActions.refreshOnce]({ dispatch }) {
|
||||||
|
dispatch('getVersion');
|
||||||
|
},
|
||||||
|
async [BotStoreActions.refreshSlow]({ dispatch, getters, state }, forceUpdate = false) {
|
||||||
|
if (state.refreshing && !forceUpdate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Refresh data only when needed
|
||||||
|
if (forceUpdate || getters[`${BotStoreGetters.refreshRequired}`]) {
|
||||||
|
const updates: Promise<AxiosInstance>[] = [];
|
||||||
|
updates.push(dispatch('getPerformance'));
|
||||||
|
updates.push(dispatch('getProfit'));
|
||||||
|
updates.push(dispatch('getTrades'));
|
||||||
|
/* white/blacklist might be refreshed more often as they are not expensive on the backend */
|
||||||
|
updates.push(dispatch('getWhitelist'));
|
||||||
|
updates.push(dispatch('getBlacklist'));
|
||||||
|
|
||||||
|
await Promise.all(updates);
|
||||||
|
dispatch('setRefreshRequired', false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[BotStoreActions.refreshFrequent]({ dispatch }, slow = true) {
|
||||||
|
if (slow) {
|
||||||
|
dispatch('refreshSlow', false);
|
||||||
|
}
|
||||||
|
// Refresh data that's needed in near realtime
|
||||||
|
dispatch('getOpenTrades');
|
||||||
|
dispatch('getState');
|
||||||
|
dispatch('getLocks');
|
||||||
|
},
|
||||||
|
|
||||||
[BotStoreActions.setDetailTrade]({ commit }, trade: Trade) {
|
[BotStoreActions.setDetailTrade]({ commit }, trade: Trade) {
|
||||||
commit('setDetailTrade', trade);
|
commit('setDetailTrade', trade);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user