mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-26 21:15:15 +00:00
Extract stake_currency logic from tooltip functions
This commit is contained in:
parent
46261f5cc6
commit
43dd865ad4
|
@ -3,30 +3,35 @@ import { roundTimeframe } from '@/shared/timemath';
|
|||
import { Order, PairHistory, Trade, BTOrder } from '@/types';
|
||||
import { ScatterSeriesOption } from 'echarts';
|
||||
|
||||
function buildTooltipCost(trade: Trade, order: Order | BTOrder): string {
|
||||
function buildTooltipCost(order: Order | BTOrder, stakeCurrency: string): string {
|
||||
return `${order.ft_order_side === 'buy' ? '+' : '-'}${formatPriceCurrency(
|
||||
'cost' in order ? order.cost : order.amount * order.safe_price,
|
||||
trade.quote_currency ?? '<stake_currency>',
|
||||
stakeCurrency,
|
||||
)}`;
|
||||
}
|
||||
|
||||
function buildToolTip(trade: Trade, order: Order | BTOrder, side: string): string {
|
||||
function buildToolTip(
|
||||
trade: Trade,
|
||||
order: Order | BTOrder,
|
||||
side: string,
|
||||
stakeCurrency: string,
|
||||
): string {
|
||||
return `${trade.is_short ? 'Short' : 'Long'} ${side}
|
||||
${formatPercent(trade.profit_ratio)} ${
|
||||
trade.profit_abs
|
||||
? '(' +
|
||||
formatPriceCurrency(trade.profit_abs, trade.quote_currency ?? '<stake_currency>') +
|
||||
')'
|
||||
: ''
|
||||
trade.profit_abs ? '(' + formatPriceCurrency(trade.profit_abs, stakeCurrency) + ')' : ''
|
||||
}
|
||||
${buildTooltipCost(trade, order)}
|
||||
${buildTooltipCost(order, stakeCurrency)}
|
||||
Enter-tag: ${trade.enter_tag ?? ''}
|
||||
Exit-Tag: ${trade.exit_reason ?? ''}`;
|
||||
}
|
||||
|
||||
function buildAdjustmentToolTip(trade: Trade, order: Order | BTOrder): string {
|
||||
function buildAdjustmentToolTip(
|
||||
trade: Trade,
|
||||
order: Order | BTOrder,
|
||||
stakeCurrency: string,
|
||||
): string {
|
||||
return `${trade.is_short ? 'Short' : 'Long'} adjustment
|
||||
${buildTooltipCost(trade, order)}
|
||||
${buildTooltipCost(order, stakeCurrency)}
|
||||
Enter-tag: ${trade.enter_tag ?? ''}`;
|
||||
}
|
||||
|
||||
|
@ -66,6 +71,7 @@ export function getTradeEntries(dataset: PairHistory, trades: Trade[]) {
|
|||
if (trade.orders) {
|
||||
for (let i = 0; i < trade.orders.length; i++) {
|
||||
const order: Order | BTOrder = trade.orders[i];
|
||||
const stakeCurrency = trade.quote_currency ?? '<stake_currency>';
|
||||
if (
|
||||
order.order_filled_timestamp &&
|
||||
roundTimeframe(dataset.timeframe_ms ?? 0, order.order_filled_timestamp) <=
|
||||
|
@ -81,7 +87,7 @@ export function getTradeEntries(dataset: PairHistory, trades: Trade[]) {
|
|||
order.ft_order_side == 'sell' ? 180 : 0,
|
||||
trade.is_short ? SHORT_COLOR : LONG_COLOR,
|
||||
trade.is_short ? 'Short' : 'Long',
|
||||
buildToolTip(trade, order, 'entry'),
|
||||
buildToolTip(trade, order, 'entry', stakeCurrency),
|
||||
]);
|
||||
// Trade exit
|
||||
} else if (i === trade.orders.length - 1 && trade.close_timestamp) {
|
||||
|
@ -99,7 +105,7 @@ export function getTradeEntries(dataset: PairHistory, trades: Trade[]) {
|
|||
trade.is_short ? SHORT_COLOR : LONG_COLOR,
|
||||
// (trade.profit_abs ?? 0) > 0 ? '#31e04b' : '#fc0505',
|
||||
formatPercent(trade.profit_ratio, 2),
|
||||
buildToolTip(trade, order, 'exit'),
|
||||
buildToolTip(trade, order, 'exit', stakeCurrency),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +118,7 @@ export function getTradeEntries(dataset: PairHistory, trades: Trade[]) {
|
|||
order.ft_order_side == 'sell' ? 180 : 0,
|
||||
trade.is_short ? SHORT_COLOR : LONG_COLOR,
|
||||
'',
|
||||
buildAdjustmentToolTip(trade, order),
|
||||
buildAdjustmentToolTip(trade, order, stakeCurrency),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user