frequi_origin/src/components/ftbot/CustomTradeList.vue

148 lines
4.4 KiB
Vue
Raw Normal View History

2021-12-22 05:44:09 +00:00
<template>
<div class="h-100 overflow-auto p-1">
<b-list-group id="tradeList">
2021-12-25 09:05:38 +00:00
<b-list-group-item
2021-12-25 18:50:00 +00:00
v-for="trade in filteredTrades"
2021-12-25 09:05:38 +00:00
:key="trade.trade_id"
class="border border-secondary rounded my-05 px-1"
2021-12-30 08:42:41 +00:00
@click="tradeClick(trade)"
2021-12-25 09:05:38 +00:00
>
2021-12-22 05:44:09 +00:00
<CustomTradeListEntry :trade="trade" :stake-currency-decimals="stakeCurrencyDecimals" />
</b-list-group-item>
</b-list-group>
2021-12-25 09:05:38 +00:00
<span v-if="trades.length == 0" class="mt-5">{{ emptyText }}</span>
<div class="w-100 d-flex justify-content-between mt-1">
2021-12-22 05:44:09 +00:00
<b-pagination
v-if="!activeTrades"
v-model="currentPage"
:total-rows="rows"
:per-page="perPage"
aria-controls="tradeList"
2021-12-22 05:44:09 +00:00
></b-pagination>
<b-input
v-if="showFilter"
v-model="filterText"
type="text"
placeholder="Filter"
size="sm"
style="width: unset"
/>
</div>
</div>
</template>
<script lang="ts">
2022-04-16 12:16:22 +00:00
import { formatPrice } from '@/shared/formatters';
2021-12-22 05:44:09 +00:00
import { MultiDeletePayload, MultiForcesellPayload, Trade } from '@/types';
import StoreModules from '@/store/storeSubModules';
import CustomTradeListEntry from '@/components/ftbot/CustomTradeListEntry.vue';
2022-04-16 12:16:22 +00:00
import { defineComponent, computed, ref } from '@vue/composition-api';
import { useNamespacedActions } from 'vuex-composition-helpers';
2021-12-22 05:44:09 +00:00
2022-04-16 12:16:22 +00:00
export default defineComponent({
name: 'CustomTradeList',
2021-12-22 05:44:09 +00:00
components: {
CustomTradeListEntry,
},
2022-04-16 12:16:22 +00:00
props: {
trades: { required: true, type: Array as () => 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 },
stakeCurrencyDecimals: { default: 3, type: Number },
},
setup(props, { root }) {
const { setDetailTrade, forceSellMulti, deleteTradeMulti } = useNamespacedActions(
StoreModules.ftbot,
['setDetailTrade', 'forceSellMulti', 'deleteTradeMulti'],
2021-12-25 18:50:00 +00:00
);
2022-04-16 12:16:22 +00:00
const currentPage = ref(1);
const filterText = ref('');
const perPage = props.activeTrades ? 200 : 25;
const rows = computed(() => props.trades.length);
const filteredTrades = computed(() => {
return props.trades.slice((currentPage.value - 1) * perPage, currentPage.value * perPage);
});
const formatPriceWithDecimals = (price) => {
return formatPrice(price, props.stakeCurrencyDecimals);
};
const forcesellHandler = (item: Trade, ordertype: string | undefined = undefined) => {
root.$bvModal
.msgBoxConfirm(`Really forcesell trade ${item.trade_id} (Pair ${item.pair})?`)
.then((value: boolean) => {
if (value) {
const payload: MultiForcesellPayload = {
tradeid: String(item.trade_id),
botId: item.botId,
};
if (ordertype) {
payload.ordertype = ordertype;
}
forceSellMulti(payload)
.then((xxx) => console.log(xxx))
.catch((error) => console.log(error.response));
2021-12-22 05:44:09 +00:00
}
2022-04-16 12:16:22 +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);
};
const removeTradeHandler = (item) => {
console.log(item);
root.$bvModal
.msgBoxConfirm(`Really delete trade ${item.trade_id} (Pair ${item.pair})?`)
.then((value: boolean) => {
if (value) {
const payload: MultiDeletePayload = {
tradeid: String(item.trade_id),
botId: item.botId,
};
deleteTradeMulti(payload).catch((error) => console.log(error.response));
}
});
};
const tradeClick = (trade) => {
setDetailTrade(trade);
};
return {
currentPage,
filterText,
perPage,
filteredTrades,
formatPriceWithDecimals,
forcesellHandler,
handleContextMenuEvent,
removeTradeHandler,
tradeClick,
setDetailTrade,
forceSellMulti,
deleteTradeMulti,
rows,
};
},
});
2021-12-22 05:44:09 +00:00
</script>
<style lang="scss" scoped>
2021-12-25 09:05:38 +00:00
.my-05 {
margin-top: 0.125rem;
margin-bottom: 0.125rem;
}
2021-12-22 05:44:09 +00:00
</style>