Add balance view

This commit is contained in:
Matthias 2020-05-14 07:15:18 +02:00
parent 8f26cff24b
commit 5fdad10b83
4 changed files with 55 additions and 1 deletions

38
src/ftbot/Balance.vue Normal file
View File

@ -0,0 +1,38 @@
<template>
<div class="card">
<div class="card-header">Balance</div>
<div class="card-body">
<b-table class="table-sm" :items="balance.currencies" :fields="table_fields">
<template slot="bottom-row">
<td>Total</td>
<td></td>
<!-- this is a computed prop that adds up all the expenses in the visible rows -->
<td>{{ formatCurrency(balance.total) }}</td>
</template>
</b-table>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex';
export default {
name: 'Balance',
computed: {
...mapState('ftbot', ['balance']),
table_fields() {
return [
{ key: 'currency', label: 'Currency' },
{ key: 'free', label: 'Available', formatter: 'formatCurrency' },
{ key: 'est_stake', label: `in ${this.balance.stake}`, formatter: 'formatCurrency' },
];
},
},
methods: {
formatCurrency(value) {
return value.toFixed(5);
},
},
};
</script>

View File

@ -32,6 +32,9 @@
<b-tab title="Status">
<BotStatus />
</b-tab>
<b-tab title="Balance">
<Balance />
</b-tab>
<b-tab title="Whitelist"> </b-tab>
</b-tabs>
</div>
@ -49,10 +52,11 @@ import TradeList from './TradeList.vue';
import Performance from './Performance.vue';
import BotControls from './BotControls.vue';
import BotStatus from './BotStatus.vue';
import Balance from './Balance.vue';
export default {
name: 'TradeView',
components: { TradeList, Performance, BotControls, BotStatus },
components: { TradeList, Performance, BotControls, BotStatus, Balance },
created() {
this.getTrades();
this.getProfit();

View File

@ -41,6 +41,7 @@ export default new Vuex.Store({
dispatch('ftbot/getWhitelist');
dispatch('ftbot/getBlacklist');
dispatch('ftbot/getProfit');
dispatch('ftbot/getBalance');
}
}
})

View File

@ -13,6 +13,7 @@ export default {
blacklist: [],
profit: {},
botState: {},
balance: {}
},
getters: {
apiAuth(state, getters, rootState, rootGetters) {
@ -46,6 +47,9 @@ export default {
updateProfit(state, profit) {
state.profit = profit;
},
updateBalance(state, balance) {
state.balance = balance;
},
updateState(state, botState) {
state.botState = botState;
},
@ -93,6 +97,13 @@ export default {
.then((result) => commit('updateProfit', result.data))
.catch(console.error);
},
getBalance({ commit, getters }) {
return axios.get(`${apiBase}/balance`, {
...getters.apiAuth
})
.then((result) => commit('updateBalance', result.data))
.catch(console.error);
},
getState({ commit, getters, dispatch }) {
return axios.get(`${apiBase}/show_config`, {
...getters.apiAuth