chore: 初始化版本控制,添加 .gitignore 纳入撮合自动化测试工程

This commit is contained in:
2026-09-19 23:10:32 +08:00
commit cb7b49a4de
31 changed files with 2160 additions and 0 deletions
+273
View File
@@ -0,0 +1,273 @@
# 下单接口用例数据(数据驱动)
# 结构:[参数 dict, 期望 dict],与 @pytest.mark.parametrize("test_input,expected", ...) 按位解包
# 正例:限价开仓冻结保证金;负例:各类非法入参 + 余额不足
creatOrderTrueTestdata:
# 全仓-限价-买入开仓
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 0
msg: OK
# 全仓-限价-卖出开仓
- - userId: 1001
contractId: 1
side: ask
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 0
msg: OK
# 逐仓-限价开仓(冻结走逐仓冻结字段)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 2
marginRate: '0.01'
orderSourceType: 1
- code: 0
msg: OK
# 更低起始保证金率(5 倍杠杆)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.005'
orderSourceType: 1
- code: 0
msg: OK
creatOrderFalseTestdata:
# userId 非数值
- - userId: ''
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:userId"
# userId 特殊字符
- - userId: '!@#$'
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:userId"
# 用户不存在
- - userId: 9999
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1001
msg: 用户不存在
# 合约不存在
- - userId: 1001
contractId: 20
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1002
msg: 合约不存在
# side 非法枚举(数值)
- - userId: 1001
contractId: 1
side: 111
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:side"
# side 非法字符串
- - userId: 1001
contractId: 1
side: asdd
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:side"
# 价格为空
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: ''
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:price"
# 价格非正数
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: -1
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:price"
# 价格非数值
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: abc
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:price"
# 数量为 0
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 0
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:quantity"
# 委托类型非法
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 5
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:orderType"
# 保证金模式非法
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 3
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:marginType"
# 保证金率超上限(>1)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '2'
orderSourceType: 1
- code: 1003
msg: "参数错误:marginRate"
# 有效期非法
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 100
quantity: 10
orderType: 1
durationQualifiers: SDFSDF
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 1003
msg: "参数错误:durationQualifiers"
# 余额不足(冻结金额超过账户资金)
- - userId: 1001
contractId: 1
side: bid
positionEffect: 1
price: 99999999
quantity: 10
orderType: 1
durationQualifiers: GTC
marginType: 1
marginRate: '0.01'
orderSourceType: 1
- code: 2001
msg: 余额不足
+32
View File
@@ -0,0 +1,32 @@
# 合约公式层纯函数用例数据(数据驱动)
# 期望值均为 Decimal 精确结果;费率用合约参数(maker=0.0002, taker=0.0005)
frozenMargin:
- {price: 100, quantity: 10, margin_rate: '0.01', expected: '10.5'}
- {price: 100, quantity: 10, margin_rate: '0.005', expected: '5.5'}
- {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'}
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'}
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'}
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'}
isBurst:
# 恰好等于强平价:保证金余额 == 维持保证金,<= 即触发
- {side: bid, open_price: 100, mark_price: '90.5', quantity: 10, margin_rate: '0.1', maintain_rate: '0.005', extra_margin: '0', expected: true}
- {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}
+26
View File
@@ -0,0 +1,26 @@
# 强平场景用例数据(数据驱动)
# 每行一个场景:市价开仓(开仓时标记价 100)→ 设安全标记价(不触发)
# → 设触发标记价(触发强平)。期望的强平价/破产价由公式层独立计算。
liquidationScenarios:
# 做多 10 倍杠杆:强平价 90.5,破产价 90
- name: 做多-触及强平价触发
side: bid
quantity: 10
marginRate: '0.1'
safeMark: '91'
triggerMark: '90.5'
# 做空 10 倍杠杆:强平价 109.5,破产价 110
- name: 做空-触及强平价触发
side: ask
quantity: 10
marginRate: '0.1'
safeMark: '109'
triggerMark: '109.5'
# 做多且标记价跌破破产价:穿仓,缺口由风险基金兜底
- name: 做多-穿仓由风险基金兜底
side: bid
quantity: 10
marginRate: '0.1'
safeMark: '91'
triggerMark: '85'