币本位买币改为按最大可开张数×权利金×可配缓冲,不全额兑换USDT

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 14:33:48 +08:00
parent 4fb3be35ef
commit 87910ed71a
9 changed files with 309 additions and 63 deletions
+39
View File
@@ -82,6 +82,45 @@ class TestOptionsMarginMode(unittest.TestCase):
self.assertTrue(r["ok"])
self.assertEqual(r["sheets"], 97)
def test_spot_buy_buffer_normalize(self):
from lib.options.options_margin_mode_lib import normalize_coin_spot_buy_buffer
self.assertAlmostEqual(normalize_coin_spot_buy_buffer(1.10), 1.10)
self.assertAlmostEqual(normalize_coin_spot_buy_buffer(0.10), 1.10)
self.assertAlmostEqual(normalize_coin_spot_buy_buffer(1.25), 1.25)
def test_plan_coin_open_by_budget(self):
from lib.options.options_margin_mode_lib import plan_coin_open_by_budget
# ask 0.01, ct 0.1 → 单张权利金 0.001 ETH;×1.1=0.0011;×指数 2000 → 2.2 USDT/张
r = plan_coin_open_by_budget(
quote_per_unit=0.01,
ct_mult=0.1,
min_sz=1,
budget_usdt=10.0,
index_px=2000.0,
ask_sz=100,
spot_buy_buffer=1.10,
)
self.assertTrue(r["ok"], r.get("msg"))
self.assertEqual(r["sheets"], 4) # floor(10/2.2)=4
self.assertAlmostEqual(r["buy_usdt"], 4 * 0.01 * 0.1 * 1.10 * 2000, places=4)
self.assertLess(r["buy_usdt"], 10.0)
one = plan_coin_open_by_budget(
quote_per_unit=0.01,
ct_mult=0.1,
min_sz=1,
budget_usdt=10.0,
index_px=2000.0,
ask_sz=100,
spot_buy_buffer=1.10,
target_sheets=1,
)
self.assertTrue(one["ok"], one.get("msg"))
self.assertEqual(one["sheets"], 1)
self.assertAlmostEqual(one["buy_usdt"], 0.01 * 0.1 * 1.10 * 2000, places=4)
if __name__ == "__main__":
unittest.main()