PDF下载 下载

交易函数

阅读 68969

order_volume - 按指定量委托

函数原型:

  1. order_volume(symbol, volume, side, order_type,position_effect, price=0,order_duration=OrderDuration_Unknown, order_qualifier=OrderQualifier_Unknown,account='')

参数:

参数名 类型 说明
symbol str 标的代码
volume int 数量(指股数)
side int 参见订单委托方向
order_type int 参见订单委托类型
position_effect int 参见开平仓类型
price float 价格(限价下单和科创板市价保护价是必填字段)
order_duration int 参见 委托时间属性
order_qualifier int 参见 委托成交属性
account account id or account name or None 帐户

返回值:

类型 说明
list[order] 委托对象列表,参见委托

示例:

  1. order_volume(symbol='SHSE.600000', volume=10000, side=OrderSide_Buy, order_type=OrderType_Limit, position_effect=PositionEffect_Open, price=11)

返回:

  1. [{'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000000', 'symbol': 'SHSE.600000', 'side': 1, 'position_effect': 1, 'position_side': 1, 'order_type': 1, 'status': 3, 'price': 11.0, 'order_style': 1, 'volume': 10000, 'value': 110000.0, 'percent': 5.5e-05, 'target_volume': 10000, 'target_value': 110000.0, 'target_percent': 5.5e-05, 'filled_volume': 10000, 'filled_vwap': 11.0011, 'filled_amount': 110010.99999999999, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 11.0011, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0}]

注意:

1.仅支持一个标的代码,若交易代码输入有误,终端会拒绝此单,并显示委托代码不正确

2.若下单数量输入有误,终端会拒绝此单,并显示委托量不正确。股票买入最小单位为100,卖出最小单位为1,如存在不足100股的持仓一次性卖出;期货买卖最小单位为1向下取整

3.若仓位不足,终端会拒绝此单,显示仓位不足。平仓时股票默认平昨仓,期货默认平今仓。应研究需要,股票也支持卖空操作

4.Order_type优先级高于price,若指定OrderType_Market下市价单,使用价格为最新一个tick中的最新价,price参数失效。则price参数失效。若OrderTpye_Limit限价单,仿真模式价格错误,终端拒绝此单,显示委托价格错误,回测模式下对价格无限制

5.输入无效参数报NameError错误,缺少参数报TypeError错误。

6.关于sideposition_effect字段的使用说明
做多(买开):side=OrderSide_Buy ,position_effect=PositionEffect_Open
平仓(卖平):side=OrderSide_Sell ,position_effect=PositionEffect_Close

做空(卖开):side=OrderSide_Sell ,position_effect=PositionEffect_Open
平仓(买平):side= OrderSide_Buy ,position_effect=PositionEffect_Close

order_value - 按指定价值委托

函数原型:

  1. order_value(symbol, value, side,order_type, position_effect, price=0, order_duration=OrderDuration_Unknown, order_qualifier=OrderQualifier_Unknown,account='')

参数:

参数名 类型 说明
symbol str 标的代码
value int 股票价值
side int 参见订单委托方向
order_type int 参见 订单委托类型
position_effect int 参见 开平仓类型
price float 价格(限价下单和科创板市价保护价是必填字段)
order_duration int 参见 委托时间属性
order_qualifier int 参见 委托成交属性
account account id or account name or None 帐户

返回值:

类型 说明
list[order] 委托对象列表,参见委托

示例:

下限价单,以11元每股的价格买入价值为100000的SHSE.600000,根据volume = value / price,计算并取整得到volume = 9000

  1. order_value(symbol='SHSE.600000', value=100000, price=11, side=OrderSide_Buy, order_type=OrderType_Limit, position_effect=PositionEffect_Open)

