frequi_origin/src/components/ftbot/TradeList.vue

84 lines
2.1 KiB
Vue
Raw Normal View History

2020-05-04 18:34:59 +00:00
<template>
<div class="card">
<div class="card-header">{{ title }}</div>
2020-05-08 05:14:55 +00:00
<div class="card-body">
2020-05-11 18:22:23 +00:00
<b-table
class="table-sm"
:items="trades"
:fields="table_fields"
@row-contextmenu="handleContextMenuEvent"
>
<template v-slot:cell(actions)="row">
<b-button size="sm" @click="forcesellHandler(row.item, row.index, $event.target)">
Forcesell
</b-button>
</template>
</b-table>
2020-05-08 05:14:55 +00:00
</div>
2020-05-04 18:56:11 +00:00
</div>
2020-05-04 18:34:59 +00:00
</template>
<script>
2020-05-11 18:22:23 +00:00
import { mapActions } from 'vuex';
2020-05-04 18:34:59 +00:00
export default {
name: 'TradeList',
props: {
trades: {
type: Array,
required: true,
},
2020-05-04 18:56:11 +00:00
title: {
type: String,
required: false,
default: 'Trades',
},
activeTrades: {
type: Boolean,
2020-05-06 19:20:33 +00:00
required: false,
default: false,
},
2020-05-04 18:34:59 +00:00
},
2020-05-11 05:05:14 +00:00
data() {
return {
table_fields: [
{ key: 'trade_id', label: 'ID' },
{ key: 'pair', label: 'Pair' },
{ key: 'amount', label: 'Amount' },
{ key: 'stake_amount', label: 'Stake amount' },
{ key: 'open_rate', label: 'Open rate' },
{
key: this.activeTrades ? 'current_rate' : 'close_rate',
label: this.activeTrades ? 'Current rate' : 'Close rate',
},
{
key: this.activeTrades ? 'current_profit' : 'close_profit',
label: this.activeTrades ? 'Current profit' : 'Profit',
formatter: 'formatPercent',
},
{ key: 'open_date', label: 'Open date' },
{ key: 'close_date', label: 'Close date' },
2020-05-11 18:22:23 +00:00
...(this.activeTrades ? [{ key: 'actions' }] : []),
2020-05-11 05:05:14 +00:00
],
};
},
methods: {
2020-05-11 18:22:23 +00:00
...mapActions('ftbot', ['forcesell']),
2020-05-11 05:05:14 +00:00
formatPercent(value) {
2020-05-24 07:15:04 +00:00
return `${(value * 100).toFixed(3)}%`;
2020-05-11 05:05:14 +00:00
},
2020-05-11 18:22:23 +00:00
forcesellHandler(item) {
this.forcesell(item.trade_id)
.then(() => console.log('asdf'))
2020-05-18 18:49:30 +00:00
.catch((error) => console.log(error.response));
2020-05-11 18:22:23 +00:00
},
handleContextMenuEvent(item, index, event) {
// stop browser context menu from appearing
event.preventDefault();
// log the selected item to the console
console.log(item);
},
2020-05-11 05:05:14 +00:00
},
2020-05-04 18:34:59 +00:00
};
</script>