Add trades list

This commit is contained in:
Matthias 2020-05-04 20:34:59 +02:00
parent 8eab68d3d5
commit 9a3cb7b618
7 changed files with 114 additions and 21 deletions

View File

@ -1,14 +1,15 @@
<template> <template>
<div id="app"> <div id="app">
<header class="bg-secondary"> <header class="bg-secondary">
<nav class="navbar navbar-expand navbar-dark flex-column flex-md-row bd-navbar"> <nav class="navbar navbar-expand navbar-dark flex-column flex-md-row bd-navbar">
<ul> <ul>
<li class="nav-item text-white"> <li class="nav-item text-white">
<img class="logo" src="./assets/freqtrade-logo.png" alt /> <img class="logo" src="./assets/freqtrade-logo.png" alt />
Freqtrade UI Freqtrade UI
</li> </li>
</ul> </ul>
</nav> </nav>
<div class="text-white">{{ ping }}</div>
</header> </header>
<main> <main>
<TradeView /> <TradeView />
@ -17,12 +18,17 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex';
import TradeView from './ftbot/TradeView.vue'; import TradeView from './ftbot/TradeView.vue';
export default { export default {
name: 'App', name: 'App',
components: { components: {
'TradeView': TradeView, TradeView,
},
computed: {
...mapState({ ping: 'ping' }),
}, },
}; };
</script> </script>
@ -36,7 +42,6 @@ export default {
color: #2c3e50; color: #2c3e50;
} }
main { main {
margin: 0 auto; margin: 0 auto;
/* padding: 30px; */ /* padding: 30px; */
@ -58,5 +63,4 @@ ul {
font-size: 22px; font-size: 22px;
/* border-right: 1px solid #bbb; */ /* border-right: 1px solid #bbb; */
} }
</style> </style>

40
src/ftbot/TradeList.vue Normal file
View File

@ -0,0 +1,40 @@
<template>
<table v-if="trades" class="table table-sm table-hover">
<thead>
<tr>
<th>Pair</th>
<th>Amount</th>
<th>Open rate</th>
<th>Current rate</th>
<th>Stake amount</th>
<th>Profit</th>
<th>Open date</th>
<th>Close date</th>
</tr>
</thead>
<tbody>
<tr v-for="(trade, index) in trades" :key="index">
<td>{{ trade.pair }}</td>
<td>{{ trade.amount }}</td>
<td>{{ trade.open_rate }}</td>
<td>{{ trade.current_rate }}</td>
<td>{{ trade.stake_amount }}</td>
<td>{{ trade.close_profit }}</td>
<td>{{ trade.open_date }}</td>
<td>{{ trade.close_date }}</td>
</tr>
</tbody>
</table>
</template>
<script>
export default {
name: 'TradeList',
props: {
trades: {
type: Array,
required: true,
},
},
};
</script>

View File

@ -1,15 +1,39 @@
<template> <template>
<div> <div class=".container-fluid">
TradeViewContent <div class="row">
<div class="col-sm">Top left</div>
<div class="col-sm">Performance</div>
</div>
<div class="row">
<div class="col-sm">Bottom left</div>
<div class="col-sm">Bottom right</div>
</div>
<div class="row">
<TradeList v-if="trades" :trades="trades" />
</div>
</div> </div>
</template> </template>
<script> <script>
import { mapActions, mapState } from 'vuex';
import TradeList from './TradeList.vue';
export default { export default {
name: 'TradeView', name: 'TradeView',
} components: { TradeList },
created() {
this.ping();
this.getTrades();
},
computed: {
...mapState('trades', ['trades']),
},
methods: {
...mapActions('trades', ['getTrades']),
...mapActions(['ping']),
},
};
</script> </script>
<style scoped> <style scoped></style>
</style>

View File

@ -1,18 +1,33 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import axios from 'axios';
import tradesModule from './modules/trades'; import tradesModule from './modules/trades';
import { apiBase } from './modules/config';
Vue.use(Vuex) Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
state: { state: {
ping: 'ddd',
}, },
modules: { modules: {
trades: tradesModule trades: tradesModule
}, },
mutations: { mutations: {
setPing(state, ping) {
console.log(ping);
const now = Date(Date.now());
state.ping = `${ping.status} ${now.toString()}` ;
}
}, },
actions: { actions: {
}, ping({ commit }) {
axios.get(`${apiBase}/ping`)
.then((result) => commit('setPing', result.data))
.catch(console.error);
}
}
}) })

View File

@ -1,5 +1,11 @@
const apiBase = '/api/v1/' const apiBase = '/api/v1'
const apiAuth = {auth: {
export default { username: 'xxxx',
apiBase, password: 'xxxx!',
}
}
module.exports = {
apiBase, apiAuth
} }

View File

@ -1,21 +1,25 @@
import axios from 'axios'; import axios from 'axios';
const apiBase = require('./config.js') import { apiBase, apiAuth } from './config';
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
trades: [], trades: [],
trade_count: 0,
}, },
mutations: { mutations: {
updateTrades(state, trades) { updateTrades(state, trades) {
state.trades = trades; state.trades = trades.trades;
state.trade_count = trades.trade_count;
} }
}, },
actions: { actions: {
getTrades({ commit }) { getTrades({ commit }) {
axios.get(`${apiBase}/trades`) axios.get(`${apiBase}/trades`, {
...apiAuth
})
.then((result) => commit('updateTrades', result.data)) .then((result) => commit('updateTrades', result.data))
.catch(console.error); .catch(console.error);
} }

View File

@ -2,7 +2,7 @@ module.exports = {
devServer: { devServer: {
proxy: { proxy: {
'/api': { '/api': {
target: 'http://localhost:8081', target: 'http://127.0.0.1:8081',
changeOrigin: true, changeOrigin: true,
}, },
}, },