fix: align unrealized PnL across four exchange instances via hub_position_metrics
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,6 +12,7 @@ from agent import _position_mark_price, _ticker_mark_price # noqa: E402
|
||||
|
||||
sys.path.insert(0, str(ROOT))
|
||||
from hub_position_metrics import ( # noqa: E402
|
||||
enrich_ccxt_position_metrics_out,
|
||||
estimate_linear_swap_upnl_usdt,
|
||||
parse_position_unrealized_pnl,
|
||||
resolve_position_display_upnl,
|
||||
@@ -52,6 +53,24 @@ class TestHubAgentMarkPrice(unittest.TestCase):
|
||||
)
|
||||
self.assertAlmostEqual(pnl, 6.81)
|
||||
|
||||
def test_okx_upl_signed(self):
|
||||
pnl = parse_position_unrealized_pnl(
|
||||
{"info": {"upl": "-2.15"}, "unrealizedPnl": None}
|
||||
)
|
||||
self.assertAlmostEqual(pnl, -2.15)
|
||||
|
||||
def test_enrich_aligns_short_gate_metrics(self):
|
||||
pos = {
|
||||
"side": "short",
|
||||
"contracts": 11,
|
||||
"entryPrice": 73.187,
|
||||
"markPrice": 66.038,
|
||||
"info": {"unrealised_pnl": "7.86"},
|
||||
}
|
||||
out = {"unrealized_pnl": 7.86, "mark_price": 66.038}
|
||||
enrich_ccxt_position_metrics_out(pos, out, contract_size=1.0, funds_decimals=2)
|
||||
self.assertGreater(out["unrealized_pnl"], 70.0)
|
||||
|
||||
def test_estimate_short_hype_contract_size(self):
|
||||
upnl = estimate_linear_swap_upnl_usdt(
|
||||
"short", 73.187, 66.038, 11, 0.1
|
||||
|
||||
Reference in New Issue
Block a user