Show trade record prices at exchange tick precision.
API enriches entry/SL/TP with price_to_precision display strings; OKX formatter now uses the same path as Gate/Binance. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -18,6 +18,7 @@ def register_trade_records_api(
|
||||
to_effective_trade_dict: Callable[[Any], dict[str, Any]],
|
||||
filter_trade_records_excluding_miss: Callable[[list], list],
|
||||
app_tz: Any,
|
||||
format_price_fn: Callable[[Any, Any], str] | None = None,
|
||||
) -> None:
|
||||
from lib.instance.records_list_lib import list_trade_records_page
|
||||
|
||||
@@ -48,6 +49,7 @@ def register_trade_records_api(
|
||||
filter_fn=filter_trade_records_excluding_miss,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
format_price_fn=format_price_fn,
|
||||
)
|
||||
return jsonify(payload)
|
||||
finally:
|
||||
|
||||
@@ -2,7 +2,32 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable
|
||||
from typing import Any, Callable, Optional
|
||||
|
||||
|
||||
def enrich_trade_price_displays(
|
||||
item: dict[str, Any],
|
||||
format_price_fn: Optional[Callable[[Any, Any], str]] = None,
|
||||
) -> dict[str, Any]:
|
||||
"""为成交/止损/止盈补交易所精度展示字段(供交易记录表直接渲染)."""
|
||||
if not format_price_fn or not isinstance(item, dict):
|
||||
return item
|
||||
sym = item.get("symbol")
|
||||
stop_show = item.get("display_open_stop_loss")
|
||||
if stop_show in (None, ""):
|
||||
stop_show = item.get("initial_stop_loss")
|
||||
if stop_show in (None, ""):
|
||||
stop_show = item.get("stop_loss")
|
||||
tp_show = item.get("effective_take_profit")
|
||||
if tp_show in (None, ""):
|
||||
tp_show = item.get("take_profit")
|
||||
try:
|
||||
item["trigger_price_display"] = format_price_fn(sym, item.get("trigger_price"))
|
||||
item["stop_loss_display"] = format_price_fn(sym, stop_show)
|
||||
item["take_profit_display"] = format_price_fn(sym, tp_show)
|
||||
except Exception:
|
||||
pass
|
||||
return item
|
||||
|
||||
|
||||
def list_trade_records_page(
|
||||
@@ -16,6 +41,7 @@ def list_trade_records_page(
|
||||
limit: int = 5,
|
||||
offset: int = 0,
|
||||
fetch_cap: int = 1000,
|
||||
format_price_fn: Optional[Callable[[Any, Any], str]] = None,
|
||||
) -> dict[str, Any]:
|
||||
"""按列表窗拉取、enrich、过滤「错过」后分页."""
|
||||
limit = max(1, min(100, int(limit or 5)))
|
||||
@@ -33,6 +59,8 @@ def list_trade_records_page(
|
||||
page = pages
|
||||
offset = (page - 1) * limit
|
||||
items = records[offset : offset + limit]
|
||||
if format_price_fn is not None:
|
||||
items = [enrich_trade_price_displays(dict(it), format_price_fn) for it in items]
|
||||
return {
|
||||
"ok": True,
|
||||
"items": items,
|
||||
|
||||
Reference in New Issue
Block a user