mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-10 02:11:57 +00:00
Merge pull request #1023 from daniila/dca_orders_on_chart
Dca orders on chart
This commit is contained in:
commit
fbd0bbd6f6
|
@ -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,45 +40,66 @@ 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
|
||||||
|
) {
|
||||||
|
if (trade.orders) {
|
||||||
|
for (let i = 0; i < trade.orders.length; i++) {
|
||||||
|
const order: Order = trade.orders[i];
|
||||||
|
if (
|
||||||
|
order.order_filled_timestamp &&
|
||||||
|
order.order_filled_timestamp <= dataset.data_stop_ts &&
|
||||||
|
order.order_filled_timestamp > dataset.data_start_ts
|
||||||
) {
|
) {
|
||||||
// Trade entry
|
// Trade entry
|
||||||
|
if (i === 0) {
|
||||||
tradeData.push([
|
tradeData.push([
|
||||||
roundTimeframe(dataset.timeframe_ms ?? 0, trade.open_timestamp),
|
roundTimeframe(dataset.timeframe_ms ?? 0, trade.open_timestamp),
|
||||||
trade.open_rate,
|
order.safe_price,
|
||||||
ENTRY_SYMB,
|
OPEN_CLOSE_SYMBOL,
|
||||||
trade.is_short ? 180 : 0,
|
order.ft_order_side == 'sell' ? 180 : 0,
|
||||||
// (trade.profit_abs ?? 0) > 0 ? '#31e04b' : '#fc0505',
|
trade.is_short ? SHORT_COLOR : LONG_COLOR,
|
||||||
trade.is_short ? '#AD00FF' : '#0066FF',
|
trade.is_short ? 'Short' : 'Long',
|
||||||
'',
|
|
||||||
// trade.profit_abs,
|
|
||||||
buildToolTip(trade, 'entry'),
|
buildToolTip(trade, 'entry'),
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
if (
|
|
||||||
trade.close_timestamp !== undefined &&
|
|
||||||
trade.close_timestamp <= dataset.data_stop_ts &&
|
|
||||||
trade.close_timestamp > dataset.data_start_ts
|
|
||||||
) {
|
|
||||||
if (trade.close_date !== undefined && trade.close_rate !== undefined) {
|
|
||||||
// Trade exit
|
// Trade exit
|
||||||
|
} else if (i === trade.orders.length - 1 && trade.close_timestamp) {
|
||||||
|
if (
|
||||||
|
trade.close_timestamp <= dataset.data_stop_ts &&
|
||||||
|
trade.close_timestamp > dataset.data_start_ts &&
|
||||||
|
trade.is_open === false
|
||||||
|
) {
|
||||||
tradeData.push([
|
tradeData.push([
|
||||||
roundTimeframe(dataset.timeframe_ms ?? 0, trade.close_timestamp),
|
roundTimeframe(dataset.timeframe_ms ?? 0, trade.close_timestamp),
|
||||||
trade.close_rate,
|
order.safe_price,
|
||||||
EXIT_SYMB,
|
OPEN_CLOSE_SYMBOL,
|
||||||
trade.is_short ? 180 : 0,
|
trade.is_short ? 0 : 180,
|
||||||
trade.is_short ? '#AD00FF' : '#0066FF',
|
trade.is_short ? SHORT_COLOR : LONG_COLOR,
|
||||||
// (trade.profit_abs ?? 0) > 0 ? '#31e04b' : '#fc0505',
|
// (trade.profit_abs ?? 0) > 0 ? '#31e04b' : '#fc0505',
|
||||||
formatPercent(trade.profit_ratio, 2),
|
formatPercent(trade.profit_ratio, 2),
|
||||||
buildToolTip(trade, 'exit'),
|
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),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return { tradeData };
|
return { tradeData };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user