# 下单接口用例数据(数据驱动) # 结构:[参数 dict, 期望 dict],与 @pytest.mark.parametrize("test_input,expected", ...) 按位解包 # 正例:限价开仓冻结保证金;负例:各类非法入参 + 余额不足 creatOrderTrueTestdata: # 全仓-限价-买入开仓 - - userId: 1001 contractId: 1 side: bid positionEffect: 1 price: 100 quantity: 10 orderType: 1 timeInForce: 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 timeInForce: 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 timeInForce: 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 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 非数值 - - userId: '' contractId: 1 side: bid positionEffect: 1 price: 100 quantity: 10 orderType: 1 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: 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 timeInForce: SDFSDF marginType: 1 marginRate: '0.01' orderSourceType: 1 - code: 1003 msg: "参数错误:timeInForce" # 余额不足(冻结金额超过账户资金) - - userId: 1001 contractId: 1 side: bid positionEffect: 1 price: 99999999 quantity: 10 orderType: 1 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: 余额不足