返回:

  1. [{'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000000', 'symbol': 'SHSE.600000', 'side': 1, 'position_effect': 1, 'position_side': 1, 'order_type': 1, 'status': 3, 'price': 11.0, 'order_style': 1, 'volume': 9000, 'value': 100000.0, 'percent': 5e-05, 'target_volume': 9000, 'target_value': 99000.0, 'target_percent': 4.95e-05, 'filled_volume': 9000, 'filled_vwap': 11.0011, 'filled_amount': 99009.9, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 9.90099, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0}]

注意:

1.仅支持一个标的代码,若交易代码输入有误,终端会拒绝此单,并显示委托代码不正确

2.根据指定价值计算购买标的数量,即value/price。股票买卖最小单位为100,不足100部分向下取整,如存在不足100的持仓一次性卖出;期货买卖最小单位为1向下取整

3.若仓位不足,终端会拒绝此单,显示仓位不足。平仓时股票默认平昨仓,期货默认平今仓。应研究需要,股票也支持卖空操作

4.Order_type优先级高于price,若指定OrderType_Market下市价单,计算使用价格为最新一个tick中的最新价,price参数失效。若OrderTpye_Limit限价单,仿真模式价格错误,终端拒绝此单,显示委托价格错误,回测模式下对价格无限制

5.输入无效参数报NameError错误,缺少参数报TypeError错误。

order_percent - 按总资产指定比例委托

函数原型:

  1. order_percent(symbol, percent, side,order_type, position_effect, price=0, order_duration=OrderDuration_Unknown, order_qualifier=OrderQualifier_Unknown, account='')

参数:

参数名 类型 说明
symbol str 标的代码
percent double 委托占总资产比例
side int 参见 订单委托方向
order_type int 参见 订单委托类型
position_effect int 参见 开平仓类型
price float 价格(限价下单和科创板市价保护价是必填字段)
order_duration int 参见 委托时间属性
order_qualifier int 参见 委托成交属性
account account id or account name or None 帐户

返回值:

类型 说明
list[order] 委托对象列表,参见委托

示例:

当前总资产为1000000。下限价单,以11元每股的价格买入SHSE.600000,期望买入比例占总资产的10%,根据volume = nav * precent / price 计算取整得出volume = 9000

  1. order_percent(symbol='SHSE.600000', percent=0.1, side=OrderSide_Buy, order_type=OrderType_Limit, position_effect=PositionEffect_Open, price=11)

返回:

  1. [{'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000000', 'symbol': 'SHSE.600000', 'side': 1, 'position_effect': 1, 'position_side': 1, 'order_type': 1, 'status': 3, 'price': 11.0, 'order_style': 1, 'volume': 18181800, 'value': 200000000.0, 'percent': 0.1, 'target_volume': 18181800, 'target_value': 199999800.0, 'target_percent': 0.0999999, 'filled_volume': 18181800, 'filled_vwap': 11.0011, 'filled_amount': 200019799.98, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 20001.979998, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0}]

注意:

1.仅支持一个标的代码,若交易代码输入有误,终端会拒绝此单,并显示委托代码不正确

2.根据指定比例计算购买标的数量,即(nav*precent)/price,股票买卖最小单位为100,不足100部分向下取整,如存在不足100的持仓一次性卖出;期货买卖最小单位为1向下取整

3.若仓位不足,终端会拒绝此单,显示仓位不足。平仓时股票默认平昨仓,期货默认平今仓。应研究需要,股票也支持卖空操作

4.Order_type优先级高于price,若指定OrderType_Market下市价单,计算使用价格为最新一个tick中的最新价,price参数失效。若OrderTpye_Limit限价单,仿真模式价格错误,终端拒绝此单,显示委托价格错误,回测模式下对价格无限制

5.输入无效参数报NameError错误,缺少参数报TypeError错误。

6.期货实盘时,percent是以合约上市的初始保证金比例计算得到的,并非实时保证金比例。

order_target_volume - 调仓到目标持仓量

