Merge pull request #1023 from daniila/dca_orders_on_chart

Dca orders on chart
This commit is contained in:
Matthias 2022-11-26 14:03:14 +01:00 committed by GitHub
commit fbd0bbd6f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,20 +1,34 @@
import { formatPercent } from '@/shared/formatters'; import { formatPercent, formatPriceCurrency } from '@/shared/formatters';
import { roundTimeframe } from '@/shared/timemath'; import { roundTimeframe } from '@/shared/timemath';
import { PairHistory, Trade } from '@/types'; import { Order, PairHistory, Trade } from '@/types';
function buildToolTip(trade: Trade, side: string): string { function buildToolTip(trade: Trade, side: string): string {
return `${trade.is_short ? 'Short' : 'Long'} ${side} ${formatPercent( return `${trade.is_short ? 'Short' : 'Long'} ${side} ${formatPercent(
trade.profit_ratio, trade.profit_ratio,
)} \nEnter-tag: ${trade.enter_tag ?? ''} \nExit-Tag: ${trade.exit_reason ?? ''}`; )} \nEnter-tag: ${trade.enter_tag ?? ''} \nExit-Tag: ${trade.exit_reason ?? ''}`;
} }
function buildAdjustmentToolTip(trade: Trade, order: Order): string {
return `${trade.is_short ? 'Short' : 'Long'} adjustment
${order.ft_order_side === 'buy' ? '+' : '-'}${formatPriceCurrency(
order.cost,
trade.quote_currency ?? '',
)}\nEnter-tag: ${trade.enter_tag ?? ''}`;
}
// const ENTRY_SYMB = 'circle'; // const ENTRY_SYMB = 'circle';
// const EXIT_SYMB = 'rect'; // const EXIT_SYMB = 'rect';
const ENTRY_SYMB = const ADJUSTMENT_SYMBOL =
'path://m 52.444161,104.1909 8.386653,25.34314 8.386651,25.34313 -16.731501,0.0422 -16.731501,0.0422 8.344848,-25.38539 z m 0.08656,-48.368126 8.386652,25.343139 8.386652,25.343137 -16.731501,0.0422 -16.731502,0.0422 8.344848,-25.385389 z'; 'path://m 52.444161,104.1909 8.386653,25.34314 8.386651,25.34313 -16.731501,0.0422 -16.731501,0.0422 8.344848,-25.38539 z m 0.08656,-48.368126 8.386652,25.343139 8.386652,25.343137 -16.731501,0.0422 -16.731502,0.0422 8.344848,-25.385389 z';
const EXIT_SYMB = const OPEN_CLOSE_SYMBOL =
'path://m 102.20764,19.885384 h 24.1454 v 41.928829 h -24.1454 z m 12.17344,36.423813 8.38665,25.343139 8.38666,25.343134 -16.7315,0.0422 -16.731507,0.0422 8.344847,-25.385386 z'; 'path://m 102.20764,19.885384 h 24.1454 v 41.928829 h -24.1454 z m 12.17344,36.423813 8.38665,25.343139 8.38666,25.343134 -16.7315,0.0422 -16.731507,0.0422 8.344847,-25.385386 z';
const SHORT_COLOR = '#AD00FF';
//const SHORT_ADJUST_COLOR = '#CE3BFF';
const LONG_COLOR = '#0066FF';
//const LONG_ADJUST_COLOR = '#00A9FF';
/** Return trade entries for charting */ /** Return trade entries for charting */
export function getTradeEntries(dataset: PairHistory, filteredTrades: Trade[]) { export function getTradeEntries(dataset: PairHistory, filteredTrades: Trade[]) {
const tradeData: (number | string)[][] = []; const tradeData: (number | string)[][] = [];
@ -26,43 +40,64 @@ export function getTradeEntries(dataset: PairHistory, filteredTrades: Trade[]) {
// 4: color // 4: color
// 5: label // 5: label
// 6: tooltip // 6: tooltip
for (let i = 0, len = filteredTrades.length; i < len; i += 1) { for (let i = 0, len = filteredTrades.length; i < len; i += 1) {
const trade: Trade = filteredTrades[i]; const trade: Trade = filteredTrades[i];
if ( if (
trade.open_timestamp >= dataset.data_start_ts && trade.open_timestamp >= dataset.data_start_ts &&
trade.open_timestamp <= dataset.data_stop_ts trade.open_timestamp <= dataset.data_stop_ts
) { ) {
// Trade entry if (trade.orders) {
tradeData.push([ for (let i = 0; i < trade.orders.length; i++) {
roundTimeframe(dataset.timeframe_ms ?? 0, trade.open_timestamp), const order: Order = trade.orders[i];
trade.open_rate, if (
ENTRY_SYMB, order.order_filled_timestamp &&
trade.is_short ? 180 : 0, order.order_filled_timestamp <= dataset.data_stop_ts &&
// (trade.profit_abs ?? 0) > 0 ? '#31e04b' : '#fc0505', order.order_filled_timestamp > dataset.data_start_ts
trade.is_short ? '#AD00FF' : '#0066FF', ) {
'', // Trade entry
// trade.profit_abs, if (i === 0) {
buildToolTip(trade, 'entry'), tradeData.push([
]); roundTimeframe(dataset.timeframe_ms ?? 0, trade.open_timestamp),
} order.safe_price,
if ( OPEN_CLOSE_SYMBOL,
trade.close_timestamp !== undefined && order.ft_order_side == 'sell' ? 180 : 0,
trade.close_timestamp <= dataset.data_stop_ts && trade.is_short ? SHORT_COLOR : LONG_COLOR,
trade.close_timestamp > dataset.data_start_ts trade.is_short ? 'Short' : 'Long',
) { buildToolTip(trade, 'entry'),
if (trade.close_date !== undefined && trade.close_rate !== undefined) { ]);
// Trade exit // Trade exit
tradeData.push([ } else if (i === trade.orders.length - 1 && trade.close_timestamp) {
roundTimeframe(dataset.timeframe_ms ?? 0, trade.close_timestamp), if (
trade.close_rate, trade.close_timestamp <= dataset.data_stop_ts &&
EXIT_SYMB, trade.close_timestamp > dataset.data_start_ts &&
trade.is_short ? 180 : 0, trade.is_open === false
trade.is_short ? '#AD00FF' : '#0066FF', ) {
// (trade.profit_abs ?? 0) > 0 ? '#31e04b' : '#fc0505', tradeData.push([
formatPercent(trade.profit_ratio, 2), roundTimeframe(dataset.timeframe_ms ?? 0, trade.close_timestamp),
buildToolTip(trade, 'exit'), order.safe_price,
]); OPEN_CLOSE_SYMBOL,
trade.is_short ? 0 : 180,
trade.is_short ? SHORT_COLOR : LONG_COLOR,
// (trade.profit_abs ?? 0) > 0 ? '#31e04b' : '#fc0505',
formatPercent(trade.profit_ratio, 2),
buildToolTip(trade, 'exit'),
]);
}
}
// Position adjustment
else {
tradeData.push([
roundTimeframe(dataset.timeframe_ms ?? 0, order.order_filled_timestamp),
order.safe_price,
ADJUSTMENT_SYMBOL,
order.ft_order_side == 'sell' ? 180 : 0,
trade.is_short ? SHORT_COLOR : LONG_COLOR,
'',
buildAdjustmentToolTip(trade, order),
]);
}
}
}
} }
} }
} }