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
+259 -20
View File
@@ -11,7 +11,7 @@ creatOrderTrueTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -25,7 +25,7 @@ creatOrderTrueTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -39,7 +39,7 @@ creatOrderTrueTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 2
marginRate: '0.01'
orderSourceType: 1
@@ -53,12 +53,167 @@ creatOrderTrueTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.005'
orderSourceType: 1
- code: 0
msg: OK
# ---- 矩阵扩充:全仓/逐仓 × 多空 × 起始保证金率三档(0.005/0.02/0.05) ----
# 全仓-卖出-0.005(20 倍杠杆)
- - userId: 1001
contractId: 1
side: ask
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: '0.005'
orderSourceType: 1
- code: 0
msg: OK
# 全仓-买入-0.02(50 倍杠杆)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: '0.02'
orderSourceType: 1
- code: 0
msg: OK
# 全仓-卖出-0.02
- - userId: 1001
contractId: 1
side: ask
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: '0.02'
orderSourceType: 1
- code: 0
msg: OK
# 全仓-买入-0.05(20 倍杠杆)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: '0.05'
orderSourceType: 1
- code: 0
msg: OK
# 全仓-卖出-0.05
- - userId: 1001
contractId: 1
side: ask
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: '0.05'
orderSourceType: 1
- code: 0
msg: OK
# 逐仓-买入-0.005(20 倍杠杆)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 2
marginRate: '0.005'
orderSourceType: 1
- code: 0
msg: OK
# 逐仓-卖出-0.005
- - userId: 1001
contractId: 1
side: ask
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 2
marginRate: '0.005'
orderSourceType: 1
- code: 0
msg: OK
# 逐仓-买入-0.02(50 倍杠杆)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 2
marginRate: '0.02'
orderSourceType: 1
- code: 0
msg: OK
# 逐仓-卖出-0.02
- - userId: 1001
contractId: 1
side: ask
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 2
marginRate: '0.02'
orderSourceType: 1
- code: 0
msg: OK
# 逐仓-买入-0.05(20 倍杠杆)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 2
marginRate: '0.05'
orderSourceType: 1
- code: 0
msg: OK
# 逐仓-卖出-0.05
- - userId: 1001
contractId: 1
side: ask
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 2
marginRate: '0.05'
orderSourceType: 1
- code: 0
msg: OK
creatOrderFalseTestdata:
# userId 非数值
@@ -69,7 +224,7 @@ creatOrderFalseTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -83,7 +238,7 @@ creatOrderFalseTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -97,7 +252,7 @@ creatOrderFalseTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -111,7 +266,7 @@ creatOrderFalseTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -125,7 +280,7 @@ creatOrderFalseTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -139,7 +294,7 @@ creatOrderFalseTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -153,7 +308,7 @@ creatOrderFalseTestdata:
price: ''
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -167,7 +322,7 @@ creatOrderFalseTestdata:
price: -1
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -181,7 +336,7 @@ creatOrderFalseTestdata:
price: abc
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -195,7 +350,7 @@ creatOrderFalseTestdata:
price: 100
quantity: 0
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -209,7 +364,7 @@ creatOrderFalseTestdata:
price: 100
quantity: 10
orderType: 5
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
@@ -223,7 +378,7 @@ creatOrderFalseTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 3
marginRate: '0.01'
orderSourceType: 1
@@ -237,7 +392,7 @@ creatOrderFalseTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '2'
orderSourceType: 1
@@ -251,12 +406,12 @@ creatOrderFalseTestdata:
price: 100
quantity: 10
orderType: 1
durationQualifiers: SDFSDF
timeInForce: SDFSDF
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:durationQualifiers"
msg: "参数错误:timeInForce"
# 余额不足(冻结金额超过账户资金)
- - userId: 1001
contractId: 1
@@ -265,9 +420,93 @@ creatOrderFalseTestdata:
price: 99999999
quantity: 10
orderType: 1
durationQualifiers: GTC
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 2001
msg: 余额不足
# ---- 负例扩充 ----
# 数量为负数
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: -10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:quantity"
# 保证金率为 0
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: '0'
orderSourceType: 1
- code: 1003
msg: "参数错误:marginRate"
# 保证金率非法字符串
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: abc
orderSourceType: 1
- code: 1003
msg: "参数错误:marginRate"
# 平仓方向(positionEffect != 1)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 2
price: 100
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:positionEffect"
# 缺 price 参数(限价单必传)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:price"
# 余额不足边界:冻结额(本金+孰高手续费)恰好略超账户总资金
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100001
quantity: 10
orderType: 1
timeInForce: GTC
marginType: 1
marginRate: '1'
orderSourceType: 1
- code: 2001
msg: 余额不足
+24
View File
@@ -7,22 +7,42 @@ frozenMargin:
- {price: '95.5', quantity: '2', margin_rate: '0.1', expected: '19.1955'}
# 精度演示:float 下 0.1*3=0.30000000000000004,Decimal 精确
- {price: '0.1', quantity: '3', margin_rate: '1', expected: '0.30015'}
# 高杠杆:1000*50*0.02=1000,手续费孰高 1000*50*0.0005=25
- {price: 1000, quantity: 50, margin_rate: '0.02', expected: '1025'}
# 整仓(margin_rate=1):125*8*1 + 125*8*0.0005 = 1000 + 0.5
- {price: 125, quantity: 8, margin_rate: '1', expected: '1000.5'}
unrealizedPnl:
- {side: bid, open_price: 100, mark_price: 110, quantity: 10, expected: '100'}
- {side: bid, open_price: 100, mark_price: 90, quantity: 10, expected: '-100'}
- {side: ask, open_price: 100, mark_price: 90, quantity: 10, expected: '100'}
- {side: ask, open_price: 100, mark_price: 110, quantity: 10, expected: '-100'}
# 标记价不变:盈亏为 0
- {side: bid, open_price: 100, mark_price: 100, quantity: 10, expected: '0'}
# 小数价格:3.5*(100.25-95.5)=16.625
- {side: bid, open_price: '95.5', mark_price: '100.25', quantity: '3.5', expected: '16.625'}
bankruptcyPrice:
- {side: bid, open_price: 100, quantity: 10, margin_rate: '0.1', extra_margin: '0', expected: '90'}
- {side: ask, open_price: 100, quantity: 10, margin_rate: '0.1', extra_margin: '0', expected: '110'}
- {side: bid, open_price: 100, quantity: 10, margin_rate: '0.1', extra_margin: '20', expected: '88'}
# 做空追加保证金:100*1.1 + 20/10 = 112
- {side: ask, open_price: 100, quantity: 10, margin_rate: '0.1', extra_margin: '20', expected: '112'}
# 高杠杆做多 20 倍:100*(1-0.05) = 95
- {side: bid, open_price: 100, quantity: 10, margin_rate: '0.05', extra_margin: '0', expected: '95'}
# 高杠杆做空 50 倍:100*(1+0.02) = 102
- {side: ask, open_price: 100, quantity: 10, margin_rate: '0.02', extra_margin: '0', expected: '102'}
liquidationPrice:
- {side: bid, open_price: 100, quantity: 10, margin_rate: '0.1', maintain_rate: '0.005', extra_margin: '0', expected: '90.5'}
- {side: ask, open_price: 100, quantity: 10, margin_rate: '0.1', maintain_rate: '0.005', extra_margin: '0', expected: '109.5'}
- {side: bid, open_price: 100, quantity: 10, margin_rate: '0.1', maintain_rate: '0.005', extra_margin: '20', expected: '88.5'}
# 做空追加保证金:需亏 115,价格上涨 11.5 → 100 + 11.5 = 111.5
- {side: ask, open_price: 100, quantity: 10, margin_rate: '0.1', maintain_rate: '0.005', extra_margin: '20', expected: '111.5'}
# 高杠杆做多 20 倍:100 + (5-0-50)/10 = 95.5
- {side: bid, open_price: 100, quantity: 10, margin_rate: '0.05', maintain_rate: '0.005', extra_margin: '0', expected: '95.5'}
# 高杠杆做空 50 倍:需亏 15,价格上涨 1.5 → 100 + 1.5 = 101.5
- {side: ask, open_price: 100, quantity: 10, margin_rate: '0.02', maintain_rate: '0.005', extra_margin: '0', expected: '101.5'}
isBurst:
# 恰好等于强平价:保证金余额 == 维持保证金,<= 即触发
@@ -30,3 +50,7 @@ isBurst:
- {side: bid, open_price: 100, mark_price: '91', quantity: 10, margin_rate: '0.1', maintain_rate: '0.005', extra_margin: '0', expected: false}
- {side: ask, open_price: 100, mark_price: '109.5', quantity: 10, margin_rate: '0.1', maintain_rate: '0.005', extra_margin: '0', expected: true}
- {side: ask, open_price: 100, mark_price: '109', quantity: 10, margin_rate: '0.1', maintain_rate: '0.005', extra_margin: '0', expected: false}
# 穿仓:标记价跌破破产价,余额为负仍判定触发
- {side: bid, open_price: 100, mark_price: '85', quantity: 10, margin_rate: '0.1', maintain_rate: '0.005', extra_margin: '0', expected: true}
# 高杠杆做空 50 倍:余额 20+(100-103.5)*10=-15 <= 维持保证金 5,触发(103.5 已越过强平价 101.5)
- {side: ask, open_price: 100, mark_price: '103.5', quantity: 10, margin_rate: '0.02', maintain_rate: '0.005', extra_margin: '0', expected: true}
+21
View File
@@ -24,3 +24,24 @@ liquidationScenarios:
marginRate: '0.1'
safeMark: '91'
triggerMark: '85'
# 逐仓 20 倍杠杆做多:强平价 95.5,破产价 95
- name: 高杠杆20x做多-触及强平价触发
side: bid
quantity: 10
marginRate: '0.05'
safeMark: '96'
triggerMark: '95.5'
# 逐仓 50 倍杠杆做空:强平价 101.5,破产价 102
- name: 高杠杆50x做空-触及强平价触发
side: ask
quantity: 10
marginRate: '0.02'
safeMark: '101'
triggerMark: '101.5'
# 做空且标记价涨破破产价 110:穿仓,缺口由风险基金兜底
- name: 做空-穿仓由风险基金兜底
side: ask
quantity: 10
marginRate: '0.1'
safeMark: '109'
triggerMark: '115'