Add daily statistics

This commit is contained in:
Matthias 2020-05-17 20:43:19 +02:00
parent 7793faa798
commit 1fcd5117c9
5 changed files with 56 additions and 6 deletions

View File

@ -20,7 +20,7 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
export default { export default {
name: 'Balance', name: 'Balance',
@ -35,9 +35,13 @@ export default {
}, },
}, },
methods: { methods: {
...mapActions('ftbot', ['getBalance']),
formatCurrency(value) { formatCurrency(value) {
return value ? value.toFixed(5) : ''; return value ? value.toFixed(5) : '';
}, },
}, },
mounted() {
this.getBalance();
},
}; };
</script> </script>

30
src/ftbot/DailyStats.vue Normal file
View File

@ -0,0 +1,30 @@
<template>
<div>
<b-table class="table-sm" :items="dailyStats.data" :fields="daily_fields"> </b-table>
</div>
</template>
<script>
import { mapActions, mapState } from 'vuex';
export default {
name: 'DailyStats',
computed: {
...mapState('ftbot', ['dailyStats']),
daily_fields() {
return [
{ key: 'date', label: 'Day' },
{ key: 'abs_profit', label: 'Profit' },
{ key: 'fiat_value', label: `In ${this.dailyStats.fiat_display_currency}` },
{ key: 'trade_count', label: 'Trades' },
];
},
},
methods: {
...mapActions('ftbot', ['getDaily']),
},
mounted() {
this.getDaily();
},
};
</script>

View File

@ -16,9 +16,13 @@
<b-tab title="Performance"> <b-tab title="Performance">
<Performance class="performance-view" /> <Performance class="performance-view" />
</b-tab> </b-tab>
<b-tab title="Balance"> <b-tab title="Balance" lazy>
<Balance /> <Balance />
</b-tab> </b-tab>
<b-tab title="Daily Stats" lazy>
<DailyStats />
</b-tab>
<b-tab title="Whitelist"> </b-tab> <b-tab title="Whitelist"> </b-tab>
</b-tabs> </b-tabs>
</div> </div>
@ -54,10 +58,11 @@ import Performance from './Performance.vue';
import BotControls from './BotControls.vue'; import BotControls from './BotControls.vue';
import BotStatus from './BotStatus.vue'; import BotStatus from './BotStatus.vue';
import Balance from './Balance.vue'; import Balance from './Balance.vue';
import DailyStats from './DailyStats.vue';
export default { export default {
name: 'TradeView', name: 'TradeView',
components: { TradeList, Performance, BotControls, BotStatus, Balance }, components: { TradeList, Performance, BotControls, BotStatus, Balance, DailyStats },
created() { created() {
this.refreshAll(); this.refreshAll();
}, },

View File

@ -35,17 +35,19 @@ export default new Vuex.Store({
refreshAll({dispatch}) { refreshAll({dispatch}) {
dispatch('refreshFrequent'); dispatch('refreshFrequent');
dispatch('refreshSlow'); dispatch('refreshSlow');
dispatch('ftbot/getDaily');
dispatch('ftbot/getBalance');
}, },
refreshSlow({ dispatch }) { refreshSlow({ dispatch }) {
dispatch('ftbot/getBalance'); // dispatch('ftbot/getDaily');
dispatch('ftbot/getPerformance'); dispatch('ftbot/getPerformance');
dispatch('ftbot/getProfit'); dispatch('ftbot/getProfit');
}, },
refreshFrequent({dispatch}) { refreshFrequent({dispatch}) {
// Refresh all data // Refresh all data
dispatch('ftbot/getState');
dispatch('ftbot/getOpentrades'); dispatch('ftbot/getOpentrades');
dispatch('ftbot/getState');
dispatch('ftbot/getTrades'); dispatch('ftbot/getTrades');
dispatch('ftbot/getWhitelist'); dispatch('ftbot/getWhitelist');
dispatch('ftbot/getBlacklist'); dispatch('ftbot/getBlacklist');

View File

@ -11,7 +11,8 @@ export default {
blacklist: [], blacklist: [],
profit: {}, profit: {},
botState: {}, botState: {},
balance: {} balance: {},
dailyStats: [],
}, },
getters: { getters: {
openTrades(state) { openTrades(state) {
@ -42,6 +43,9 @@ export default {
updateProfit(state, profit) { updateProfit(state, profit) {
state.profit = profit; state.profit = profit;
}, },
updateDaily(state, daily) {
state.dailyStats = daily;
},
updateBalance(state, balance) { updateBalance(state, balance) {
state.balance = balance; state.balance = balance;
}, },
@ -86,6 +90,11 @@ export default {
.then((result) => commit('updateBalance', result.data)) .then((result) => commit('updateBalance', result.data))
.catch(console.error); .catch(console.error);
}, },
getDaily({ commit }) {
return api.get(`/daily`)
.then((result) => commit('updateDaily', result.data))
.catch(console.error);
},
getState({ commit }) { getState({ commit }) {
return api.get(`/show_config`) return api.get(`/show_config`)
.then((result) => commit('updateState', result.data)) .then((result) => commit('updateState', result.data))