feat(hub): exchange price precision, entry price, and trend DCA display

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-03 21:25:24 +08:00
parent fac28c402b
commit f95118065d
5 changed files with 368 additions and 49 deletions
+32
View File
@@ -0,0 +1,32 @@
"""子代理持仓:四所开仓价字段统一解析。"""
from __future__ import annotations
import sys
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "manual_trading_hub"))
from agent import _position_entry_price # noqa: E402
class TestHubAgentEntryPrice(unittest.TestCase):
def test_binance_entry_price(self):
px = _position_entry_price({"entryPrice": 65851.6, "info": {}})
self.assertAlmostEqual(px, 65851.6)
def test_okx_avg_px(self):
px = _position_entry_price({"info": {"avgPx": "72.731"}})
self.assertAlmostEqual(px, 72.731)
def test_gate_info_entry(self):
px = _position_entry_price({"info": {"entry_price": "0.2232"}})
self.assertAlmostEqual(px, 0.2232)
def test_missing_returns_none(self):
self.assertIsNone(_position_entry_price({"info": {}}))
if __name__ == "__main__":
unittest.main()
+44
View File
@@ -0,0 +1,44 @@
"""趋势回调中控 enrich:补仓次数与加仓价。"""
from __future__ import annotations
import json
import sys
import unittest
from pathlib import Path
from unittest.mock import MagicMock
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from strategy_trend_register import _trend_add_leg_fields # noqa: E402
class TestTrendHubEnrich(unittest.TestCase):
def test_add_count_and_prices(self):
mock_ex = MagicMock()
mock_ex.price_to_precision = lambda sym, px: f"{float(px):.4f}"
app_mod = MagicMock()
app_mod.exchange = mock_ex
app_mod.ensure_markets_loaded = MagicMock()
app_mod.normalize_exchange_symbol = lambda s: s
cfg = {"app_module": app_mod}
raw = {
"symbol": "ETH/USDT",
"exchange_symbol": "ETH/USDT:USDT",
"legs_done": 2,
"dca_legs": 5,
"grid_prices_json": json.dumps([1800.1, 1750.2, 1700.3]),
"stop_loss": 1600,
"take_profit": 2000,
"avg_entry_price": 1820.5,
}
out = _trend_add_leg_fields(cfg, raw)
self.assertEqual(out["add_count"], 2)
self.assertEqual(out["add_count_total"], 5)
self.assertEqual(out["add_prices"], [1800.1, 1750.2])
self.assertEqual(len(out["add_prices_display"]), 2)
self.assertEqual(out["stop_loss_display"], "1600.0000")
if __name__ == "__main__":
unittest.main()