2020-05-04 18:34:59 +00:00
|
|
|
<template>
|
2021-07-11 18:43:19 +00:00
|
|
|
<div class="h-100 overflow-auto w-100">
|
2021-07-04 14:12:13 +00:00
|
|
|
<b-table
|
|
|
|
ref="tradesTable"
|
|
|
|
small
|
|
|
|
hover
|
2021-07-17 15:31:01 +00:00
|
|
|
stacked="md"
|
2021-07-04 14:12:13 +00:00
|
|
|
:items="trades"
|
|
|
|
:fields="tableFields"
|
|
|
|
show-empty
|
|
|
|
:empty-text="emptyText"
|
|
|
|
:per-page="perPage"
|
|
|
|
:current-page="currentPage"
|
2021-09-18 08:40:53 +00:00
|
|
|
primary-key="botTradeId"
|
2021-07-04 14:12:13 +00:00
|
|
|
selectable
|
|
|
|
select-mode="single"
|
2021-08-09 17:56:11 +00:00
|
|
|
:filter="filterText"
|
2021-07-04 14:12:13 +00:00
|
|
|
@row-contextmenu="handleContextMenuEvent"
|
|
|
|
@row-clicked="onRowClicked"
|
|
|
|
@row-selected="onRowSelected"
|
|
|
|
>
|
|
|
|
<template #cell(actions)="row">
|
2021-11-27 08:15:21 +00:00
|
|
|
<b-button :id="`btn-actions_${row.index}`" class="btn-xs" size="sm" title="Actions">
|
|
|
|
<ActionIcon :size="16" title="Actions" />
|
2021-07-04 14:12:13 +00:00
|
|
|
</b-button>
|
2021-11-27 08:15:21 +00:00
|
|
|
<b-popover :target="`btn-actions_${row.index}`" triggers="focus" placement="left">
|
2021-12-25 10:21:00 +00:00
|
|
|
<trade-actions
|
|
|
|
:trade="row.item"
|
|
|
|
:bot-api-version="botApiVersion"
|
|
|
|
@deleteTrade="removeTradeHandler"
|
|
|
|
@forceSell="forcesellHandler"
|
|
|
|
/>
|
2021-11-27 08:15:21 +00:00
|
|
|
</b-popover>
|
2021-07-04 14:12:13 +00:00
|
|
|
</template>
|
|
|
|
<template #cell(pair)="row">
|
|
|
|
<span>
|
2021-07-04 17:57:35 +00:00
|
|
|
{{
|
|
|
|
`${row.item.pair}${
|
|
|
|
row.item.open_order_id === undefined || row.item.open_order_id === null ? '' : '*'
|
|
|
|
}`
|
|
|
|
}}
|
2021-07-04 14:12:13 +00:00
|
|
|
</span>
|
|
|
|
</template>
|
2022-02-27 15:30:59 +00:00
|
|
|
<template #cell(trade_id)="row">
|
|
|
|
{{ row.item.trade_id }}
|
|
|
|
{{ botApiVersion > 2.0 ? '| ' + (row.item.is_short ? 'Short' : 'Long') : '' }}
|
|
|
|
</template>
|
2021-07-17 15:14:20 +00:00
|
|
|
<template #cell(profit)="row">
|
2021-09-04 08:35:44 +00:00
|
|
|
<trade-profit :trade="row.item" />
|
2021-07-17 15:14:20 +00:00
|
|
|
</template>
|
2021-07-04 14:12:13 +00:00
|
|
|
<template #cell(open_timestamp)="row">
|
|
|
|
<DateTimeTZ :date="row.item.open_timestamp" />
|
|
|
|
</template>
|
|
|
|
<template #cell(close_timestamp)="row">
|
|
|
|
<DateTimeTZ :date="row.item.close_timestamp" />
|
|
|
|
</template>
|
|
|
|
</b-table>
|
2021-08-09 17:56:11 +00:00
|
|
|
<div class="w-100 d-flex justify-content-between">
|
|
|
|
<b-pagination
|
|
|
|
v-if="!activeTrades"
|
|
|
|
v-model="currentPage"
|
|
|
|
:total-rows="rows"
|
|
|
|
:per-page="perPage"
|
|
|
|
aria-controls="my-table"
|
|
|
|
></b-pagination>
|
|
|
|
<b-input
|
|
|
|
v-if="showFilter"
|
|
|
|
v-model="filterText"
|
|
|
|
type="text"
|
|
|
|
placeholder="Filter"
|
|
|
|
size="sm"
|
|
|
|
style="width: unset"
|
|
|
|
/>
|
|
|
|
</div>
|
2020-09-01 05:51:03 +00:00
|
|
|
</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
|
2021-07-01 05:15:11 +00:00
|
|
|
import { formatPercent, formatPrice } from '@/shared/formatters';
|
2021-11-26 06:00:09 +00:00
|
|
|
import { MultiDeletePayload, MultiForcesellPayload, Trade } from '@/types';
|
2021-11-27 08:15:21 +00:00
|
|
|
import ActionIcon from 'vue-material-design-icons/GestureTap.vue';
|
2021-07-01 05:15:11 +00:00
|
|
|
import DateTimeTZ from '@/components/general/DateTimeTZ.vue';
|
2021-07-17 14:00:15 +00:00
|
|
|
import { BotStoreGetters } from '@/store/modules/ftbot';
|
2021-12-20 19:12:57 +00:00
|
|
|
import StoreModules from '@/store/storeSubModules';
|
2021-09-04 08:35:44 +00:00
|
|
|
import TradeProfit from './TradeProfit.vue';
|
2021-12-25 10:21:00 +00:00
|
|
|
import TradeActions from './TradeActions.vue';
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2021-12-20 19:12:57 +00:00
|
|
|
const ftbot = namespace(StoreModules.ftbot);
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2020-09-02 18:53:59 +00:00
|
|
|
@Component({
|
2022-01-22 12:04:12 +00:00
|
|
|
components: { ActionIcon, DateTimeTZ, TradeProfit, TradeActions },
|
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;
|
|
|
|
};
|
|
|
|
|
2021-07-17 15:14:20 +00:00
|
|
|
formatPercent = formatPercent;
|
|
|
|
|
|
|
|
formatPrice = formatPrice;
|
|
|
|
|
|
|
|
@Prop({ required: true }) trades!: Array<Trade>;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2021-07-17 15:14:20 +00:00
|
|
|
@Prop({ default: 'Trades' }) title!: string;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2021-07-17 15:14:20 +00:00
|
|
|
@Prop({ required: false, default: '' }) stakeCurrency!: string;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2021-07-17 15:14:20 +00:00
|
|
|
@Prop({ default: false }) activeTrades!: boolean;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2021-08-09 17:56:11 +00:00
|
|
|
@Prop({ default: false }) showFilter!: boolean;
|
|
|
|
|
2021-09-18 18:00:48 +00:00
|
|
|
@Prop({ default: false, type: Boolean }) multiBotView!: boolean;
|
|
|
|
|
2021-07-17 15:14:20 +00:00
|
|
|
@Prop({ default: 'No Trades to show.' }) emptyText!: string;
|
2020-08-08 18:22:05 +00:00
|
|
|
|
2021-08-28 09:39:03 +00:00
|
|
|
@ftbot.Getter [BotStoreGetters.detailTradeId]?: number;
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2021-07-17 14:00:15 +00:00
|
|
|
@ftbot.Getter [BotStoreGetters.stakeCurrencyDecimals]!: number;
|
|
|
|
|
2021-11-27 08:15:21 +00:00
|
|
|
@ftbot.Getter [BotStoreGetters.botApiVersion]: number;
|
|
|
|
|
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
|
2021-11-26 06:00:09 +00:00
|
|
|
@ftbot.Action forceSellMulti!: (payload: MultiForcesellPayload) => Promise<string>;
|
2020-08-04 05:19:43 +00:00
|
|
|
|
2020-09-08 13:45:01 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2021-11-26 06:00:09 +00:00
|
|
|
@ftbot.Action deleteTradeMulti!: (payload: MultiDeletePayload) => 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;
|
|
|
|
|
2021-08-09 17:56:11 +00:00
|
|
|
filterText = '';
|
|
|
|
|
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-02-04 18:35:28 +00:00
|
|
|
closedFields: Record<string, string | Function>[] = [
|
2021-07-01 05:15:11 +00:00
|
|
|
{ key: 'close_timestamp', label: 'Close date' },
|
2022-04-06 18:46:17 +00:00
|
|
|
{ key: 'exit_reason', label: 'Close Reason' },
|
2021-02-04 18:35:28 +00:00
|
|
|
];
|
2020-09-03 15:22:52 +00:00
|
|
|
|
2020-08-29 15:47:05 +00:00
|
|
|
tableFields: Record<string, string | Function>[] = [
|
2021-09-18 18:00:48 +00:00
|
|
|
this.multiBotView ? { key: 'botName', label: 'Bot' } : {},
|
2020-06-29 19:14:16 +00:00
|
|
|
{ key: 'trade_id', label: 'ID' },
|
|
|
|
{ key: 'pair', label: 'Pair' },
|
|
|
|
{ key: 'amount', label: 'Amount' },
|
2021-07-30 18:34:12 +00:00
|
|
|
{
|
|
|
|
key: 'stake_amount',
|
|
|
|
label: 'Stake amount',
|
|
|
|
formatter: (value: number) => this.formatPriceWithDecimals(value),
|
|
|
|
},
|
2021-07-17 15:31:01 +00:00
|
|
|
{
|
|
|
|
key: 'open_rate',
|
|
|
|
label: 'Open rate',
|
2021-09-04 14:44:48 +00:00
|
|
|
formatter: (value: number) => this.formatPrice(value),
|
2021-07-17 15:31:01 +00:00
|
|
|
},
|
2020-06-29 19:14:16 +00:00
|
|
|
{
|
|
|
|
key: this.activeTrades ? 'current_rate' : 'close_rate',
|
|
|
|
label: this.activeTrades ? 'Current rate' : 'Close rate',
|
2021-09-04 14:44:48 +00:00
|
|
|
formatter: (value: number) => this.formatPrice(value),
|
2020-05-11 18:22:23 +00:00
|
|
|
},
|
2020-06-29 19:14:16 +00:00
|
|
|
{
|
2021-07-17 15:14:20 +00:00
|
|
|
key: 'profit',
|
2020-08-17 17:55:43 +00:00
|
|
|
label: this.activeTrades ? 'Current profit %' : 'Profit %',
|
2021-07-17 15:31:01 +00:00
|
|
|
formatter: (value: number, key, item: Trade) => {
|
2021-07-17 15:05:17 +00:00
|
|
|
const percent = formatPercent(item.profit_ratio, 2);
|
|
|
|
return `${percent} ${`(${this.formatPriceWithDecimals(item.profit_abs)})`}`;
|
2021-07-17 14:00:15 +00:00
|
|
|
},
|
2020-06-02 11:05:16 +00:00
|
|
|
},
|
2021-07-01 05:15:11 +00:00
|
|
|
{ key: 'open_timestamp', 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
|
|
|
];
|
|
|
|
|
2021-07-17 14:00:15 +00:00
|
|
|
formatPriceWithDecimals(price) {
|
|
|
|
return formatPrice(price, this.stakeCurrencyDecimals);
|
|
|
|
}
|
|
|
|
|
2021-12-26 15:04:19 +00:00
|
|
|
forcesellHandler(item: Trade, ordertype: string | undefined = undefined) {
|
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) {
|
2021-11-26 06:00:09 +00:00
|
|
|
const payload: MultiForcesellPayload = {
|
|
|
|
tradeid: String(item.trade_id),
|
|
|
|
botId: item.botId,
|
|
|
|
};
|
2021-11-27 08:15:21 +00:00
|
|
|
if (ordertype) {
|
|
|
|
payload.ordertype = ordertype;
|
|
|
|
}
|
2021-11-26 06:00:09 +00:00
|
|
|
this.forceSellMulti(payload)
|
2020-08-29 15:18:56 +00:00
|
|
|
.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) {
|
2021-11-26 06:00:09 +00:00
|
|
|
const payload: MultiDeletePayload = {
|
|
|
|
tradeid: String(item.trade_id),
|
|
|
|
botId: item.botId,
|
|
|
|
};
|
|
|
|
this.deleteTradeMulti(payload).catch((error) => console.log(error.response));
|
2020-08-29 15:18:56 +00:00
|
|
|
}
|
|
|
|
});
|
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>
|