Gate option closes behind 2x recycle sustained for 2 minutes.
Require bid-side recoverable premium at least 2x cost continuously before target auto-close or depth close can fire. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""期权平仓门控:可回收≥2×权利金且持续持有."""
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from lib.options.options_close_gate_lib import clear_close_gate, update_close_gate
|
||||
|
||||
|
||||
class OptionsCloseGateTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
clear_close_gate()
|
||||
|
||||
def tearDown(self):
|
||||
clear_close_gate()
|
||||
|
||||
def test_below_2x_not_ready(self):
|
||||
g = update_close_gate("ETH-X", recycle_usdc=15.0, premium_paid=10.0, now=1000.0)
|
||||
self.assertFalse(g["recycle_ok"])
|
||||
self.assertFalse(g["ready"])
|
||||
|
||||
def test_meets_2x_needs_hold(self):
|
||||
g1 = update_close_gate("ETH-X", recycle_usdc=20.0, premium_paid=10.0, now=1000.0)
|
||||
self.assertTrue(g1["recycle_ok"])
|
||||
self.assertFalse(g1["ready"])
|
||||
self.assertAlmostEqual(g1["remain_seconds"], 120.0)
|
||||
|
||||
g2 = update_close_gate("ETH-X", recycle_usdc=21.0, premium_paid=10.0, now=1120.0)
|
||||
self.assertTrue(g2["ready"])
|
||||
self.assertGreaterEqual(g2["held_seconds"], 120.0)
|
||||
|
||||
def test_break_resets_timer(self):
|
||||
update_close_gate("ETH-X", recycle_usdc=20.0, premium_paid=10.0, now=1000.0)
|
||||
update_close_gate("ETH-X", recycle_usdc=21.0, premium_paid=10.0, now=1100.0)
|
||||
g_break = update_close_gate("ETH-X", recycle_usdc=12.0, premium_paid=10.0, now=1110.0)
|
||||
self.assertFalse(g_break["recycle_ok"])
|
||||
g_again = update_close_gate("ETH-X", recycle_usdc=22.0, premium_paid=10.0, now=1111.0)
|
||||
self.assertTrue(g_again["recycle_ok"])
|
||||
self.assertFalse(g_again["ready"])
|
||||
self.assertAlmostEqual(g_again["held_seconds"], 0.0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user