Add BotStoreActions enum

This commit is contained in:
Matthias 2021-08-28 17:35:48 +02:00
parent b2ba9638e2
commit b2f893b9ec

View File

@ -85,6 +85,45 @@ export enum BotStoreGetters {
selectedBacktestResultKey = 'selectedBacktestResultKey', selectedBacktestResultKey = 'selectedBacktestResultKey',
} }
export enum BotStoreActions {
ping = 'ping',
setDetailTrade = 'setDetailTrade',
setSelectedPair = 'setSelectedPair',
getTrades = 'getTrades',
getLocks = 'getLocks',
deleteLock = 'deleteLock',
getOpenTrades = 'getOpenTrades',
getPairCandles = 'getPairCandles',
getPairHistory = 'getPairHistory',
getStrategyPlotConfig = 'getStrategyPlotConfig',
setPlotConfigName = 'setPlotConfigName',
getStrategyList = 'getStrategyList',
getStrategy = 'getStrategy',
getAvailablePairs = 'getAvailablePairs',
getPerformance = 'getPerformance',
getWhitelist = 'getWhitelist',
getBlacklist = 'getBlacklist',
getProfit = 'getProfit',
getBalance = 'getBalance',
getDaily = 'getDaily',
getState = 'getState',
getVersion = 'getVersion',
getLogs = 'getLogs',
startBot = 'startBot',
stopBot = 'stopBot',
stopBuy = 'stopBuy',
reloadConfig = 'reloadConfig',
deleteTrade = 'deleteTrade',
startTrade = 'startTrade',
forcesell = 'forcesell',
forcebuy = 'forcebuy',
addBlacklist = 'addBlacklist',
startBacktest = 'startBacktest',
pollBacktest = 'pollBacktest',
removeBacktest = 'removeBacktest',
stopBacktest = 'stopBacktest',
}
export function createBotSubStore() { export function createBotSubStore() {
const { api } = useApi(userService); const { api } = useApi(userService);
@ -338,7 +377,7 @@ export function createBotSubStore() {
}, },
}, },
actions: { actions: {
ping({ commit, rootState }) { [BotStoreActions.ping]({ commit, rootState }) {
if (rootState.loggedIn) { if (rootState.loggedIn) {
api api
.get('/ping') .get('/ping')
@ -349,13 +388,13 @@ export function createBotSubStore() {
.catch(console.error); .catch(console.error);
} }
}, },
setDetailTrade({ commit }, trade: Trade) { [BotStoreActions.setDetailTrade]({ commit }, trade: Trade) {
commit('setDetailTrade', trade); commit('setDetailTrade', trade);
}, },
setSelectedPair({ commit }, pair: string) { [BotStoreActions.setSelectedPair]({ commit }, pair: string) {
commit('setSelectedPair', pair); commit('setSelectedPair', pair);
}, },
async getTrades({ commit }) { async [BotStoreActions.getTrades]({ commit }) {
try { try {
let totalTrades = 0; let totalTrades = 0;
const pageLength = 500; const pageLength = 500;
@ -388,13 +427,13 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
getLocks({ commit }) { [BotStoreActions.getLocks]({ commit }) {
return api return api
.get('/locks') .get('/locks')
.then((result) => commit('updateLocks', result.data)) .then((result) => commit('updateLocks', result.data))
.catch(console.error); .catch(console.error);
}, },
async deleteLock({ dispatch, commit }, lockid: string) { async [BotStoreActions.deleteLock]({ dispatch, commit }, lockid: string) {
try { try {
const res = await api.delete(`/locks/${lockid}`); const res = await api.delete(`/locks/${lockid}`);
showAlert( showAlert(
@ -411,7 +450,7 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
getOpenTrades({ commit, state }) { [BotStoreActions.getOpenTrades]({ commit, state }) {
return api return api
.get('/status') .get('/status')
.then((result) => { .then((result) => {
@ -433,7 +472,7 @@ export function createBotSubStore() {
}) })
.catch(console.error); .catch(console.error);
}, },
getPairCandles({ commit }, payload: PairCandlePayload) { [BotStoreActions.getPairCandles]({ commit }, payload: PairCandlePayload) {
if (payload.pair && payload.timeframe && payload.limit) { if (payload.pair && payload.timeframe && payload.limit) {
return api return api
.get('/pair_candles', { .get('/pair_candles', {
@ -455,7 +494,7 @@ export function createBotSubStore() {
reject(error); reject(error);
}); });
}, },
getPairHistory({ commit }, payload: PairHistoryPayload) { [BotStoreActions.getPairHistory]({ commit }, payload: PairHistoryPayload) {
if (payload.pair && payload.timeframe && payload.timerange) { if (payload.pair && payload.timeframe && payload.timerange) {
return api return api
.get('/pair_history', { .get('/pair_history', {
@ -479,7 +518,7 @@ export function createBotSubStore() {
reject(error); reject(error);
}); });
}, },
async getStrategyPlotConfig({ commit }) { async [BotStoreActions.getStrategyPlotConfig]({ commit }) {
try { try {
const result = await api.get('/plot_config'); const result = await api.get('/plot_config');
const plotConfig = result.data; const plotConfig = result.data;
@ -493,16 +532,16 @@ export function createBotSubStore() {
return console.error(data); return console.error(data);
} }
}, },
setPlotConfigName({ commit }, plotConfigName: string) { [BotStoreActions.setPlotConfigName]({ commit }, plotConfigName: string) {
commit('updatePlotConfigName', plotConfigName); commit('updatePlotConfigName', plotConfigName);
}, },
getStrategyList({ commit }) { [BotStoreActions.getStrategyList]({ commit }) {
return api return api
.get('/strategies') .get('/strategies')
.then((result) => commit('updateStrategyList', result.data)) .then((result) => commit('updateStrategyList', result.data))
.catch(console.error); .catch(console.error);
}, },
async getStrategy({ commit }, strategy: string) { async [BotStoreActions.getStrategy]({ commit }, strategy: string) {
try { try {
const result = await api.get(`/strategy/${strategy}`, {}); const result = await api.get(`/strategy/${strategy}`, {});
commit('updateStrategy', result.data); commit('updateStrategy', result.data);
@ -512,7 +551,7 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
async getAvailablePairs({ commit }, payload: AvailablePairPayload) { async [BotStoreActions.getAvailablePairs]({ commit }, payload: AvailablePairPayload) {
try { try {
const result = await api.get('/available_pairs', { const result = await api.get('/available_pairs', {
params: { ...payload }, params: { ...payload },
@ -526,7 +565,7 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
async getPerformance({ commit }) { async [BotStoreActions.getPerformance]({ commit }) {
try { try {
const result = await api.get('/performance'); const result = await api.get('/performance');
commit('updatePerformance', result.data); commit('updatePerformance', result.data);
@ -536,7 +575,7 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
getWhitelist({ commit }) { [BotStoreActions.getWhitelist]({ commit }) {
return api return api
.get('/whitelist') .get('/whitelist')
.then((result) => { .then((result) => {
@ -548,19 +587,19 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
}); });
}, },
getBlacklist({ commit }) { [BotStoreActions.getBlacklist]({ commit }) {
return api return api
.get('/blacklist') .get('/blacklist')
.then((result) => commit('updateBlacklist', result.data)) .then((result) => commit('updateBlacklist', result.data))
.catch(console.error); .catch(console.error);
}, },
getProfit({ commit }) { [BotStoreActions.getProfit]({ commit }) {
return api return api
.get('/profit') .get('/profit')
.then((result) => commit('updateProfit', result.data)) .then((result) => commit('updateProfit', result.data))
.catch(console.error); .catch(console.error);
}, },
async getBalance({ commit }) { async [BotStoreActions.getBalance]({ commit }) {
try { try {
const result = await api.get('/balance'); const result = await api.get('/balance');
return commit('updateBalance', result.data); return commit('updateBalance', result.data);
@ -568,26 +607,26 @@ export function createBotSubStore() {
return console.error(error); return console.error(error);
} }
}, },
getDaily({ commit }, payload: DailyPayload = {}) { [BotStoreActions.getDaily]({ commit }, payload: DailyPayload = {}) {
const { timescale = 20 } = payload; const { timescale = 20 } = payload;
return api return api
.get('/daily', { params: { timescale } }) .get('/daily', { params: { timescale } })
.then((result) => commit('updateDaily', result.data)) .then((result) => commit('updateDaily', result.data))
.catch(console.error); .catch(console.error);
}, },
getState({ commit }) { [BotStoreActions.getState]({ commit }) {
return api return api
.get('/show_config') .get('/show_config')
.then((result) => commit('updateState', result.data)) .then((result) => commit('updateState', result.data))
.catch(console.error); .catch(console.error);
}, },
getVersion({ commit }) { [BotStoreActions.getVersion]({ commit }) {
return api return api
.get('/version') .get('/version')
.then((result) => commit('updateVersion', result.data)) .then((result) => commit('updateVersion', result.data))
.catch(console.error); .catch(console.error);
}, },
getLogs({ commit }) { [BotStoreActions.getLogs]({ commit }) {
return api return api
.get('/logs') .get('/logs')
.then((result) => commit('updateLogs', result.data)) .then((result) => commit('updateLogs', result.data))
@ -595,7 +634,7 @@ export function createBotSubStore() {
}, },
// Post methods // Post methods
// TODO: Migrate calls to API to a seperate module unrelated to vuex? // TODO: Migrate calls to API to a seperate module unrelated to vuex?
async startBot({ dispatch }) { async [BotStoreActions.startBot]({ dispatch }) {
try { try {
const res = await api.post('/start', {}); const res = await api.post('/start', {});
console.log(res.data); console.log(res.data);
@ -609,7 +648,7 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
async stopBot({ dispatch }) { async [BotStoreActions.stopBot]({ dispatch }) {
try { try {
const res = await api.post('/stop', {}); const res = await api.post('/stop', {});
showAlert(dispatch, res.data.status); showAlert(dispatch, res.data.status);
@ -622,7 +661,7 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
async stopBuy({ dispatch }) { async [BotStoreActions.stopBuy]({ dispatch }) {
try { try {
const res = await api.post('/stopbuy', {}); const res = await api.post('/stopbuy', {});
showAlert(dispatch, res.data.status); showAlert(dispatch, res.data.status);
@ -635,7 +674,7 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
async reloadConfig({ dispatch }) { async [BotStoreActions.reloadConfig]({ dispatch }) {
try { try {
const res = await api.post('/reload_config', {}); const res = await api.post('/reload_config', {});
console.log(res.data); console.log(res.data);
@ -649,7 +688,7 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
async deleteTrade({ dispatch }, tradeid: string) { async [BotStoreActions.deleteTrade]({ dispatch }, tradeid: string) {
try { try {
const res = await api.delete(`/trades/${tradeid}`); const res = await api.delete(`/trades/${tradeid}`);
showAlert( showAlert(
@ -665,7 +704,7 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
async startTrade() { async [BotStoreActions.startTrade]() {
try { try {
const res = await api.post('/start_trade', {}); const res = await api.post('/start_trade', {});
return Promise.resolve(res); return Promise.resolve(res);
@ -673,7 +712,7 @@ export function createBotSubStore() {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
async forcesell({ dispatch }, tradeid: string) { async [BotStoreActions.forcesell]({ dispatch }, tradeid: string) {
if (tradeid) { if (tradeid) {
const payload = { tradeid }; const payload = { tradeid };
try { try {
@ -693,7 +732,7 @@ export function createBotSubStore() {
console.error(error); console.error(error);
return Promise.reject(error); return Promise.reject(error);
}, },
async forcebuy({ dispatch }, payload: ForcebuyPayload) { async [BotStoreActions.forcebuy]({ dispatch }, payload: ForcebuyPayload) {
if (payload && payload.pair) { if (payload && payload.pair) {
try { try {
const res = await api.post('/forcebuy', payload); const res = await api.post('/forcebuy', payload);
@ -717,7 +756,7 @@ export function createBotSubStore() {
console.error(error); console.error(error);
return Promise.reject(error); return Promise.reject(error);
}, },
async addBlacklist({ commit, dispatch }, payload: BlacklistPayload) { async [BotStoreActions.addBlacklist]({ commit, dispatch }, payload: BlacklistPayload) {
console.log(`Adding ${payload} to blacklist`); console.log(`Adding ${payload} to blacklist`);
if (payload && payload.blacklist) { if (payload && payload.blacklist) {
try { try {
@ -753,7 +792,7 @@ export function createBotSubStore() {
console.error(error); console.error(error);
return Promise.reject(error); return Promise.reject(error);
}, },
async startBacktest({ commit }, payload) { async [BotStoreActions.startBacktest]({ commit }, payload) {
try { try {
const result = await api.post('/backtest', payload); const result = await api.post('/backtest', payload);
commit('updateBacktestRunning', result.data); commit('updateBacktestRunning', result.data);
@ -761,14 +800,14 @@ export function createBotSubStore() {
console.log(err); console.log(err);
} }
}, },
async pollBacktest({ commit }) { async [BotStoreActions.pollBacktest]({ commit }) {
const result = await api.get('/backtest'); const result = await api.get('/backtest');
commit('updateBacktestRunning', result.data); commit('updateBacktestRunning', result.data);
if (result.data.running === false && result.data.backtest_result) { if (result.data.running === false && result.data.backtest_result) {
commit('updateBacktestResult', result.data.backtest_result); commit('updateBacktestResult', result.data.backtest_result);
} }
}, },
async removeBacktest({ commit }) { async [BotStoreActions.removeBacktest]({ commit }) {
commit('resetBacktestHistory'); commit('resetBacktestHistory');
try { try {
const result = await api.delete('/backtest'); const result = await api.delete('/backtest');
@ -778,7 +817,7 @@ export function createBotSubStore() {
return Promise.reject(err); return Promise.reject(err);
} }
}, },
async stopBacktest({ commit }) { async [BotStoreActions.stopBacktest]({ commit }) {
try { try {
const result = await api.get('/backtest/abort'); const result = await api.get('/backtest/abort');
commit('updateBacktestRunning', result.data); commit('updateBacktestRunning', result.data);