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"
|
2023-02-10 18:45:54 +00:00
|
|
|
:items="
|
|
|
|
trades.filter(
|
|
|
|
(t) =>
|
|
|
|
t.pair.toLowerCase().includes(filterText.toLowerCase()) ||
|
|
|
|
t.exit_reason?.toLowerCase().includes(filterText.toLowerCase()) ||
|
|
|
|
t.enter_tag?.toLowerCase().includes(filterText.toLowerCase()),
|
2023-04-06 05:17:29 +00:00
|
|
|
) as unknown as TableItem[]
|
2023-02-10 18:45:54 +00:00
|
|
|
"
|
2021-07-04 14:12:13 +00:00
|
|
|
: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
|
2023-01-25 06:32:47 +00:00
|
|
|
:select-head="false"
|
2021-07-04 14:12:13 +00:00
|
|
|
select-mode="single"
|
|
|
|
@row-contextmenu="handleContextMenuEvent"
|
|
|
|
@row-clicked="onRowClicked"
|
|
|
|
@row-selected="onRowSelected"
|
|
|
|
>
|
|
|
|
<template #cell(actions)="row">
|
2023-02-19 16:28:44 +00:00
|
|
|
<TradeActionsPopover
|
|
|
|
:id="row.index"
|
|
|
|
:trade="row.item"
|
|
|
|
:bot-api-version="botStore.activeBot.botApiVersion"
|
|
|
|
@deleteTrade="removeTradeHandler(row.item)"
|
|
|
|
@forceExit="forceExitHandler"
|
|
|
|
@forceExitPartial="forceExitPartialHandler"
|
|
|
|
@cancel-open-order="cancelOpenOrderHandler"
|
|
|
|
/>
|
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 }}
|
2022-04-09 08:43:46 +00:00
|
|
|
{{
|
2022-04-19 04:33:25 +00:00
|
|
|
botStore.activeBot.botApiVersion > 2.0 && row.item.trading_mode !== 'spot'
|
2022-04-09 08:43:46 +00:00
|
|
|
? '| ' + (row.item.is_short ? 'Short' : 'Long')
|
|
|
|
: ''
|
|
|
|
}}
|
2022-02-27 15:30:59 +00:00
|
|
|
</template>
|
2023-02-19 16:45:59 +00:00
|
|
|
<template #cell(stake_amount)="row">
|
|
|
|
{{ formatPriceWithDecimals(row.item.stake_amount) }}
|
|
|
|
{{ row.item.trading_mode !== 'spot' ? `(${row.item.leverage}x)` : '' }}
|
|
|
|
</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>
|
2022-11-18 16:10:06 +00:00
|
|
|
<b-form-input
|
2021-08-09 17:56:11 +00:00
|
|
|
v-if="showFilter"
|
|
|
|
v-model="filterText"
|
|
|
|
type="text"
|
|
|
|
placeholder="Filter"
|
|
|
|
size="sm"
|
|
|
|
style="width: unset"
|
|
|
|
/>
|
|
|
|
</div>
|
2022-11-19 13:39:46 +00:00
|
|
|
<force-exit-form v-if="activeTrades" v-model="forceExitVisible" :trade="feTrade" />
|
2023-01-31 06:11:34 +00:00
|
|
|
<b-modal v-model="removeTradeVisible" title="Exit trade" @ok="forceExitExecuter">
|
2022-11-20 08:01:13 +00:00
|
|
|
{{ confirmExitText }}
|
|
|
|
</b-modal>
|
2020-09-01 05:51:03 +00:00
|
|
|
</div>
|
2020-05-04 18:34:59 +00:00
|
|
|
</template>
|
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
<script setup lang="ts">
|
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-07-01 05:15:11 +00:00
|
|
|
import DateTimeTZ from '@/components/general/DateTimeTZ.vue';
|
2021-09-04 08:35:44 +00:00
|
|
|
import TradeProfit from './TradeProfit.vue';
|
2023-02-19 16:28:44 +00:00
|
|
|
import TradeActionsPopover from './TradeActionsPopover.vue';
|
2022-08-03 18:09:45 +00:00
|
|
|
import ForceExitForm from '@/components/ftbot/ForceExitForm.vue';
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
import { ref, computed, watch } from 'vue';
|
2022-04-19 04:33:25 +00:00
|
|
|
import { useBotStore } from '@/stores/ftbotwrapper';
|
2023-02-25 14:39:00 +00:00
|
|
|
import { useRouter } from 'vue-router';
|
2023-04-06 05:17:29 +00:00
|
|
|
import { TableField, TableItem } from 'bootstrap-vue-next';
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2023-01-31 06:11:34 +00:00
|
|
|
enum ModalReasons {
|
|
|
|
removeTrade,
|
|
|
|
forceExit,
|
|
|
|
forceExitPartial,
|
|
|
|
cancelOpenOrder,
|
|
|
|
}
|
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
const props = defineProps({
|
|
|
|
trades: { required: true, type: Array as () => Array<Trade> },
|
|
|
|
title: { default: 'Trades', type: String },
|
|
|
|
stakeCurrency: { required: false, default: '', type: String },
|
|
|
|
activeTrades: { default: false, type: Boolean },
|
|
|
|
showFilter: { default: false, type: Boolean },
|
|
|
|
multiBotView: { default: false, type: Boolean },
|
|
|
|
emptyText: { default: 'No Trades to show.', type: String },
|
|
|
|
});
|
|
|
|
const botStore = useBotStore();
|
2023-02-25 14:39:00 +00:00
|
|
|
const router = useRouter();
|
2023-01-30 19:08:59 +00:00
|
|
|
const currentPage = ref(1);
|
|
|
|
const selectedItemIndex = ref();
|
|
|
|
const filterText = ref('');
|
|
|
|
const feTrade = ref<Trade>({} as Trade);
|
|
|
|
const perPage = props.activeTrades ? 200 : 15;
|
|
|
|
const tradesTable = ref<HTMLFormElement>();
|
|
|
|
const forceExitVisible = ref(false);
|
|
|
|
const removeTradeVisible = ref(false);
|
|
|
|
const confirmExitText = ref('');
|
2023-01-31 06:11:34 +00:00
|
|
|
const confirmExitValue = ref<ModalReasons | null>(null);
|
2022-11-20 08:01:13 +00:00
|
|
|
|
2023-04-06 05:15:05 +00:00
|
|
|
const openFields: TableField[] = [{ key: 'actions' }];
|
|
|
|
const closedFields: TableField[] = [
|
2023-01-30 19:08:59 +00:00
|
|
|
{ key: 'close_timestamp', label: 'Close date' },
|
|
|
|
{ key: 'exit_reason', label: 'Close Reason' },
|
|
|
|
];
|
|
|
|
const formatPriceWithDecimals = (price) => {
|
|
|
|
return formatPrice(price, botStore.activeBot.stakeCurrencyDecimals);
|
|
|
|
};
|
|
|
|
const rows = computed(() => {
|
|
|
|
return props.trades.length;
|
|
|
|
});
|
2023-02-17 17:05:42 +00:00
|
|
|
|
2023-04-06 05:15:05 +00:00
|
|
|
const tableFields: TableField[] = [
|
|
|
|
props.multiBotView ? { key: 'botName', label: 'Bot' } : { key: 'actions' },
|
2023-01-30 19:08:59 +00:00
|
|
|
{ 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',
|
2023-04-06 05:15:05 +00:00
|
|
|
formatter: (value: unknown) => formatPrice(value as number),
|
2023-01-30 19:08:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: props.activeTrades ? 'current_rate' : 'close_rate',
|
|
|
|
label: props.activeTrades ? 'Current rate' : 'Close rate',
|
2023-04-06 05:15:05 +00:00
|
|
|
formatter: (value: unknown) => formatPrice(value as number),
|
2023-01-30 19:08:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'profit',
|
|
|
|
label: props.activeTrades ? 'Current profit %' : 'Profit %',
|
2023-04-06 05:15:05 +00:00
|
|
|
|
|
|
|
formatter: (value: unknown, key?: string, item?: unknown) => {
|
|
|
|
if (!item) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
const typedItem = item as Trade;
|
|
|
|
const percent = formatPercent(typedItem.profit_ratio, 2);
|
|
|
|
return `${percent} ${`(${formatPriceWithDecimals(typedItem.profit_abs)})`}`;
|
2023-01-30 19:08:59 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{ key: 'open_timestamp', label: 'Open date' },
|
|
|
|
...(props.activeTrades ? openFields : closedFields),
|
|
|
|
];
|
|
|
|
const feOrderType = ref<string | undefined>(undefined);
|
|
|
|
const forceExitHandler = (item: Trade, ordertype: string | undefined = undefined) => {
|
|
|
|
feTrade.value = item;
|
2023-01-31 06:11:34 +00:00
|
|
|
confirmExitValue.value = ModalReasons.forceExit;
|
2023-01-30 19:08:59 +00:00
|
|
|
confirmExitText.value = `Really exit trade ${item.trade_id} (Pair ${item.pair}) using ${ordertype} Order?`;
|
|
|
|
removeTradeVisible.value = true;
|
|
|
|
feOrderType.value = ordertype;
|
|
|
|
};
|
2022-11-20 08:01:13 +00:00
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
const forceExitExecuter = () => {
|
2023-01-31 06:11:34 +00:00
|
|
|
if (confirmExitValue.value === ModalReasons.removeTrade) {
|
2023-01-30 19:08:59 +00:00
|
|
|
const payload: MultiDeletePayload = {
|
|
|
|
tradeid: String(feTrade.value.trade_id),
|
|
|
|
botId: feTrade.value.botId,
|
2022-11-20 08:01:13 +00:00
|
|
|
};
|
2023-01-30 19:08:59 +00:00
|
|
|
botStore.deleteTradeMulti(payload).catch((error) => console.log(error.response));
|
|
|
|
}
|
2023-01-31 06:11:34 +00:00
|
|
|
if (confirmExitValue.value === ModalReasons.forceExit) {
|
|
|
|
const payload: MultiForcesellPayload = {
|
|
|
|
tradeid: String(feTrade.value.trade_id),
|
|
|
|
botId: feTrade.value.botId,
|
|
|
|
};
|
|
|
|
if (feOrderType.value) {
|
|
|
|
payload.ordertype = feOrderType.value;
|
|
|
|
}
|
|
|
|
botStore
|
|
|
|
.forceSellMulti(payload)
|
|
|
|
.then((xxx) => console.log(xxx))
|
|
|
|
.catch((error) => console.log(error.response));
|
2023-01-30 19:08:59 +00:00
|
|
|
}
|
2023-01-31 06:11:34 +00:00
|
|
|
if (confirmExitValue.value === ModalReasons.cancelOpenOrder) {
|
|
|
|
const payload: MultiDeletePayload = {
|
|
|
|
tradeid: String(feTrade.value.trade_id),
|
|
|
|
botId: feTrade.value.botId,
|
|
|
|
};
|
|
|
|
botStore.cancelOpenOrderMulti(payload);
|
|
|
|
}
|
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
feOrderType.value = undefined;
|
|
|
|
removeTradeVisible.value = false;
|
|
|
|
};
|
2020-06-29 19:14:16 +00:00
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
const removeTradeHandler = (item: Trade) => {
|
|
|
|
confirmExitText.value = `Really delete trade ${item.trade_id} (Pair ${item.pair})?`;
|
2023-01-31 06:11:34 +00:00
|
|
|
confirmExitValue.value = ModalReasons.removeTrade;
|
2023-01-30 19:08:59 +00:00
|
|
|
feTrade.value = item;
|
|
|
|
removeTradeVisible.value = true;
|
|
|
|
};
|
2022-08-03 18:09:45 +00:00
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
const forceExitPartialHandler = (item: Trade) => {
|
|
|
|
feTrade.value = item;
|
|
|
|
forceExitVisible.value = true;
|
|
|
|
};
|
2022-04-16 18:27:33 +00:00
|
|
|
|
2023-01-31 06:11:34 +00:00
|
|
|
const cancelOpenOrderHandler = (item: Trade) => {
|
|
|
|
confirmExitText.value = `Cancel open order for trade ${item.trade_id} (Pair ${item.pair})?`;
|
|
|
|
feTrade.value = item;
|
|
|
|
confirmExitValue.value = ModalReasons.cancelOpenOrder;
|
|
|
|
removeTradeVisible.value = true;
|
|
|
|
};
|
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
const handleContextMenuEvent = (item, index, event) => {
|
|
|
|
// stop browser context menu from appearing
|
|
|
|
if (!props.activeTrades) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
// log the selected item to the console
|
|
|
|
console.log(item);
|
|
|
|
};
|
2022-04-16 18:27:33 +00:00
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
const onRowClicked = (item) => {
|
2023-02-25 14:39:00 +00:00
|
|
|
if (props.multiBotView && botStore.selectedBot !== item.botId) {
|
|
|
|
// Multibotview - on click switch to the bot trade view
|
|
|
|
botStore.selectBot(item.botId);
|
|
|
|
}
|
2023-01-30 19:08:59 +00:00
|
|
|
if (item && item.trade_id !== botStore.activeBot.detailTradeId) {
|
|
|
|
botStore.activeBot.setDetailTrade(item);
|
2023-02-25 14:39:00 +00:00
|
|
|
if (props.multiBotView) {
|
|
|
|
router.push({ name: 'Freqtrade Trading' });
|
|
|
|
}
|
2023-01-30 19:08:59 +00:00
|
|
|
} else {
|
|
|
|
botStore.activeBot.setDetailTrade(null);
|
|
|
|
}
|
|
|
|
};
|
2020-09-02 18:19:51 +00:00
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
const onRowSelected = () => {
|
|
|
|
if (botStore.activeBot.detailTradeId) {
|
|
|
|
const itemIndex = props.trades.findIndex(
|
|
|
|
(v) => v.trade_id === botStore.activeBot.detailTradeId,
|
2022-04-19 04:33:25 +00:00
|
|
|
);
|
2023-01-30 19:08:59 +00:00
|
|
|
if (itemIndex >= 0) {
|
|
|
|
tradesTable.value?.selectRow(itemIndex);
|
|
|
|
} else {
|
|
|
|
console.log(`Unsetting item for tradeid ${selectedItemIndex.value}`);
|
|
|
|
selectedItemIndex.value = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-04-16 18:27:33 +00:00
|
|
|
|
2023-01-30 19:08:59 +00:00
|
|
|
watch(
|
|
|
|
() => botStore.activeBot.detailTradeId,
|
|
|
|
(val) => {
|
|
|
|
const index = props.trades.findIndex((v) => v.trade_id === val);
|
|
|
|
// Unselect when another tradeTable is selected!
|
|
|
|
if (index < 0) {
|
|
|
|
tradesTable.value?.clearSelected();
|
|
|
|
}
|
2022-04-16 18:27:33 +00:00
|
|
|
},
|
2023-01-30 19:08:59 +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>
|