fix: unify order/key focus K-line theme, PnL, RR and exchange price tick
Share focus_chart templates and APIs across four instances; align chart Y-axis, price lines and meta bar with exchange symbol precision and live unrealized PnL. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6549,39 +6549,51 @@ def api_order_kline():
|
||||
"volume": float(bar[5]),
|
||||
})
|
||||
|
||||
from focus_chart_lib import (
|
||||
build_order_kline_order_payload,
|
||||
load_swap_positions_for_order_kline,
|
||||
metrics_for_order_item,
|
||||
)
|
||||
|
||||
current_price = get_price(order_item["symbol"])
|
||||
margin = float(order_item.get("margin_capital") or 0)
|
||||
leverage = float(order_item.get("leverage") or 0)
|
||||
entry = float(order_item.get("trigger_price") or 0)
|
||||
float_pnl = calc_pnl(order_item.get("direction") or "long", entry, current_price, margin, leverage) if current_price else 0
|
||||
float_pct = round((float_pnl / margin * 100), 2) if margin > 0 else 0
|
||||
positions = load_swap_positions_for_order_kline(
|
||||
exchange,
|
||||
private_configured=exchange_private_api_configured(),
|
||||
ensure_markets_fn=ensure_markets_loaded,
|
||||
)
|
||||
ex_metrics = metrics_for_order_item(
|
||||
order_item,
|
||||
positions,
|
||||
resolve_ex_sym_fn=resolve_monitor_exchange_symbol,
|
||||
select_live_fn=_select_live_position_row,
|
||||
parse_metrics_fn=parse_ccxt_position_metrics,
|
||||
)
|
||||
order_payload = build_order_kline_order_payload(
|
||||
order_item,
|
||||
ticker_price=current_price,
|
||||
format_price_fn=format_price_for_symbol,
|
||||
calc_pnl_fn=calc_pnl,
|
||||
calc_rr_ratio_fn=calc_rr_ratio,
|
||||
ex_metrics=ex_metrics,
|
||||
)
|
||||
|
||||
from focus_chart_lib import kline_api_price_fields
|
||||
|
||||
price_fields = kline_api_price_fields(
|
||||
exchange,
|
||||
exchange_symbol,
|
||||
candles,
|
||||
ensure_markets_fn=ensure_markets_loaded,
|
||||
)
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
"timeframe": timeframe,
|
||||
"limit": limit,
|
||||
"order": {
|
||||
"id": order_item["id"],
|
||||
"symbol": order_item["symbol"],
|
||||
"direction": order_item.get("direction") or "long",
|
||||
"trigger_price": order_item.get("trigger_price"),
|
||||
"stop_loss": order_item.get("stop_loss"),
|
||||
"take_profit": order_item.get("take_profit"),
|
||||
"trigger_price_display": format_price_for_symbol(exchange_symbol, order_item.get("trigger_price")),
|
||||
"stop_loss_display": format_price_for_symbol(exchange_symbol, order_item.get("stop_loss")),
|
||||
"take_profit_display": format_price_for_symbol(exchange_symbol, order_item.get("take_profit")),
|
||||
"margin_capital": order_item.get("margin_capital"),
|
||||
"leverage": order_item.get("leverage"),
|
||||
"position_ratio": order_item.get("position_ratio"),
|
||||
"rr_ratio": order_item.get("rr_ratio"),
|
||||
"breakeven_enabled": bool(int(order_item.get("breakeven_enabled") or 0)),
|
||||
"current_price": round(float(current_price), 8) if current_price else None,
|
||||
"current_price_display": format_price_for_symbol(exchange_symbol, current_price) if current_price else None,
|
||||
"float_pnl": round(float(float_pnl), FUNDS_DECIMALS),
|
||||
"float_pct": float_pct,
|
||||
},
|
||||
"order": order_payload,
|
||||
"candles": candles,
|
||||
"updated_at": app_now_str(),
|
||||
**price_fields,
|
||||
})
|
||||
|
||||
|
||||
@@ -6675,8 +6687,6 @@ def api_key_kline():
|
||||
"direction": key_row["direction"] or "long",
|
||||
"upper": upper,
|
||||
"lower": lower,
|
||||
"upper_display": format_price_for_symbol(exchange_symbol, upper) if upper is not None else None,
|
||||
"lower_display": format_price_for_symbol(exchange_symbol, lower) if lower is not None else None,
|
||||
"notification_count": int(key_row["notification_count"] or 0),
|
||||
"upper_diff": upper_diff,
|
||||
"upper_pct": upper_pct,
|
||||
@@ -6684,16 +6694,35 @@ def api_key_kline():
|
||||
"lower_pct": lower_pct,
|
||||
}
|
||||
|
||||
from focus_chart_lib import enrich_key_kline_response
|
||||
|
||||
price_display, key_info = enrich_key_kline_response(
|
||||
symbol=symbol,
|
||||
current_price=current_price,
|
||||
key_info=key_info,
|
||||
format_price_fn=format_price_for_symbol,
|
||||
)
|
||||
|
||||
from focus_chart_lib import kline_api_price_fields
|
||||
|
||||
price_fields = kline_api_price_fields(
|
||||
exchange,
|
||||
exchange_symbol,
|
||||
candles,
|
||||
ensure_markets_fn=ensure_markets_loaded,
|
||||
)
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
"symbol": symbol,
|
||||
"timeframe": timeframe,
|
||||
"limit": limit,
|
||||
"current_price": round(float(current_price), 8) if current_price is not None else None,
|
||||
"current_price_display": format_price_for_symbol(exchange_symbol, current_price) if current_price is not None else None,
|
||||
"current_price_display": price_display,
|
||||
"key_monitor": key_info,
|
||||
"candles": candles,
|
||||
"updated_at": app_now_str(),
|
||||
**price_fields,
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user