refactor: 字段与接口路径改用中性演示命名,并扩充下单用例矩阵

This commit is contained in:
2026-09-21 22:38:59 +08:00
parent 4f39f6cef2
commit e3afd2e46c
8 changed files with 389 additions and 105 deletions
+10 -10
View File
@@ -3,8 +3,8 @@
市价单按标记价格立即成交,校验:
- order 表:状态全部成交、成交量;
- position 表:方向/数量/开仓均价;
- account_future 表:仓位保证金占用、手续费扣减(期望值由公式层独立计算);
- user_currency_flow 表:手续费(5)与开仓(7)两条流水;
- futures_account 表:仓位保证金占用、手续费扣减(期望值由公式层独立计算);
- account_flow 表:手续费(5)与开仓(7)两条流水;
- 缓存:仓位键与资金镜像;
- 行情联动:标记价格变化后,风控接口返回的保证金余额与公式一致。
"""
@@ -25,7 +25,7 @@ MARK_PRICE = Decimal(settings.CONTRACTS[1]["mark_price"])
def _market_order_param(user_id, side, margin_rate="0.1"):
return {
"userId": user_id, "contractId": 1, "side": side, "positionEffect": 1,
"orderType": 2, "quantity": 10, "durationQualifiers": "GTC",
"orderType": 2, "quantity": 10, "timeInForce": "GTC",
"marginType": 2, "marginRate": margin_rate, "orderSourceType": 1,
}
@@ -35,7 +35,7 @@ class TestMarketOrderOpen:
def test_open_long_position(self, base_url, trader, db, cache):
"""做多开仓:仓位/资金/流水/缓存四面对账。"""
contract = settings.CONTRACTS[1]
before = dict(db.select("account_future", user_id=trader)[0])
before = dict(db.select("futures_account", user_id=trader)[0])
body = order_api.add_order(base_url, **_market_order_param(trader, "bid"))
assert body["code"] == 0
@@ -62,18 +62,18 @@ class TestMarketOrderOpen:
contract["maker_fee_rate"], contract["taker_fee_rate"])
# 资金:total 扣(保证金+手续费),逐仓保证金占用增加
account = db.select("account_future", user_id=trader)[0]
assert_decimal_equal(account["isolated_position_margin"],
before["isolated_position_margin"] + expect_init)
account = db.select("futures_account", user_id=trader)[0]
assert_decimal_equal(account["isolated_margin"],
before["isolated_margin"] + expect_init)
assert_decimal_equal(account["total_money"],
before["total_money"] - expect_init - expect_fee)
# 流水:手续费(5)与开仓(7)
assert_decimal_equal(
db.select("user_currency_flow", order_no=order_no, type=5)[0]["quantity"],
db.select("account_flow", order_no=order_no, type=5)[0]["quantity"],
expect_fee)
assert_decimal_equal(
db.select("user_currency_flow", order_no=order_no, type=7)[0]["quantity"],
db.select("account_flow", order_no=order_no, type=7)[0]["quantity"],
expect_init)
# 缓存:仓位键与资金镜像
@@ -82,7 +82,7 @@ class TestMarketOrderOpen:
assert cached_position["side"] == "1"
assert_decimal_equal(cached_position["avgPrice"], position["avg_price"])
cached_account = json.loads(
cache.get("account_future:userId:%s:currencyId:1" % trader))
cache.get("futures_account:userId:%s:currencyId:1" % trader))
assert_decimal_equal(cached_account["totalMoney"], account["total_money"])
def test_open_short_position_and_mark_price_move(self, base_url, trader, db):