2020-05-18 18:49:30 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Vuex from 'vuex';
|
2020-05-04 04:31:12 +00:00
|
|
|
|
2020-07-19 13:45:44 +00:00
|
|
|
import userService from '@/shared/userService';
|
2020-05-04 18:58:41 +00:00
|
|
|
import ftbotModule from './modules/ftbot';
|
2020-05-11 18:22:23 +00:00
|
|
|
import alertsModule from './modules/alerts';
|
2020-08-18 06:29:40 +00:00
|
|
|
import layoutModule from './modules/layout';
|
2020-05-04 18:34:59 +00:00
|
|
|
|
2020-07-23 17:58:25 +00:00
|
|
|
const AUTO_REFRESH = 'ft_auto_refresh';
|
|
|
|
|
2020-05-18 18:49:30 +00:00
|
|
|
Vue.use(Vuex);
|
2020-05-04 04:31:12 +00:00
|
|
|
|
|
|
|
export default new Vuex.Store({
|
2020-06-20 04:44:57 +00:00
|
|
|
state: {
|
2020-06-20 14:55:33 +00:00
|
|
|
ping: '',
|
2020-07-19 13:12:06 +00:00
|
|
|
loggedIn: userService.loggedIn(),
|
2020-07-24 05:21:07 +00:00
|
|
|
autoRefresh: JSON.parse(localStorage.getItem(AUTO_REFRESH) || '{}'),
|
2020-07-26 09:10:56 +00:00
|
|
|
isBotOnline: false,
|
2020-06-20 04:44:57 +00:00
|
|
|
},
|
2020-05-04 05:28:53 +00:00
|
|
|
modules: {
|
2020-05-06 19:24:12 +00:00
|
|
|
ftbot: ftbotModule,
|
2020-05-11 18:22:23 +00:00
|
|
|
alerts: alertsModule,
|
2020-08-18 06:29:40 +00:00
|
|
|
layout: layoutModule,
|
2020-05-04 05:28:53 +00:00
|
|
|
},
|
2020-05-04 04:31:12 +00:00
|
|
|
mutations: {
|
2020-05-04 18:34:59 +00:00
|
|
|
setPing(state, ping) {
|
2020-06-20 04:44:57 +00:00
|
|
|
// console.log(ping);
|
|
|
|
const now = Date.now();
|
2020-05-18 18:49:30 +00:00
|
|
|
state.ping = `${ping.status} ${now.toString()}`;
|
|
|
|
},
|
2020-07-19 13:12:06 +00:00
|
|
|
setLoggedIn(state, loggedin: boolean) {
|
|
|
|
state.loggedIn = loggedin;
|
|
|
|
},
|
2020-07-23 17:58:25 +00:00
|
|
|
setAutoRefresh(state, newRefreshValue: boolean) {
|
|
|
|
state.autoRefresh = newRefreshValue;
|
|
|
|
},
|
2020-07-24 05:21:07 +00:00
|
|
|
setIsBotOnline(state, isBotOnline: boolean) {
|
|
|
|
state.isBotOnline = isBotOnline;
|
|
|
|
},
|
2020-05-04 04:31:12 +00:00
|
|
|
},
|
|
|
|
actions: {
|
2020-07-23 17:58:25 +00:00
|
|
|
setAutoRefresh({ commit }, newRefreshValue) {
|
|
|
|
commit('setAutoRefresh', newRefreshValue);
|
|
|
|
localStorage.setItem(AUTO_REFRESH, JSON.stringify(newRefreshValue));
|
|
|
|
},
|
2020-07-24 05:21:07 +00:00
|
|
|
setIsBotOnline({ commit, dispatch }, isOnline) {
|
|
|
|
commit('setIsBotOnline', isOnline);
|
|
|
|
if (isOnline === false) {
|
|
|
|
console.log('disabling autorun');
|
|
|
|
dispatch('setAutoRefresh', false);
|
|
|
|
}
|
|
|
|
},
|
2020-05-25 18:41:17 +00:00
|
|
|
refreshOnce({ dispatch }) {
|
|
|
|
dispatch('ftbot/getVersion');
|
|
|
|
},
|
2020-05-18 18:49:30 +00:00
|
|
|
refreshAll({ dispatch }) {
|
2020-05-14 16:34:45 +00:00
|
|
|
dispatch('refreshFrequent');
|
|
|
|
dispatch('refreshSlow');
|
2020-05-17 18:43:19 +00:00
|
|
|
dispatch('ftbot/getDaily');
|
|
|
|
dispatch('ftbot/getBalance');
|
2020-07-19 13:35:10 +00:00
|
|
|
dispatch('ftbot/getWhitelist');
|
|
|
|
dispatch('ftbot/getBlacklist');
|
2020-05-14 16:34:45 +00:00
|
|
|
},
|
|
|
|
refreshSlow({ dispatch }) {
|
2020-08-23 18:37:58 +00:00
|
|
|
// Refresh data that's needed "from time to time"
|
2020-05-17 18:43:19 +00:00
|
|
|
// dispatch('ftbot/getDaily');
|
2020-05-14 16:34:45 +00:00
|
|
|
dispatch('ftbot/getPerformance');
|
|
|
|
dispatch('ftbot/getProfit');
|
2020-08-23 18:37:58 +00:00
|
|
|
dispatch('ftbot/getTrades');
|
2020-05-14 16:34:45 +00:00
|
|
|
},
|
2020-05-18 18:49:30 +00:00
|
|
|
refreshFrequent({ dispatch }) {
|
2020-08-23 18:37:58 +00:00
|
|
|
// Refresh data that's needed in near realtime
|
2020-07-17 14:43:58 +00:00
|
|
|
dispatch('ftbot/getOpenTrades');
|
2020-05-17 18:43:19 +00:00
|
|
|
dispatch('ftbot/getState');
|
2020-05-14 16:34:45 +00:00
|
|
|
},
|
2020-05-18 18:49:30 +00:00
|
|
|
},
|
|
|
|
});
|