函数原型:

  1. order_target_volume(symbol, volume, position_side, order_type, price=0, order_duration=OrderDuration_Unknown, order_qualifier=OrderQualifier_Unknown, account='')

参数:

参数名 类型 说明
symbol str 标的代码
volume int 期望的最终数量
position_side int 表示将多仓还是空仓调到目标持仓量,参见 持仓方向
order_type int 参见 订单类型
price float 价格(限价下单和科创板市价保护价是必填字段)
order_duration int 参见 委托时间属性
order_qualifier int 参见 委托成交属性
account account id or account name or None 帐户

返回值:

类型 说明
list[order] 委托对象列表,参见委托

示例:

当前SHSE.600000多方向持仓量为0,期望持仓量为10000,下单量为期望持仓量 - 当前持仓量 = 10000

  1. order_target_volume(symbol='SHSE.600000', volume=10000, position_side=PositionSide_Long, order_type=OrderType_Limit, price=13)

返回:

  1. [{'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000000', 'symbol': 'SHSE.600000', 'side': 1, 'position_effect': 1, 'position_side': 1, 'order_type': 1, 'status': 3, 'price': 13.0, 'order_style': 1, 'volume': 10000, 'value': 130000.0, 'percent': 6.5e-05, 'target_volume': 10000, 'target_value': 130000.0, 'target_percent': 6.5e-05, 'filled_volume': 10000, 'filled_vwap': 13.0013, 'filled_amount': 130013.0, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 13.0013, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0}]

注意:

1.仅支持一个标的代码,若交易代码输入有误,订单会被拒绝,终端无显示,无回报。回测模式可参看order_reject_reason。

2.根据目标数量计算下单数量,系统判断开平仓类型。若下单数量有误,终端拒绝此单,并显示委托量不正确。若实际需要买入数量为0,则订单会被拒绝,终端无显示,无回报。股票买卖最小单位为100,不足100部分向下取整,如存在不足100的持仓一次性卖出;期货买卖最小单位为1向下取整

3.若仓位不足,终端拒绝此单,显示仓位不足。平仓时股票默认平昨仓,期货默认平今仓,上期所昨仓不能平掉。应研究需要,股票也支持卖空操作。

4.Order_type优先级高于price,若指定OrderTpye_Market下市价单,使用价格为最新一个tick中的最新价,price参数失效。若OrderTpye_Limit限价单价格错误,终端拒绝此单,显示委托价格错误。回测模式下对价格无限制

5.输入无效参数报NameError错误,缺少参数报Typeerror错误。

order_target_value - 调仓到目标持仓额

函数原型:

  1. order_target_value(symbol, value, position_side, order_type, price=0, order_duration=OrderDuration_Unknown, order_qualifier=OrderQualifier_Unknown, account='')

参数:

参数名 类型 说明
symbol str 标的代码
value int 期望的股票最终价值
position_side int 表示将多仓还是空仓调到目标持仓额,参见持仓方向
order_type int 参见订单类型
price float 价格(限价下单和科创板市价保护价是必填字段)
order_duration int 参见 委托时间属性
order_qualifier int 参见 委托成交属性
account account id or account name or None 帐户

返回值:

类型 说明
list[order] 委托对象列表,参见委托

示例:

当前SHSE.600000多方向当前持仓量为0,目标持有价值为100000的该股票,根据value / price 计算取整得出目标持仓量volume为9000,目标持仓量 - 当前持仓量 = 下单量为9000

  1. order_target_value(symbol='SHSE.600000', value=100000, position_side=PositionSide_Long, order_type=OrderType_Limit, price=11)

返回:

  1. [{'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000000', 'symbol': 'SHSE.600000', 'side': 1, 'position_effect': 1, 'position_side': 1, 'order_type': 1, 'status': 3, 'price': 11.0, 'order_style': 1, 'volume': 9000, 'value': 100000.0, 'percent': 5e-05, 'target_volume': 9000, 'target_value': 100000.0, 'target_percent': 5e-05, 'filled_volume': 9000, 'filled_vwap': 11.0011, 'filled_amount': 99009.9, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 9.90099, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0}]

