frequi_origin/src/components/ftbot/BotComparisonList.vue

129 lines
4.3 KiB
Vue
Raw Normal View History

2021-09-03 14:55:39 +00:00
<template>
<b-table
ref="tradesTable"
small
hover
show-empty
primary-key="botId"
:items="tableItems"
:fields="tableFields"
>
<template #cell(profitOpen)="row">
2021-09-04 09:10:57 +00:00
<profit-pill
v-if="row.item.profitOpen && row.item.botId != 'Summary'"
:profit-ratio="row.item.profitOpenRatio"
:profit-abs="row.item.profitOpen"
2021-09-04 09:10:57 +00:00
:stake-currency="row.item.stakeCurrency"
/>
</template>
<template #cell(profitClosed)="row">
2021-09-04 09:10:57 +00:00
<profit-pill
v-if="row.item.profitClosed && row.item.botId != 'Summary'"
:profit-ratio="row.item.profitClosedRatio"
:profit-abs="row.item.profitClosed"
2021-09-04 09:10:57 +00:00
:stake-currency="row.item.stakeCurrency"
/>
</template>
2021-09-18 14:31:53 +00:00
<template #cell(balance)="row">
<div v-if="row.item.balance">
<span :title="row.item.stakeCurrency"
>{{ formatPrice(row.item.balance, row.item.stakeCurrencyDecimals) }}
</span>
<span clas="text-small">{{ row.item.stakeCurrency }}</span>
</div>
</template>
2021-09-04 09:20:55 +00:00
<template #cell(winVsLoss)="row">
<div v-if="row.item.losses !== undefined">
<span class="text-profit">{{ row.item.wins }}</span> /
<span class="text-loss">{{ row.item.losses }}</span>
</div>
</template>
2021-09-03 14:55:39 +00:00
</b-table>
</template>
<script lang="ts">
import { MultiBotStoreGetters } from '@/store/modules/botStoreWrapper';
import { BalanceInterface, BotDescriptors, BotState, ProfitInterface, Trade } from '@/types';
2021-09-03 14:55:39 +00:00
import { Component, Vue } from 'vue-property-decorator';
import { namespace } from 'vuex-class';
2021-09-04 09:10:57 +00:00
import ProfitPill from '@/components/general/ProfitPill.vue';
2021-09-18 14:31:53 +00:00
import { formatPrice } from '@/shared/formatters';
2021-09-03 14:55:39 +00:00
const ftbot = namespace('ftbot');
2021-09-04 09:10:57 +00:00
@Component({ components: { ProfitPill } })
2021-09-03 14:55:39 +00:00
export default class BotComparisonList extends Vue {
@ftbot.Getter [MultiBotStoreGetters.allProfit]!: Record<string, ProfitInterface>;
2021-09-03 15:27:20 +00:00
@ftbot.Getter [MultiBotStoreGetters.allOpenTradeCount]!: Record<string, number>;
@ftbot.Getter [MultiBotStoreGetters.allOpenTrades]!: Record<string, Trade[]>;
2021-09-03 15:27:20 +00:00
@ftbot.Getter [MultiBotStoreGetters.allBotState]!: Record<string, BotState>;
2021-09-18 14:31:53 +00:00
@ftbot.Getter [MultiBotStoreGetters.allBalance]!: Record<string, BalanceInterface>;
2021-09-03 14:55:39 +00:00
@ftbot.Getter [MultiBotStoreGetters.allAvailableBots]!: BotDescriptors;
2021-09-18 14:31:53 +00:00
formatPrice = formatPrice;
2021-09-03 14:55:39 +00:00
get tableItems() {
console.log('tableItems called');
2021-09-03 14:55:39 +00:00
const val: any[] = [];
2021-09-04 09:10:57 +00:00
const summary = {
botId: 'Summary',
profitClosed: 0,
profitClosedRatio: 0,
2021-09-04 09:10:57 +00:00
profitOpen: 0,
profitOpenRatio: 0,
2021-09-04 09:10:57 +00:00
stakeCurrency: 'USDT',
wins: 0,
losses: 0,
};
2021-09-03 14:55:39 +00:00
Object.entries(this.allProfit).forEach(([k, v]) => {
const allStakes = this.allOpenTrades[k].reduce((a, b) => a + b.stake_amount, 0);
const profitOpenRatio =
this.allOpenTrades[k].reduce((a, b) => a + b.profit_ratio * b.stake_amount, 0) / allStakes;
const profitOpen = this.allOpenTrades[k].reduce((a, b) => a + b.profit_abs, 0);
2021-09-03 14:55:39 +00:00
// TODO: handle one inactive bot ...
val.push({
botId: this.allAvailableBots[k].botName,
2021-09-04 09:20:55 +00:00
trades: `${this.allOpenTradeCount[k]} / ${this.allBotState[k]?.max_open_trades || 'N/A'}`,
2021-09-04 09:10:57 +00:00
profitClosed: v.profit_closed_coin,
profitClosedRatio: v.profit_closed_ratio || 0,
2021-09-04 09:10:57 +00:00
stakeCurrency: this.allBotState[k]?.stake_currency || '',
profitOpenRatio,
profitOpen,
2021-09-04 09:20:55 +00:00
wins: v.winning_trades,
losses: v.losing_trades,
2021-09-18 14:31:53 +00:00
balance: this.allBalance[k]?.total,
stakeCurrencyDecimals: this.allBotState[k]?.stake_currency_decimals || 3,
2021-09-03 14:55:39 +00:00
});
2021-09-03 15:27:20 +00:00
if (v.profit_closed_coin !== undefined) {
2021-09-04 09:10:57 +00:00
summary.profitClosed += v.profit_closed_coin;
summary.profitOpen += v.profit_all_coin;
summary.wins += v.winning_trades;
summary.losses += v.losing_trades;
// summary.decimals = this.allBotState[k]?.stake_currency_decimals || summary.decimals;
2021-09-03 15:27:20 +00:00
}
});
2021-09-04 09:10:57 +00:00
val.push(summary);
2021-09-03 14:55:39 +00:00
return val;
}
tableFields: Record<string, string | Function>[] = [
2021-09-03 15:27:20 +00:00
{ key: 'botId', label: 'Bot' },
{ key: 'trades', label: 'Trades' },
2021-09-04 09:10:57 +00:00
{ key: 'profitOpen', label: 'Open Profit' },
2021-09-03 14:55:39 +00:00
{ key: 'profitClosed', label: 'Closed Profit' },
2021-09-18 14:31:53 +00:00
{ key: 'balance', label: 'Balance' },
2021-09-03 14:55:39 +00:00
{ key: 'winVsLoss', label: 'W/L' },
];
}
</script>
<style scoped></style>