fix(gate-bot): format mark price with exchange symbol precision
Use price_to_precision in price_snapshot so live mark price matches entry/SL display instead of fixed 8 decimals.
This commit is contained in:
@@ -52,6 +52,7 @@ from key_monitor_full_margin_lib import (
|
|||||||
from auto_transfer_daily_lib import run_auto_transfer_once_per_day
|
from auto_transfer_daily_lib import run_auto_transfer_once_per_day
|
||||||
from form_submit_lib import check_duplicate_submit, submit_scope_add_key, submit_scope_add_order
|
from form_submit_lib import check_duplicate_submit, submit_scope_add_key, submit_scope_add_order
|
||||||
from order_monitor_display_lib import (
|
from order_monitor_display_lib import (
|
||||||
|
apply_order_live_price_display,
|
||||||
apply_order_price_display_fields,
|
apply_order_price_display_fields,
|
||||||
enrich_order_display_fields,
|
enrich_order_display_fields,
|
||||||
stop_is_profit_protecting,
|
stop_is_profit_protecting,
|
||||||
@@ -5926,6 +5927,13 @@ def api_price_snapshot():
|
|||||||
payload["float_pct"] = (
|
payload["float_pct"] = (
|
||||||
round((payload["float_pnl"] / float(denom)) * 100, 4) if denom and float(denom) > 0 else pnl_pct
|
round((payload["float_pnl"] / float(denom)) * 100, 4) if denom and float(denom) > 0 else pnl_pct
|
||||||
)
|
)
|
||||||
|
apply_order_live_price_display(
|
||||||
|
payload,
|
||||||
|
r["symbol"],
|
||||||
|
price,
|
||||||
|
payload.get("exchange_mark_price"),
|
||||||
|
format_price_for_symbol,
|
||||||
|
)
|
||||||
if exchange_private_api_configured():
|
if exchange_private_api_configured():
|
||||||
try:
|
try:
|
||||||
exchange_tpsl = fetch_exchange_tpsl_slots(
|
exchange_tpsl = fetch_exchange_tpsl_slots(
|
||||||
|
|||||||
@@ -1867,7 +1867,7 @@ function refreshPriceSnapshotConditional(){
|
|||||||
else if(o.price_display) disp = o.price_display;
|
else if(o.price_display) disp = o.price_display;
|
||||||
else {
|
else {
|
||||||
const px = hasMark ? Number(o.exchange_mark_price) : Number(o.price);
|
const px = hasMark ? Number(o.exchange_mark_price) : Number(o.price);
|
||||||
disp = Number.isFinite(px) ? px.toFixed(hasMark ? 8 : 6) : "-";
|
disp = Number.isFinite(px) ? String(px) : "-";
|
||||||
}
|
}
|
||||||
pEl.innerText = disp;
|
pEl.innerText = disp;
|
||||||
const pxNum = hasMark ? Number(o.exchange_mark_price) : Number(o.price);
|
const pxNum = hasMark ? Number(o.exchange_mark_price) : Number(o.price);
|
||||||
|
|||||||
@@ -119,6 +119,33 @@ def enrich_order_display_fields(item: dict[str, Any], calc_rr_ratio_fn: Callable
|
|||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
|
def apply_order_live_price_display(
|
||||||
|
payload: dict[str, Any],
|
||||||
|
symbol: Any,
|
||||||
|
ticker_price: Any,
|
||||||
|
exchange_mark_price: Any,
|
||||||
|
format_price_fn: Callable[[Any, Any], str],
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""标记价/现价展示:与交易所 price_to_precision 对齐,避免前端 toFixed(8)。"""
|
||||||
|
px_for_fmt = ticker_price
|
||||||
|
mark_raw = exchange_mark_price
|
||||||
|
if mark_raw is not None:
|
||||||
|
try:
|
||||||
|
px_for_fmt = float(mark_raw)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
pass
|
||||||
|
px_disp = format_price_fn(symbol, px_for_fmt)
|
||||||
|
payload["price_display"] = px_disp
|
||||||
|
if mark_raw is not None:
|
||||||
|
try:
|
||||||
|
payload["exchange_mark_price_display"] = format_price_fn(symbol, float(mark_raw))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
payload["exchange_mark_price_display"] = px_disp
|
||||||
|
else:
|
||||||
|
payload["exchange_mark_price_display"] = None
|
||||||
|
return payload
|
||||||
|
|
||||||
|
|
||||||
def apply_order_price_display_fields(
|
def apply_order_price_display_fields(
|
||||||
payload: dict[str, Any],
|
payload: dict[str, Any],
|
||||||
*,
|
*,
|
||||||
|
|||||||
Reference in New Issue
Block a user