2020-10-31 08:40:40 +00:00
|
|
|
<template>
|
|
|
|
<!-- <b-table class="table-sm" :items="combinedPairList" :fields="tableFields"> </b-table> -->
|
|
|
|
|
|
|
|
<b-list-group>
|
|
|
|
<b-list-group-item
|
|
|
|
v-for="comb in combinedPairList"
|
|
|
|
:key="comb.pair"
|
|
|
|
button
|
2020-10-31 08:56:03 +00:00
|
|
|
class="d-flex justify-content-between align-items-center py-1"
|
2021-01-15 19:42:20 +00:00
|
|
|
:active="comb.pair === selectedPair"
|
2021-10-13 17:26:37 +00:00
|
|
|
:title="`${comb.pair} - ${comb.tradeCount} trades`"
|
2020-10-31 08:40:40 +00:00
|
|
|
@click="setSelectedPair(comb.pair)"
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
{{ comb.pair }}
|
|
|
|
<span v-if="comb.locks" :title="comb.lockReason"> 🔒 </span>
|
|
|
|
</div>
|
2021-10-11 18:58:13 +00:00
|
|
|
|
2021-10-13 17:26:37 +00:00
|
|
|
<TradeProfit v-if="comb.trade && !backtestMode" :trade="comb.trade" />
|
|
|
|
<ProfitPill v-if="backtestMode && comb.tradeCount > 0" :profit-ratio="comb.profit" />
|
2020-10-31 08:40:40 +00:00
|
|
|
</b-list-group-item>
|
|
|
|
</b-list-group>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { formatPercent, timestampms } from '@/shared/formatters';
|
2021-01-15 19:42:20 +00:00
|
|
|
import { BotStoreGetters } from '@/store/modules/ftbot';
|
2020-10-31 08:40:40 +00:00
|
|
|
import { Lock, Trade } from '@/types';
|
2020-12-05 16:06:26 +00:00
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
2020-10-31 08:40:40 +00:00
|
|
|
import { namespace } from 'vuex-class';
|
2021-09-04 08:35:44 +00:00
|
|
|
import TradeProfit from '@/components/ftbot/TradeProfit.vue';
|
2021-10-11 18:58:13 +00:00
|
|
|
import ProfitPill from '@/components/general/ProfitPill.vue';
|
2021-12-20 19:12:57 +00:00
|
|
|
import StoreModules from '@/store/storeSubModules';
|
2020-10-31 08:40:40 +00:00
|
|
|
|
2021-12-20 19:12:57 +00:00
|
|
|
const ftbot = namespace(StoreModules.ftbot);
|
2020-10-31 08:40:40 +00:00
|
|
|
|
|
|
|
interface CombinedPairList {
|
|
|
|
pair: string;
|
|
|
|
lockReason: string;
|
|
|
|
profitString: string;
|
|
|
|
trade?: Trade;
|
|
|
|
locks?: Lock;
|
2020-12-05 16:44:18 +00:00
|
|
|
profit: number;
|
2021-10-11 18:58:13 +00:00
|
|
|
profitAbs: number;
|
2021-10-13 17:26:37 +00:00
|
|
|
tradeCount: number;
|
2020-10-31 08:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 18:58:13 +00:00
|
|
|
@Component({ components: { TradeProfit, ProfitPill } })
|
2020-10-31 08:40:40 +00:00
|
|
|
export default class PairSummary extends Vue {
|
2020-12-05 16:06:26 +00:00
|
|
|
@Prop({ required: true }) pairlist!: string[];
|
2020-10-31 08:40:40 +00:00
|
|
|
|
2020-12-05 16:17:05 +00:00
|
|
|
@Prop({ required: false, default: () => [] }) currentLocks!: Lock[];
|
2020-10-31 08:40:40 +00:00
|
|
|
|
2020-12-05 16:17:39 +00:00
|
|
|
@Prop({ required: true }) trades!: Trade[];
|
2020-10-31 08:40:40 +00:00
|
|
|
|
2020-12-05 18:39:07 +00:00
|
|
|
/** Sort method, "normal" (sorts by open trades > pairlist -> locks) or "profit" */
|
|
|
|
@Prop({ required: false, default: 'normal' }) sortMethod!: string;
|
|
|
|
|
2021-10-13 17:26:37 +00:00
|
|
|
@Prop({ required: false, default: false }) backtestMode!: boolean;
|
|
|
|
|
2020-10-31 08:40:40 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
@ftbot.Action setSelectedPair!: (pair: string) => void;
|
|
|
|
|
2021-01-15 19:42:20 +00:00
|
|
|
@ftbot.Getter [BotStoreGetters.selectedPair]!: string;
|
|
|
|
|
2020-10-31 08:40:40 +00:00
|
|
|
timestampms = timestampms;
|
|
|
|
|
|
|
|
formatPercent = formatPercent;
|
|
|
|
|
|
|
|
get combinedPairList() {
|
|
|
|
const comb: CombinedPairList[] = [];
|
|
|
|
|
2020-12-05 16:06:26 +00:00
|
|
|
this.pairlist.forEach((pair) => {
|
2020-12-05 16:17:39 +00:00
|
|
|
const trades: Trade[] = this.trades.filter((el) => el.pair === pair);
|
2020-10-31 08:56:03 +00:00
|
|
|
const allLocks = this.currentLocks.filter((el) => el.pair === pair);
|
2020-10-31 08:40:40 +00:00
|
|
|
let lockReason = '';
|
2020-10-31 08:56:03 +00:00
|
|
|
let locks;
|
2020-12-05 16:14:42 +00:00
|
|
|
|
|
|
|
// Sort to have longer timeframe in front
|
|
|
|
allLocks.sort((a, b) => (a.lock_end_timestamp > b.lock_end_timestamp ? -1 : 1));
|
2020-10-31 08:56:03 +00:00
|
|
|
if (allLocks.length > 0) {
|
|
|
|
[locks] = allLocks;
|
2020-10-31 08:40:40 +00:00
|
|
|
lockReason = `${timestampms(locks.lock_end_timestamp)} - ${locks.reason}`;
|
|
|
|
}
|
|
|
|
let profitString = '';
|
2020-12-05 16:14:42 +00:00
|
|
|
let profit = 0;
|
2021-10-11 18:58:13 +00:00
|
|
|
let profitAbs = 0;
|
2020-12-05 16:14:42 +00:00
|
|
|
trades.forEach((trade) => {
|
|
|
|
profit += trade.profit_ratio;
|
2021-10-11 18:58:13 +00:00
|
|
|
profitAbs += trade.profit_abs;
|
2020-12-05 16:14:42 +00:00
|
|
|
});
|
2021-10-13 17:26:37 +00:00
|
|
|
const tradeCount = trades.length;
|
|
|
|
const trade = tradeCount ? trades[0] : undefined;
|
2020-12-05 16:14:42 +00:00
|
|
|
if (trades.length > 0) {
|
|
|
|
profitString = `Current profit: ${formatPercent(profit)}`;
|
|
|
|
}
|
|
|
|
if (trade) {
|
|
|
|
profitString += `\nOpen since: ${timestampms(trade.open_timestamp)}`;
|
2020-10-31 08:40:40 +00:00
|
|
|
}
|
2021-10-13 17:26:37 +00:00
|
|
|
comb.push({ pair, trade, locks, lockReason, profitString, profit, profitAbs, tradeCount });
|
2020-10-31 08:40:40 +00:00
|
|
|
});
|
2020-12-05 18:39:07 +00:00
|
|
|
if (this.sortMethod === 'profit') {
|
|
|
|
comb.sort((a, b) => {
|
|
|
|
if (a.profit > b.profit) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// sort Pairs: "with open trade" -> available -> locked
|
|
|
|
comb.sort((a, b) => {
|
|
|
|
if (a.trade && !b.trade) {
|
|
|
|
return -1;
|
|
|
|
}
|
2021-05-08 07:57:15 +00:00
|
|
|
if (a.trade && b.trade) {
|
|
|
|
// 2 open trade pairs
|
|
|
|
return a.trade.trade_id > b.trade.trade_id ? 1 : -1;
|
|
|
|
}
|
2020-12-05 18:39:07 +00:00
|
|
|
if (!a.locks && b.locks) {
|
|
|
|
return -1;
|
|
|
|
}
|
2021-05-08 07:57:15 +00:00
|
|
|
if (a.locks && b.locks) {
|
|
|
|
// Both have locks
|
|
|
|
return a.locks.lock_end_timestamp > b.locks.lock_end_timestamp ? 1 : -1;
|
|
|
|
}
|
2020-12-05 18:39:07 +00:00
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
}
|
2020-10-31 08:40:40 +00:00
|
|
|
return comb;
|
|
|
|
}
|
|
|
|
|
|
|
|
get tableFields() {
|
|
|
|
return [
|
|
|
|
{ key: 'pair', label: 'Pair' },
|
|
|
|
{
|
|
|
|
key: 'locks.lock_end_timestamp',
|
|
|
|
label: 'Lock',
|
|
|
|
formatter: (value) => (value ? `${timestampms(value)}` : ''),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'trade.current_profit',
|
|
|
|
label: 'Position',
|
|
|
|
formatter: (value) => formatPercent(value, 3),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.list-group {
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
</style>
|