注意:

1.仅支持一个标的代码,若交易代码输入有误,订单会被拒绝,终端无显示,无回报。回测模式可参看order_reject_reason。

2.根据目标价值计算下单数量,系统判断开平仓类型。若下单数量有误,终端拒绝此单,并显示委托量不正确。若实际需要买入数量为0,则本地拒绝此单,终端无显示,无回报。股票买卖最小单位为100,不足100部分向下取整,如存在不足100的持仓一次性卖出;期货买卖最小单位为1向下取整

3.若仓位不足,终端拒绝此单,显示仓位不足。平仓时股票默认平昨仓,期货默认平今仓,目前不可修改。应研究需要,股票也支持卖空操作

4.Order_type优先级高于price,若指定OrderType_Market下市价单,计算使用价格为最新一个tick中的最新价,price参数失效。若OrderTpye_Limit限价单价格错误,终端拒绝此单,显示委托价格错误。回测模式下对价格无限制

5.输入无效参数报NameError错误,缺少参数报Typeerror错误。

order_target_percent - 调仓到目标持仓比例(总资产的比例)

函数原型:

  1. order_target_percent(symbol, percent, position_side, order_type, price=0, order_duration=OrderDuration_Unknown, order_qualifier=OrderQualifier_Unknown, account='')

参数:

参数名 类型 说明
symbol str 标的代码
percent double 期望的最终占总资产比例
position_side int 表示将多仓还是空仓调到目标持仓比例,参见持仓方向
order_type int 参见订单类型
order_duration int 参见 委托时间属性
order_qualifier int 参见 委托成交属性
price float 价格(限价下单和科创板市价保护价是必填字段)
account account id or account name or None 帐户

返回值:

类型 说明
list[order] 委托对象列表,参见委托

示例:

当前总资产价值为1000000,目标为以11元每股的价格买入SHSE.600000的价值占总资产的10%,根据volume = nav * percent / price 计算取整得出应持有9000股。当前该股持仓量为零,因此买入量为9000

  1. order_target_percent(symbol='SHSE.600000', percent=0.1, position_side=PositionSide_Long, order_type=OrderType_Limit, price=11)

返回:

  1. [{'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000000', 'symbol': 'SHSE.600000', 'side': 1, 'position_effect': 1, 'position_side': 1, 'order_type': 1, 'status': 3, 'price': 11.0, 'order_style': 1, 'volume': 18181800, 'value': 200000000.0, 'percent': 0.1, 'target_volume': 18181800, 'target_value': 199999800.0, 'target_percent': 0.1, 'filled_volume': 18181800, 'filled_vwap': 11.0011, 'filled_amount': 200019799.98, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 20001.979998, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0}]

注意:

1.仅支持一个标的代码,若交易代码输入有误,订单会被拒绝,终端无显示,无回报。回测模式可参看order_reject_reason。

2.根据目标比例计算下单数量,为占总资产(nav)比例,系统判断开平仓类型。若下单数量有误,终端拒绝此单,并显示委托量不正确。若实际需要买入数量为0,则本地拒绝此单,终端无显示,无回报。股票买卖最小单位为100,不足100部分向下取整,如存在不足100的持仓一次性卖出;期货买卖最小单位为1向下取整

3.若仓位不足,终端拒绝此单,显示仓位不足。平仓时股票默认平昨仓,期货默认平今仓,目前不可修改。应研究需要,股票也支持卖空操作

4.Order_type优先级高于price,若指定OrderType_Market下市价单,计算使用价格为最新一个tick中的最新价,price参数失效。若OrderTpye_Limit限价单价格错误,终端拒绝此单,显示委托价格错误。回测模式下对价格无限制

5.输入无效参数报NameError错误,缺少参数报Typeerror错误。

