修复 OKX 期权翻倍出场与币本位浮盈:中控/看板按指数折 U,避免 BTC 币数量当美金。
翻倍出场按全仓买一判定且对冲表异常不再整段跳过;面板按当前倍数展示需回收公式。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""币本位期权浮盈折 U(BTC/ETH 不得把币数量直接当 U)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from lib.options.options_positions_lib import display_pnl_usdt_from_option_row
|
||||
|
||||
|
||||
class DisplayPnlUsdtTests(unittest.TestCase):
|
||||
def test_btc_coin_pnl_times_index(self):
|
||||
row = {
|
||||
"inst_id": "BTC-USD-260327-100000-P",
|
||||
"premium_ccy": "BTC",
|
||||
"margin_mode": "coin",
|
||||
"idx_px": 100000.0,
|
||||
"upl": -0.001,
|
||||
"close_preview": {"bid_invalid": True},
|
||||
}
|
||||
self.assertAlmostEqual(display_pnl_usdt_from_option_row(row), -100.0, places=4)
|
||||
|
||||
def test_btc_infers_ccy_when_premium_ccy_missing(self):
|
||||
row = {
|
||||
"inst_id": "BTC-USD-260327-100000-C",
|
||||
"margin_mode": "coin",
|
||||
"underlying": "BTC",
|
||||
"idx_px": 95000.0,
|
||||
"upl": 0.002,
|
||||
"close_preview": {"bid_invalid": True},
|
||||
}
|
||||
self.assertAlmostEqual(display_pnl_usdt_from_option_row(row), 190.0, places=4)
|
||||
|
||||
def test_usdc_unchanged(self):
|
||||
row = {
|
||||
"inst_id": "BTC-USD_UM-260327-100000-C",
|
||||
"premium_ccy": "USDC",
|
||||
"margin_mode": "usdc",
|
||||
"upl": -12.5,
|
||||
"close_preview": {"bid_invalid": True},
|
||||
}
|
||||
self.assertAlmostEqual(display_pnl_usdt_from_option_row(row), -12.5, places=4)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user