frequi_origin/src/components/ftbot/PairSummary.vue

117 lines
3.1 KiB
Vue
Raw Normal View History

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"
2020-10-31 08:40:40 +00:00
@click="setSelectedPair(comb.pair)"
>
<div>
{{ comb.pair }}
<span v-if="comb.locks" :title="comb.lockReason"> &#128274; </span>
</div>
<b-badge
2020-12-02 19:03:17 +00:00
:variant="comb.trade && comb.trade.profit_ratio > 0 ? 'success' : 'danger'"
2020-10-31 08:40:40 +00:00
pill
:title="comb.profitString"
>{{
2020-12-02 19:03:17 +00:00
comb.trade && comb.trade.profit_ratio ? formatPercent(comb.trade.profit_ratio) : ''
2020-10-31 08:40:40 +00:00
}}</b-badge
>
</b-list-group-item>
</b-list-group>
</template>
<script lang="ts">
import { formatPercent, timestampms } from '@/shared/formatters';
import { Lock, Trade } from '@/types';
import { Component, Prop, Vue } from 'vue-property-decorator';
2020-10-31 08:40:40 +00:00
import { namespace } from 'vuex-class';
const ftbot = namespace('ftbot');
interface CombinedPairList {
pair: string;
lockReason: string;
profitString: string;
trade?: Trade;
locks?: Lock;
}
@Component({})
export default class PairSummary extends Vue {
@Prop({ required: true }) pairlist!: string[];
2020-10-31 08:40:40 +00:00
@Prop({ required: true }) currentLocks!: Lock[];
2020-10-31 08:40:40 +00:00
@Prop({ required: true }) openTrades!: Trade[];
2020-10-31 08:40:40 +00:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@ftbot.Action setSelectedPair!: (pair: string) => void;
timestampms = timestampms;
formatPercent = formatPercent;
get combinedPairList() {
const comb: CombinedPairList[] = [];
this.pairlist.forEach((pair) => {
2020-10-31 08:40:40 +00:00
const trade = this.openTrades.find((el) => el.pair === pair);
2020-10-31 08:56:03 +00:00
const allLocks = this.currentLocks.filter((el) => el.pair === pair);
// 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:40:40 +00:00
let lockReason = '';
2020-10-31 08:56:03 +00:00
let locks;
if (allLocks.length > 0) {
[locks] = allLocks;
console.log(locks);
2020-10-31 08:40:40 +00:00
lockReason = `${timestampms(locks.lock_end_timestamp)} - ${locks.reason}`;
}
let profitString = '';
2020-12-02 19:03:17 +00:00
if (trade && trade.profit_ratio) {
profitString = `Current profit: ${formatPercent(trade.profit_ratio)}
2020-10-31 08:40:40 +00:00
Open since: ${timestampms(trade.open_timestamp)}`;
}
comb.push({ pair, trade, locks, lockReason, profitString });
});
// sort Pairs: "with open trade" -> available -> locked
comb.sort((a, b) => {
if (a.trade && !b.trade) {
return -1;
}
if (!a.locks && b.locks) {
return -1;
}
return 1;
});
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>