6.期货实盘时,percent是以合约上市的初始保证金比例计算得到的,并非实时保证金比例。

order_batch - 批量委托接口

函数原型:

  1. order_batch(orders, combine=False, account='')

参数:

参数名 类型 说明
orders list[order] 委托对象列表,其中委托至少包含交易接口的必选参数,参见委托
combine bool 是否是组合单, 默认不是(预留字段,目前无效)
account account id or account name or None 帐户

返回值:

类型 说明
list[order] 委托对象列表,参见委托

示例:

  1. order_1 = {'symbol': 'SHSE.600000', 'volume': 100, 'price': 11, 'side': 1,
  2. 'order_type': 2, 'position_effect':1}
  3. order_2 = {'symbol': 'SHSE.600004', 'volume': 100, 'price': 11, 'side': 1,
  4. 'order_type': 2, 'position_effect':1}
  5. orders = [order_1, order_2]
  6. batch_orders = order_batch(orders, combine=True)
  7. for order in batch_orders:
  8. print(order)

返回:

  1. {'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000000', 'symbol': 'SHSE.600000', 'side': 1, 'position_effect': 1, 'order_type': 2, 'status': 3, 'price': 10.280000686645508, 'order_style': 1, 'volume': 100, 'filled_volume': 100, 'filled_vwap': 10.281028686714173, 'filled_amount': 1028.1028686714174, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 0.10281028686714173, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'position_side': 0, 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0, 'value': 0.0, 'percent': 0.0, 'target_volume': 0, 'target_value': 0.0, 'target_percent': 0.0}
  2. {'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000001', 'symbol': 'SHSE.600004', 'side': 1, 'position_effect': 1, 'order_type': 2, 'status': 3, 'price': 15.050000190734863, 'order_style': 1, 'volume': 100, 'filled_volume': 100, 'filled_vwap': 15.051505190753936, 'filled_amount': 1505.1505190753935, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 0.15051505190753936, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'position_side': 0, 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0, 'value': 0.0, 'percent': 0.0, 'target_volume': 0, 'target_value': 0.0, 'target_percent': 0.0}
  3. {'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000002', 'symbol': 'SHSE.600000', 'side': 1, 'position_effect': 1, 'order_type': 2, 'status': 3, 'price': 10.180000305175781, 'order_style': 1, 'volume': 100, 'filled_volume': 100, 'filled_vwap': 10.1810183052063, 'filled_amount': 1018.10183052063, 'created_at': datetime.datetime(2020, 9, 2, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 2, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 0.101810183052063, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'position_side': 0, 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0, 'value': 0.0, 'percent': 0.0, 'target_volume': 0, 'target_value': 0.0, 'target_percent': 0.0}
  4. {'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000003', 'symbol': 'SHSE.600004', 'side': 1, 'position_effect': 1, 'order_type': 2, 'status': 3, 'price': 14.819999694824219, 'order_style': 1, 'volume': 100, 'filled_volume': 100, 'filled_vwap': 14.8214816947937, 'filled_amount': 1482.14816947937, 'created_at': datetime.datetime(2020, 9, 2, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 2, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 0.148214816947937, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'position_side': 0, 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0, 'value': 0.0, 'percent': 0.0, 'target_volume': 0, 'target_value': 0.0, 'target_percent': 0.0}

注意:

1.每个order的symbol仅支持一个标的代码,若交易代码输入有误,终端会拒绝此单,并显示委托代码不正确

2.若下单数量输入有误,终端会拒绝此单,并显示委托量不正确下单数量严格按照指定数量下单,需注意股票买入最小单位为100。

3.若仓位不足,终端会拒绝此单,显示仓位不足。应研究需要,股票也支持卖空操作

4.Order_type优先级高于price,若指定OrderType_Market下市价单,则price参数失效。若OrderTpye_Limit限价单,仿真模式价格错误,终端拒绝此单,显示委托价格错误,回测模式下对价格无限制

5.输入无效参数报NameError错误,缺少参数不报错,可能会出现下单被拒。

order_cancel - 撤销委托

函数原型:

  1. order_cancel(wait_cancel_orders)

参数:

参数名 类型 说明
wait_cancel_orders list[dict] 传入单个字典. 或者list字典. 每个字典包含key: cl_ord_id, account_id, 参见委托

示例:

  1. order_1 = {'cl_ord_id': order1['cl_ord_id'], 'account_id': order1['account_id']}
  2. order_2 = {'cl_ord_id': order2['cl_ord_id'], 'account_id': order2['account_id']}
  3. orders = [order_1, order_2]
  4. order_cancel(wait_cancel_orders=orders)

order_cancel_all - 撤销所有委托

函数原型:

  1. order_cancel_all()

示例:

  1. order_cancel_all()

order_close_all - 平当前所有可平持仓

注意:不支持市价委托类型的委托,会被柜台拒绝

函数原型:

  1. order_close_all()

示例:

  1. order_close_all()

get_unfinished_orders - 查询日内全部未结委托

函数原型:

  1. get_unfinished_orders()

返回值:

类型 说明
list[order] 委托对象列表,参见委托

示例:

  1. get_unfinished_orders()

返回:

  1. [{'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000000', 'symbol': 'SHSE.600519', 'side': 1, 'position_effect': 1, 'position_side': 1, 'order_type': 2, 'status': 3, 'price': 1792.0, 'order_style': 1, 'volume': 100, 'value': 179200.0, 'percent': 8.96e-05, 'target_volume': 100, 'target_value': 179200.0, 'target_percent': 8.96e-05, 'filled_volume': 100, 'filled_vwap': 1792.1792, 'filled_amount': 179217.92, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 17.921792000000003, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0}]

get_orders - 查询日内全部委托

函数原型:

  1. get_orders()

返回值:

类型 说明
list[order] 委托对象列表,参见委托

示例:

  1. get_orders()

返回:

  1. [{'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000000', 'symbol': 'SHSE.600519', 'side': 1, 'position_effect': 1, 'position_side': 1, 'order_type': 2, 'status': 3, 'price': 1792.0, 'order_style': 1, 'volume': 100, 'value': 179200.0, 'percent': 8.96e-05, 'target_volume': 100, 'target_value': 179200.0, 'target_percent': 8.96e-05, 'filled_volume': 100, 'filled_vwap': 1792.1792, 'filled_amount': 179217.92, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 17.921792000000003, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0}]

get_execution_reports - 查询日内全部执行回报

函数原型:

  1. get_execution_reports()

返回值:

类型 说明
list[execrpt] 回报对象列表, 参见成交回报

示例:

  1. get_execution_reports()

返回:

  1. [{'strategy_id': '004beb61-1282-11eb-9313-00ff5a669ee2', 'account_id': '3acc8b6e-af54-11e9-b2de-00163e0a4100', 'account_name': '3acc8b6e-af54-11e9-b2de-00163e0a4100', 'cl_ord_id': '49764a82-14fb-11eb-89df-00ff5a669ee2', 'order_id': '4a06f925-14fb-11eb-9e8a-00163e0a4100', 'exec_id': '573b108b-14fb-11eb-9e8a-00163e0a4100', 'symbol': 'SHSE.600714', 'position_effect': 1, 'side': 1, 'exec_type': 15, 'price': 5.579999923706055, 'volume': 900, 'amount': 5021.999931335449, 'created_at': datetime.datetime(2020, 10, 23, 14, 45, 29, 776756, tzinfo=tzfile('PRC')), 'commission': 5.0, 'cost': 5021.999931335449, 'ord_rej_reason': 0, 'ord_rej_reason_detail': ''}]
1 篇笔记
  • 拉链77 2019-03-16 12:11:57