ensure that open profit also updates in bot-comparison

closes #543
This commit is contained in:
Matthias 2021-10-28 19:33:08 +02:00
parent d3a5a737a4
commit 1554bc079a
3 changed files with 26 additions and 17 deletions

View File

@ -54,7 +54,7 @@ export default class DailyChart extends Vue {
return Number(
this.dailyStats.data.reduce(
(min, p) => (p.abs_profit < min ? p.abs_profit : min),
this.dailyStats.data[0].abs_profit,
this.dailyStats.data[0]?.abs_profit,
),
);
}
@ -63,7 +63,7 @@ export default class DailyChart extends Vue {
return Number(
this.dailyStats.data.reduce(
(max, p) => (p.abs_profit > max ? p.abs_profit : max),
this.dailyStats.data[0].abs_profit,
this.dailyStats.data[0]?.abs_profit,
),
);
}

View File

@ -8,22 +8,23 @@
:items="tableItems"
:fields="tableFields"
>
<template #cell(profitClosed)="row">
<profit-pill
v-if="row.item.profitClosed"
:profit-ratio="row.item.profitClosedRatio"
:profit-abs="row.item.profitClosed"
:stake-currency="row.item.stakeCurrency"
/>
</template>
<template #cell(profitOpen)="row">
<profit-pill
v-if="row.item.profitClosed"
v-if="row.item.profitOpen && row.item.botId != 'Summary'"
:profit-ratio="row.item.profitOpenRatio"
:profit-abs="row.item.profitOpen"
:stake-currency="row.item.stakeCurrency"
/>
</template>
<template #cell(profitClosed)="row">
<profit-pill
v-if="row.item.profitClosed && row.item.botId != 'Summary'"
:profit-ratio="row.item.profitClosedRatio"
:profit-abs="row.item.profitClosed"
:stake-currency="row.item.stakeCurrency"
/>
</template>
<template #cell(balance)="row">
<div v-if="row.item.balance">
<span :title="row.item.stakeCurrency"
@ -43,7 +44,7 @@
<script lang="ts">
import { MultiBotStoreGetters } from '@/store/modules/botStoreWrapper';
import { BalanceInterface, BotDescriptors, BotState, ProfitInterface } from '@/types';
import { BalanceInterface, BotDescriptors, BotState, ProfitInterface, Trade } from '@/types';
import { Component, Vue } from 'vue-property-decorator';
import { namespace } from 'vuex-class';
import ProfitPill from '@/components/general/ProfitPill.vue';
@ -57,6 +58,8 @@ export default class BotComparisonList extends Vue {
@ftbot.Getter [MultiBotStoreGetters.allOpenTradeCount]!: Record<string, number>;
@ftbot.Getter [MultiBotStoreGetters.allOpenTrades]!: Record<string, Trade[]>;
@ftbot.Getter [MultiBotStoreGetters.allBotState]!: Record<string, BotState>;
@ftbot.Getter [MultiBotStoreGetters.allBalance]!: Record<string, BalanceInterface>;
@ -66,19 +69,25 @@ export default class BotComparisonList extends Vue {
formatPrice = formatPrice;
get tableItems() {
console.log('tableItems called');
const val: any[] = [];
const summary = {
botId: 'Summary',
profitClosed: 0,
profitClosedRatio: undefined,
profitClosedRatio: 0,
profitOpen: 0,
profitOpenRatio: undefined,
profitOpenRatio: 0,
stakeCurrency: 'USDT',
wins: 0,
losses: 0,
};
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);
// TODO: handle one inactive bot ...
val.push({
botId: this.allAvailableBots[k].botName,
@ -86,8 +95,8 @@ export default class BotComparisonList extends Vue {
profitClosed: v.profit_closed_coin,
profitClosedRatio: v.profit_closed_ratio_sum || 0,
stakeCurrency: this.allBotState[k]?.stake_currency || '',
profitOpenRatio: v.profit_all_ratio_sum - v.profit_closed_ratio_sum,
profitOpen: v.profit_all_coin - v.profit_closed_coin,
profitOpenRatio,
profitOpen,
wins: v.winning_trades,
losses: v.losing_trades,
balance: this.allBalance[k]?.total,

View File

@ -100,7 +100,7 @@ import { GridLayout, GridItem, GridItemData } from 'vue-grid-layout';
import DailyChart from '@/components/charts/DailyChart.vue';
import CumProfitChart from '@/components/charts/CumProfitChart.vue';
import TradesLogChart from '@/components/charts/TradesLog.vue';
import BotComparisonList from '@/components/ftbot/BotComarisonList.vue';
import BotComparisonList from '@/components/ftbot/BotComparisonList.vue';
import TradeList from '@/components/ftbot/TradeList.vue';
import DraggableContainer from '@/components/layout/DraggableContainer.vue';