Files
crypto_okx/tests/test_sim_option_fee.py
T
dekun 78f18e731a fix模拟盘期权手续费按OKX币本位公式计费,并纠正复盘旧单展示。
费率作用在标的币数量上并以权利金7%封顶,不再误用权利金×费率。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-13 09:37:14 +08:00

53 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""模拟盘期权手续费:对齐 OKX 币本位公式."""
from __future__ import annotations
import unittest
from lib.sim.pricing_lib import option_fee_coin, option_fill
class OptionFeeCoinTests(unittest.TestCase):
def test_fee_on_underlying_not_premium(self):
# 90 张 BTC×0.01=0.9 币;权利金 0.01125
fee = option_fee_coin(
underlying_coin=0.9,
premium_coin=0.01125,
fee_rate=0.0005,
)
# min(0.9*0.0005, 0.01125*0.07) = min(0.00045, 0.0007875)
self.assertAlmostEqual(fee, 0.00045, places=8)
def test_premium_cap(self):
fee = option_fee_coin(
underlying_coin=1.0,
premium_coin=0.001,
fee_rate=0.0005,
)
# min(0.0005, 0.00007) = 0.00007
self.assertAlmostEqual(fee, 0.00007, places=8)
def test_option_fill_uses_okx_fee(self):
pr = option_fill(
action="open",
bid=0.012,
ask=0.0125,
qty=0.9,
fee_rate=0.0005,
)
self.assertGreater(pr.fee, 1e-6)
# 旧算法 fee≈notional*rate≈5.6e-6;新算法应为 4.5e-4 量级
self.assertGreater(pr.fee, 1e-4)
self.assertAlmostEqual(
pr.fee,
option_fee_coin(
underlying_coin=0.9,
premium_coin=pr.notional,
fee_rate=0.0005,
),
places=8,
)
if __name__ == "__main__":
unittest.main()