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