Skip to content

Commit

Permalink
Properly handle Null values in profit responses
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Apr 29, 2022
1 parent 9e953ed commit c80ec9f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/components/ftbot/BotComparisonList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import ProfitPill from '@/components/general/ProfitPill.vue';
import { formatPrice } from '@/shared/formatters';
import { defineComponent, computed } from '@vue/composition-api';
import { useBotStore } from '@/stores/ftbotwrapper';
import { ProfitInterface } from '@/types';
export default defineComponent({
name: 'BotComparisonList',
Expand Down Expand Up @@ -77,12 +78,12 @@ export default defineComponent({
losses: 0,
};
Object.entries(botStore.allProfit).forEach(([k, v]: [k: string, v: any]) => {
Object.entries(botStore.allProfit).forEach(([k, v]: [k: string, v: ProfitInterface]) => {
const allStakes = botStore.allOpenTrades[k].reduce((a, b) => a + b.stake_amount, 0);
const profitOpenRatio =
botStore.allOpenTrades[k].reduce((a, b) => a + b.profit_ratio * b.stake_amount, 0) /
allStakes;
const profitOpen = botStore.allOpenTrades[k].reduce((a, b) => a + b.profit_abs, 0);
const profitOpen = botStore.allOpenTrades[k].reduce((a, b) => a + (b.profit_abs ?? 0), 0);
// TODO: handle one inactive bot ...
val.push({
Expand Down
2 changes: 1 addition & 1 deletion src/components/ftbot/PairSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default defineComponent({
let profitAbs = 0;
trades.forEach((trade) => {
profit += trade.profit_ratio;
profitAbs += trade.profit_abs;
profitAbs += trade.profit_abs ?? 0;
});
const tradeCount = trades.length;
const trade = tradeCount ? trades[0] : undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/formatters/numberformat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function formatPrice(value: number, decimals = 15): string {
useGrouping: false,
maximumFractionDigits: decimals,
})
: '';
: 'N/A';
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/stores/ftbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ export function createBotSubStore(botId: string, botName: string) {
botId,
botName,
botTradeId: `${botId}__${t.trade_id}`,
// eslint-disable-next-line @typescript-eslint/camelcase
profit_ratio: t.profit_ratio ?? -1,
}));
// TODO Don't force-patch profit_ratio but handle null values properly
this.openTrades = openTrades;
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/types/trades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export interface Trade {
/** Current profit as ratio */
profit_ratio: number;
/** Current profit in % */
profit_pct: number;
profit_pct: number | null;
/** Current absolute profit */
profit_abs: number;
profit_abs?: number;

/** @deprecated - replaced by exit reason 2.x */
sell_reason?: string;
Expand Down

0 comments on commit c80ec9f

Please sign in to comment.