2020-05-04 18:34:59 +00:00
|
|
|
<template>
|
2020-09-01 05:51:03 +00:00
|
|
|
<div class="h-100 d-flex overflow-auto">
|
|
|
|
<div>
|
2020-05-11 18:22:23 +00:00
|
|
|
<b-table
|
2020-09-02 18:19:51 +00:00
|
|
|
ref="tradesTable"
|
2020-05-11 18:22:23 +00:00
|
|
|
class="table-sm"
|
|
|
|
:items="trades"
|
2020-06-04 18:06:58 +00:00
|
|
|
:fields="tableFields"
|
2020-05-27 18:24:57 +00:00
|
|
|
show-empty
|
2020-08-31 15:43:44 +00:00
|
|
|
:empty-text="emptyText"
|
2020-06-29 19:26:49 +00:00
|
|
|
:per-page="perPage"
|
|
|
|
:current-page="currentPage"
|
2020-09-02 18:19:51 +00:00
|
|
|
primary-key="trade_id"
|
2020-08-29 08:52:33 +00:00
|
|
|
selectable
|
|
|
|
select-mode="single"
|
2020-08-31 15:43:44 +00:00
|
|
|
@row-contextmenu="handleContextMenuEvent"
|
2020-09-02 18:19:51 +00:00
|
|
|
@row-clicked="onRowClicked"
|
2020-08-29 08:52:33 +00:00
|
|
|
@row-selected="onRowSelected"
|
2020-05-11 18:22:23 +00:00
|
|
|
>
|
2020-10-06 06:00:26 +00:00
|
|
|
<template #cell(actions)="row">
|
2020-09-12 14:39:52 +00:00
|
|
|
<b-button class="btn-xs" size="sm" title="Forcesell" @click="forcesellHandler(row.item)">
|
2020-12-28 09:55:42 +00:00
|
|
|
<ForceSellIcon :size="16" />
|
2020-09-12 14:39:52 +00:00
|
|
|
</b-button>
|
|
|
|
<b-button
|
2020-12-28 09:55:42 +00:00
|
|
|
class="btn-xs ml-1"
|
2020-09-12 14:39:52 +00:00
|
|
|
size="sm"
|
|
|
|
title="Delete trade"
|
|
|
|
@click="removeTradeHandler(row.item)"
|
|
|
|
>
|
2020-12-28 09:55:42 +00:00
|
|
|
<DeleteIcon :size="16" />
|
2020-08-29 15:31:45 +00:00
|
|
|
</b-button>
|
2020-05-11 18:22:23 +00:00
|
|
|
</template>
|
2020-10-06 06:00:26 +00:00
|
|
|
<template #cell(pair)="row">
|
2020-09-02 18:53:59 +00:00
|
|
|
<ProfitSymbol :trade="row.item" />
|
2020-05-31 11:13:19 +00:00
|
|
|
<span>
|
|
|
|
{{ row.item.pair }}
|
|
|
|
</span>
|
|
|
|
</template>
|
2020-05-11 18:22:23 +00:00
|
|
|
</b-table>
|
2020-06-29 19:26:49 +00:00
|
|
|
<b-pagination
|
|
|
|
v-if="!activeTrades"
|
|
|
|
v-model="currentPage"
|
|
|
|
:total-rows="rows"
|
|
|
|
:per-page="perPage"
|
|
|
|
aria-controls="my-table"
|
|
|
|
></b-pagination>
|
2020-09-01 05:51:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-05-04 18:34:59 +00:00
|
|
|
</template>
|
|
|
|
|
2020-06-29 19:14:16 +00:00
|
|
|
<script lang="ts">
|
2020-09-03 05:27:03 +00:00
|
|
|
import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
|
2020-06-29 19:14:16 +00:00
|
|
|
import { namespace } from 'vuex-class';
|
|
|
|
|
2020-06-29 19:29:09 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2020-09-03 05:11:24 +00:00
|
|
|
import { formatPercent, formatPrice } from '@/shared/formatters';
|
2020-08-29 09:23:39 +00:00
|
|
|
import { Trade } from '@/types';
|
2020-12-28 09:55:42 +00:00
|
|
|
import DeleteIcon from 'vue-material-design-icons/Delete.vue';
|
|
|
|
import ForceSellIcon from 'vue-material-design-icons/CloseBoxMultiple.vue';
|
2020-09-02 18:53:59 +00:00
|
|
|
import ProfitSymbol from './ProfitSymbol.vue';
|
2020-06-29 19:14:16 +00:00
|
|
|
|
|
|
|
const ftbot = namespace('ftbot');
|
|
|
|
|
2020-09-02 18:53:59 +00:00
|
|
|
@Component({
|
2020-12-28 09:55:42 +00:00
|
|
|
components: { ProfitSymbol, DeleteIcon, ForceSellIcon },
|
2020-09-02 18:53:59 +00:00
|
|
|
})
|
2020-06-29 19:14:16 +00:00
|
|
|
export default class TradeList extends Vue {
|
2020-09-02 18:53:59 +00:00
|
|
|
$refs!: {
|
|
|
|
tradesTable: HTMLFormElement;
|
|
|
|
};
|
|
|
|
|
2020-06-29 19:14:16 +00:00
|
|
|
@Prop({ required: true })
|
2020-06-29 19:26:49 +00:00
|
|
|
trades!: Array<Trade>;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
|
|
|
@Prop({ default: 'Trades' })
|
|
|
|
title!: string;
|
|
|
|
|
|
|
|
@Prop({ default: false })
|
|
|
|
activeTrades!: boolean;
|
|
|
|
|
|
|
|
@Prop({ default: 'No Trades to show.' })
|
2020-06-29 19:26:49 +00:00
|
|
|
emptyText!: string;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2020-09-02 18:19:51 +00:00
|
|
|
@ftbot.State detailTradeId?: number;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2020-09-02 18:19:51 +00:00
|
|
|
@ftbot.Action setDetailTrade;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2020-09-08 13:45:01 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2020-08-04 05:19:43 +00:00
|
|
|
@ftbot.Action forcesell!: (tradeid: string) => Promise<string>;
|
|
|
|
|
2020-09-08 13:45:01 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2020-08-04 05:19:43 +00:00
|
|
|
@ftbot.Action deleteTrade!: (tradeid: string) => Promise<string>;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2020-06-29 19:26:49 +00:00
|
|
|
currentPage = 1;
|
|
|
|
|
2020-09-02 18:19:51 +00:00
|
|
|
selectedItemIndex? = undefined;
|
|
|
|
|
2020-09-03 05:27:03 +00:00
|
|
|
@Watch('detailTradeId')
|
|
|
|
watchTradeDetail(val) {
|
|
|
|
const index = this.trades.findIndex((v) => v.trade_id === val);
|
|
|
|
// Unselect when another tradeTable is selected!
|
|
|
|
if (index < 0) {
|
|
|
|
this.$refs.tradesTable.clearSelected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 19:26:49 +00:00
|
|
|
get rows(): number {
|
|
|
|
return this.trades.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
perPage = this.activeTrades ? 200 : 15;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2020-09-03 15:22:52 +00:00
|
|
|
// Added to table-fields for current trades
|
|
|
|
openFields: Record<string, string | Function>[] = [{ key: 'actions' }];
|
|
|
|
|
|
|
|
// Added to table-fields for historic trades
|
2021-01-28 16:07:24 +00:00
|
|
|
closedFields: Record<string, string | Function>[] = [{ key: 'close_date', label: 'Close date' },{key: 'sell_reason', label: 'Close Reason'}];
|
2020-09-03 15:22:52 +00:00
|
|
|
|
2020-08-29 15:47:05 +00:00
|
|
|
tableFields: Record<string, string | Function>[] = [
|
2020-06-29 19:14:16 +00:00
|
|
|
{ key: 'trade_id', label: 'ID' },
|
|
|
|
{ key: 'pair', label: 'Pair' },
|
|
|
|
{ key: 'amount', label: 'Amount' },
|
|
|
|
{ key: 'stake_amount', label: 'Stake amount' },
|
2020-09-03 05:11:24 +00:00
|
|
|
{ key: 'open_rate', label: 'Open rate', formatter: (value) => formatPrice(value) },
|
2020-06-29 19:14:16 +00:00
|
|
|
{
|
|
|
|
key: this.activeTrades ? 'current_rate' : 'close_rate',
|
|
|
|
label: this.activeTrades ? 'Current rate' : 'Close rate',
|
2020-09-03 05:11:24 +00:00
|
|
|
formatter: (value) => formatPrice(value),
|
2020-05-11 18:22:23 +00:00
|
|
|
},
|
2020-06-29 19:14:16 +00:00
|
|
|
{
|
|
|
|
key: this.activeTrades ? 'current_profit' : 'close_profit',
|
2020-08-17 17:55:43 +00:00
|
|
|
label: this.activeTrades ? 'Current profit %' : 'Profit %',
|
2020-08-25 17:36:14 +00:00
|
|
|
formatter: (value) => formatPercent(value, 3),
|
2020-06-02 11:05:16 +00:00
|
|
|
},
|
2020-06-29 19:14:16 +00:00
|
|
|
{ key: 'open_date', label: 'Open date' },
|
2020-09-03 15:22:52 +00:00
|
|
|
...(this.activeTrades ? this.openFields : this.closedFields),
|
2020-06-29 19:14:16 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
forcesellHandler(item) {
|
2020-08-29 15:18:56 +00:00
|
|
|
this.$bvModal
|
|
|
|
.msgBoxConfirm(`Really forcesell trade ${item.trade_id} (Pair ${item.pair})?`)
|
|
|
|
.then((value: boolean) => {
|
|
|
|
if (value) {
|
|
|
|
this.forcesell(item.trade_id)
|
|
|
|
.then((xxx) => console.log(xxx))
|
|
|
|
.catch((error) => console.log(error.response));
|
|
|
|
}
|
|
|
|
});
|
2020-06-29 19:14:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleContextMenuEvent(item, index, event) {
|
|
|
|
// stop browser context menu from appearing
|
|
|
|
if (!this.activeTrades) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
// log the selected item to the console
|
|
|
|
console.log(item);
|
|
|
|
}
|
|
|
|
|
2020-08-04 06:00:11 +00:00
|
|
|
removeTradeHandler(item) {
|
2020-08-29 15:18:56 +00:00
|
|
|
console.log(item);
|
|
|
|
this.$bvModal
|
|
|
|
.msgBoxConfirm(`Really delete trade ${item.trade_id} (Pair ${item.pair})?`)
|
|
|
|
.then((value: boolean) => {
|
|
|
|
if (value) {
|
|
|
|
this.deleteTrade(item.trade_id).catch((error) => console.log(error.response));
|
|
|
|
}
|
|
|
|
});
|
2020-08-04 05:19:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-02 18:19:51 +00:00
|
|
|
onRowClicked(item, index) {
|
2020-08-29 08:52:33 +00:00
|
|
|
// Only allow single selection mode!
|
2020-09-02 18:19:51 +00:00
|
|
|
if (
|
|
|
|
item &&
|
|
|
|
item.trade_id !== this.detailTradeId &&
|
|
|
|
!this.$refs.tradesTable.isRowSelected(index)
|
|
|
|
) {
|
|
|
|
this.setDetailTrade(item);
|
2020-06-29 19:14:16 +00:00
|
|
|
} else {
|
2020-09-02 18:19:51 +00:00
|
|
|
console.log('unsetting item');
|
2020-08-29 08:52:33 +00:00
|
|
|
this.setDetailTrade(null);
|
2020-06-29 19:14:16 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-02 18:19:51 +00:00
|
|
|
|
2020-09-08 13:45:01 +00:00
|
|
|
onRowSelected() {
|
2020-09-02 18:19:51 +00:00
|
|
|
if (this.detailTradeId) {
|
|
|
|
const itemIndex = this.trades.findIndex((v) => v.trade_id === this.detailTradeId);
|
|
|
|
if (itemIndex >= 0) {
|
|
|
|
this.$refs.tradesTable.selectRow(itemIndex);
|
|
|
|
} else {
|
|
|
|
console.log(`Unsetting item for tradeid ${this.selectedItemIndex}`);
|
|
|
|
this.selectedItemIndex = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-29 19:14:16 +00:00
|
|
|
}
|
2020-05-04 18:34:59 +00:00
|
|
|
</script>
|
2020-05-31 11:13:19 +00:00
|
|
|
|
2020-09-04 15:04:09 +00:00
|
|
|
<style lang="scss" scoped>
|
2020-08-19 18:30:09 +00:00
|
|
|
.card-body {
|
|
|
|
padding: 0 0.2em;
|
2020-07-11 18:00:13 +00:00
|
|
|
}
|
2020-09-04 15:04:09 +00:00
|
|
|
.table-sm {
|
|
|
|
font-size: $fontsize-small;
|
|
|
|
}
|
2020-09-12 14:39:52 +00:00
|
|
|
.btn-xs {
|
|
|
|
padding: 0.1rem 0.25rem;
|
|
|
|
font-size: 0.75rem;
|
|
|
|
}
|
2020-05-31 11:13:19 +00:00
|
|
|
</style>
|