首页
数据字典 (opens new window)
  • 内置Python
  • 原生Python
  • VBA
投研服务平台 (opens new window)
迅投官网 (opens new window)

    暂无数据

    策略服务 (opens new window) 迅投知识库 迅投知识库
    首页
    数据字典 (opens new window)
    • 内置Python
    • 原生Python
    • VBA
    投研服务平台 (opens new window)
    迅投官网 (opens new window)
      • XtQuant.简介

      • XtQuant.XtData 行情模块

      • XtQuant.Xttrader 交易模块

        • 版本信息
        • 快速上手
        • 接口说明
          • XtQuant API说明
            • 系统设置接口
            • 创建API实例
            • 注册回调类
            • 准备API环境
            • 创建连接
            • 停止运行
            • 阻塞当前线程进入等待状态
            • 开启主动请求接口的专用线程
            • 操作接口
            • 订阅账号信息
            • 反订阅账号信息
            • 同步查询账号状态
            • 异步查询账号状态
            • 股票同步报单
            • 股票异步报单
            • 股票同步撤单
            • 股票同步撤单
            • 股票异步撤单
            • 股票异步撤单
            • 股票查询接口
            • 资产查询
            • 委托查询
            • 成交查询
            • 持仓查询
            • 信用查询接口
            • 信用资产查询
            • 负债合约查询
            • 融资融券标的查询
            • 可融券数据查询
            • 标的担保品查询
            • 其他查询接口
            • 新股申购额度查询
            • 当日新股信息查询
            • 账号信息查询
            • 约券相关接口
            • 券源费率信息查询
            • 约券异步报单
            • 约券合约信息查询
            • 回调类
            • 连接状态回调
            • 账号状态信息推送
            • 资产信息推送
            • 委托信息推送
            • 成交信息推送
            • 持仓信息推送
            • 下单失败信息推送
            • 撤单失败信息推送
            • 异步下单回报推送
            • 异步约券回报推送
        • 附录
      • XtQuant交易示例
      • 常见问题Q&A
      • XtQuant版本下载
      ×
      当前文档查询 “ ” 关键字 0 个
      0/0
      • 原生Python
      • XtQuant.Xttrader 交易模块
      RZRK
      2022-08-16
      目录

      接口说明

      ×

      # XtQuant API说明

      # 系统设置接口

      # 创建API实例

      XtQuantTrader(path, session_id)
      
      1
      • 释义
        • 创建XtQuant API的实例
      • 参数
        • path - str MiniQMT客户端userdata_mini的完整路径
        • session_id - int 与MiniQMT通信的会话ID,不同的会话要保证不重
      • 返回
        • XtQuant API实例对象
      • 备注
        • 后续对XtQuant API的操作都需要该实例对象
        • 通常情况下只需要创建一个XtQuant API实例
      • 示例
      path = 'D:\\迅投极速交易终端 睿智融科版\\userdata_mini'
      # session_id为会话编号,策略使用方对于不同的Python策略需要使用不同的会话编号
      session_id = 123456
      #后续的所有示例将使用该实例对象
      xt_trader = XtQuantTrader(path, session_id)
      
      1
      2
      3
      4
      5

      # 注册回调类

      register_callback(callback)
      
      1
      • 释义
        • 将回调类实例对象注册到API实例中,用以消息回调和主推
      • 参数
        • callback - XtQuantTraderCallback 回调类实例对象
      • 返回
        • 无
      • 备注
        • 无
      • 示例
      # 创建交易回调类对象,并声明接收回调
      class MyXtQuantTraderCallback(XtQuantTraderCallback):
      	...
      	pass
      callback = MyXtQuantTraderCallback()
      #xt_trader为XtQuant API实例对象
      xt_trader.register_callback(callback)
      
      1
      2
      3
      4
      5
      6
      7

      # 准备API环境

      start()
      
      1
      • 释义
        • 启动交易线程,准备交易所需的环境
      • 参数
        • 无
      • 返回
        • 无
      • 备注
        • 无
      • 示例
      # 启动交易线程
      #xt_trader为XtQuant API实例对象
      xt_trader.start()
      
      1
      2
      3

      # 创建连接

      connect()
      
      1
      • 释义
        • 连接MiniQMT
      • 参数
        • 无
      • 返回
        • 连接结果信息,连接成功返回0,失败返回非0
      • 备注
        • 该连接为一次性连接,断开连接后不会重连,需要再次主动调用
      • 示例
      # 建立交易连接,返回0表示连接成功
      #xt_trader为XtQuant API实例对象
      connect_result = xt_trader.connect()
      print(connect_result)
      
      1
      2
      3
      4

      # 停止运行

      stop()
      
      1
      • 释义
        • 停止API接口
      • 参数
        • 无
      • 返回
        • 无
      • 备注
        • 无
      • 示例
      #xt_trader为XtQuant API实例对象
      xt_trader.stop()
      
      1
      2

      # 阻塞当前线程进入等待状态

      run_forever()
      
      1
      • 释义
        • 阻塞当前线程,进入等待状态,直到stop函数被调用结束阻塞
      • 参数
        • 无
      • 返回
        • 无
      • 备注
        • 无
      • 示例
      #xt_trader为XtQuant API实例对象
      xt_trader.run_forever()
      
      1
      2

      # 开启主动请求接口的专用线程

      set_relaxed_response_order_enabled(enabled)
      
      1
      • 释义

        • 控制主动请求接口的返回是否从额外的专用线程返回,以获得宽松的数据时序
        • 不开启(enabled=False)效果:在on_stock_xxx回调函数里调用XtQuantTrader.query_xxx函数会造成回调线程卡住,后续回调会接收不到
        • 开启效果(enabled=True)效果:在on_stock_xxx回调函数里调用XtQuantTrader.query_xxx函数不会卡住回调线程,但是查询和推送的数据在时序上会变得不确定,参考下面的备注说明
      • 参数

        • enabled - bool 是否开启,默认为False关闭
      • 返回

        • 无
      • 备注

        • 如果开启,在on_stock_order等推送回调中调用同步请求不会卡住,但查询和推送的数据在时序上会变得不确定

        • timeline 	t1		t2		t3		t4
          callback	push1	push2	push3	resp4
          do 			query4 ------------------^
          
          1
          2
          3
        • 例如:分别在t1 t2 t3时刻到达三条委托数据,在on_push1中调用同步委托查询接口query_orders()

        • 未开启宽松时序时,查询返回resp4会在t4时刻排队到push3完成之后处理,这使得同步等待结果的查询不能返回而卡住执行

        • 开启宽松时序时,查询返回的resp4由专用线程返回,程序正常执行,但此时查到的resp4是push3之后的状态,也就是说resp4中的委托要比push2 push3这两个前一时刻推送的数据新,但在更早的t1时刻就进入了处理

        • 使用中请根据策略实际情况来开启,通常情况下,推荐在on_stock_order等推送回调中使用查询接口的异步版本,如query_stock_orders_async

      # 操作接口

      # 订阅账号信息

      subscribe(account)
      
      1
      • 释义
        • 订阅账号信息,包括资金账号、委托信息、成交信息、持仓信息
      • 参数
        • account - StockAccount 资金账号
      • 返回
        • 订阅结果信息,订阅成功返回True,订阅失败返回False
      • 备注
        • 无
      • 示例
        • 订阅资金账号1000000365
      account = StockAccount('1000000365')
      #xt_trader为XtQuant API实例对象
      order_id = xt_trader.subscribe(account)
      
      1
      2
      3

      # 反订阅账号信息

      unsubscribe(account)
      
      1
      • 释义
        • 反订阅账号信息
      • 参数
        • account - StockAccount 资金账号
      • 返回
        • 反订阅结果信息,订阅成功返回True,订阅失败返回False
      • 备注
        • 无
      • 示例
        • 订阅资金账号1000000365
      account = StockAccount('1000000365')
      #xt_trader为XtQuant API实例对象
      order_id = xt_trader.unsubscribe(account)
      
      1
      2
      3

      # 同步查询账号状态

      query_account_status()
      
      1
      • 释义
        • 同步接口,查询账号状态
      • 参数
        • 无
      • 返回
        • 由xttype.XtAccountStatus组成的list
      • 备注
        • 无
      • 示例
        • 查询客户端账号状态
      #xt_trader为XtQuant API实例对象
      account_status = xt_trader.query_account_status()
      for acc in account_status:
          print(account_status.account_id, account_status.status)
      
      1
      2
      3
      4

      # 异步查询账号状态

      query_account_status_async(callback)
      
      1
      • 释义
        • 查询账号状态,通过指定callback回调函数获取账号状态信息
      • 参数
        • callback(account_status_list) - python函数,用于异步接账号状态, callback函数需要定义一个位置参数用于接收接口返回结果
        • ccount_status_list: 由xttype.XtAccountStatus组成的list
      • 返回
        • 查询号
      • 备注
        • 无
      • 示例
        • 查询客户端账号状态
      #xt_trader为XtQuant API实例对象
      def cb(account_status_list):
          for acc in account_status_list:
              print(acc.status, acc.account_id, acc.account_type)
      xt_trader.query_account_status_async(cb)
      
      1
      2
      3
      4
      5

      # 股票同步报单

      order_stock(account, stock_code, order_type, order_volume, price_type, price, strategy_name, order_remark)
      
      1
      • 释义
        • 对股票进行下单操作
      • 参数
        • account - StockAccount 资金账号
        • stock_code - str 证券代码,如'600000.SH'
        • order_type - int 委托类型
        • order_volume - int 委托数量,股票以'股'为单位,债券以'张'为单位
        • price_type - int 报价类型
        • price - float 委托价格
        • strategy_name - str 策略名称
        • order_remark - str 委托备注
      • 返回
        • 系统生成的订单编号,成功委托后的订单编号为大于0的正整数,如果为-1表示委托失败
      • 备注
        • 无
      • 示例
        • 股票资金账号1000000365对浦发银行买入1000股,使用限价价格10.5元, 委托备注为'order_test'
      account = StockAccount('1000000365')
      #xt_trader为XtQuant API实例对象
      order_id = xt_trader.order_stock(account, '600000.SH', xtconstant.STOCK_BUY, 1000, xtconstant.FIX_PRICE, 10.5, 'strategy1', 'order_test')
      
      1
      2
      3

      # 股票异步报单

      order_stock_async(account, stock_code, order_type, order_volume, price_type, price, strategy_name, order_remark)
      
      1
      • 释义
        • 对股票进行异步下单操作,异步下单接口如果正常返回了下单请求序号seq,会收到on_order_stock_async_response的委托反馈
      • 参数
        • account - StockAccount 资金账号
        • stock_code - str 证券代码, 如'600000.SH'
        • order_type - int 委托类型
        • order_volume - int 委托数量,股票以'股'为单位,债券以'张'为单位
        • price_type - int 报价类型
        • price - float 委托价格
        • strategy_name - str 策略名称
        • order_remark - str 委托备注
      • 返回
        • 返回下单请求序号seq,成功委托后的下单请求序号为大于0的正整数,如果为-1表示委托失败
      • 备注
        • 如果失败,则通过下单失败主推接口返回下单失败信息
      • 示例
        • 股票资金账号1000000365对浦发银行买入1000股,使用限价价格10.5元,委托备注为'order_test'
      account = StockAccount('1000000365')
      #xt_trader为XtQuant API实例对象
      seq = xt_trader.order_stock_async(account, '600000.SH', xtconstant.STOCK_BUY, 1000, xtconstant.FIX_PRICE, 10.5, 'strategy1', 'order_test')
      
      1
      2
      3

      # 股票同步撤单

      cancel_order_stock(account, order_id)
      
      1
      • 释义
        • 根据订单编号对委托进行撤单操作
      • 参数
        • account - StockAccount 资金账号
        • order_id - int 同步下单接口返回的订单编号
      • 返回
        • 返回是否成功发出撤单指令,0: 成功, -1: 表示撤单失败
      • 备注
        • 无
      • 示例
        • 股票资金账号1000000365对订单编号为order_id的委托进行撤单
      account = StockAccount('1000000365')
      order_id = 100
      #xt_trader为XtQuant API实例对象
      cancel_result = xt_trader.cancel_order_stock(account, order_id)
      
      1
      2
      3
      4

      # 股票同步撤单

      cancel_order_stock_sysid(account, market, order_sysid)
      
      1
      • 释义
        • 根据券商柜台返回的合同编号对委托进行撤单操作
      • 参数
        • account - StockAccount 资金账号
        • market - int 交易市场
        • order_sysid - str 券商柜台的合同编号
      • 返回
        • 返回是否成功发出撤单指令,0: 成功, -1: 表示撤单失败
      • 备注
        • 无
      • 示例
        • 股票资金账号1000000365对柜台合同编号为order_sysid的上交所委托进行撤单
      account = StockAccount('1000000365')
      market = xtconstant.SH_MARKET
      order_sysid = "100" 
      #xt_trader为XtQuant API实例对象
      cancel_result = xt_trader.cancel_order_stock_sysid(account, market, order_sysid)
      
      1
      2
      3
      4
      5

      # 股票异步撤单

      cancel_order_stock_async(account, order_id)
      
      1
      • 释义
        • 根据订单编号对委托进行异步撤单操作
      • 参数
        • account - StockAccount 资金账号
        • order_id - int 下单接口返回的订单编号
      • 返回
        • 返回撤单请求序号, 成功委托后的撤单请求序号为大于0的正整数, 如果为-1表示委托失败
      • 备注
        • 如果失败,则通过撤单失败主推接口返回撤单失败信息
      • 示例
        • 股票资金账号1000000365对订单编号为order_id的委托进行异步撤单
      account = StockAccount('1000000365')
      order_id = 100
      #xt_trader为XtQuant API实例对象
      cancel_result = xt_trader.cancel_order_stock_async(account, order_id)
      
      1
      2
      3
      4

      # 股票异步撤单

      cancel_order_stock_sysid_async(account, market, order_sysid)
      
      1
      • 释义
        • 根据券商柜台返回的合同编号对委托进行异步撤单操作
      • 参数
        • account - StockAccount 资金账号
        • market - int 交易市场
        • order_sysid - str 券商柜台的合同编号
      • 返回
        • 返回撤单请求序号, 成功委托后的撤单请求序号为大于0的正整数, 如果为-1表示委托失败
      • 备注
        • 如果失败,则通过撤单失败主推接口返回撤单失败信息
      • 示例
        • 股票资金账号1000000365对柜台合同编号为order_sysid的上交所委托进行异步撤单
      account = StockAccount('1000000365')
      market = xtconstant.SH_MARKET
      order_sysid = "100" 
      #xt_trader为XtQuant API实例对象
      cancel_result = xt_trader.cancel_order_stock_sysid_async(account, market, order_sysid)
      
      1
      2
      3
      4
      5

      # 股票查询接口

      # 资产查询

      query_stock_asset(account)
      
      1
      • 释义
        • 查询资金账号对应的资产
      • 参数
        • account - StockAccount 资金账号
      • 返回
        • 该账号对应的资产对象XtAsset或者None
      • 备注
        • 返回None表示查询失败
      • 示例
        • 查询股票资金账号1000000365对应的资产数据
      account = StockAccount('1000000365')
      #xt_trader为XtQuant API实例对象
      asset = xt_trader.query_stock_asset(account)
      
      1
      2
      3

      # 委托查询

      query_stock_orders(account, cancelable_only = False)
      
      1
      • 释义
        • 查询资金账号对应的当日所有委托
      • 参数
        • account - StockAccount 资金账号
        • cancelable_only - bool 仅查询可撤委托
      • 返回
        • 该账号对应的当日所有委托对象XtOrder组成的list或者None
      • 备注
        • None表示查询失败或者当日委托列表为空
      • 示例
        • 查询股票资金账号1000000365对应的当日所有委托
      account = StockAccount('1000000365')
      #xt_trader为XtQuant API实例对象
      orders = xt_trader.query_stock_orders(account, False)
      
      1
      2
      3

      # 成交查询

      query_stock_trades(account)
      
      1
      • 释义
        • 查询资金账号对应的当日所有成交
      • 参数
        • account - StockAccount 资金账号
      • 返回
        • 该账号对应的当日所有成交对象XtTrade组成的list或者None
      • 备注
        • None表示查询失败或者当日成交列表为空
      • 示例
        • 查询股票资金账号1000000365对应的当日所有成交
      account = StockAccount('1000000365')
      #xt_trader为XtQuant API实例对象
      trades = xt_trader.query_stock_trades(account)
      
      1
      2
      3

      # 持仓查询

      query_stock_positions(account)
      
      1
      • 释义
        • 查询资金账号对应的持仓
      • 参数
        • account - StockAccount 资金账号
      • 返回
        • 该账号对应的最新持仓对象XtPosition组成的list或者None
      • 备注
        • None表示查询失败或者当日持仓列表为空
      • 示例
        • 查询股票资金账号1000000365对应的最新持仓
      account = StockAccount('1000000365')
      #xt_trader为XtQuant API实例对象
      positions = xt_trader.query_stock_positions(account)
      
      1
      2
      3

      # 信用查询接口

      # 信用资产查询

      query_credit_detail(account)
      
      1
      • 释义
        • 查询信用资金账号对应的资产
      • 参数
        • account - StockAccount 资金账号
      • 返回
        • 该信用账户对应的资产对象XtCreditDetail组成的list或者None
      • 备注
        • None表示查询失败
        • 通常情况下一个资金账号只有一个详细信息数据
      • 示例
        • 查询信用资金账号1208970161对应的资产信息
      account = StockAccount('1208970161', 'CREDIT')
      #xt_trader为XtQuant API实例对象
      datas = xt_trader.query_credit_detail(account)
      
      1
      2
      3

      # 负债合约查询

      query_stk_compacts(account)
      
      1
      • 释义
        • 查询资金账号对应的负债合约
      • 参数
        • account - StockAccount 资金账号
      • 返回
        • 该账户对应的负债合约对象StkCompacts组成的list或者None
      • 备注
        • None表示查询失败或者负债合约列表为空
      • 示例
        • 查询信用资金账号1208970161对应的负债合约
      account = StockAccount('1208970161', 'CREDIT')
      #xt_trader为XtQuant API实例对象
      datas = xt_trader.query_stk_compacts(account)
      
      1
      2
      3

      # 融资融券标的查询

      query_credit_subjects(account)
      
      1
      • 释义
        • 查询资金账号对应的融资融券标的
      • 参数
        • account - StockAccount 资金账号
      • 返回
        • 该账户对应的融资融券标的对象CreditSubjects组成的list或者None
      • 备注
        • None表示查询失败或者融资融券标的列表为空
      • 示例
        • 查询信用资金账号1208970161对应的融资融券标的
      account = StockAccount('1208970161', 'CREDIT')
      #xt_trader为XtQuant API实例对象
      datas = xt_trader.query_credit_subjects(account)
      
      1
      2
      3

      # 可融券数据查询

      query_credit_slo_code(account)
      
      1
      • 释义
        • 查询资金账号对应的可融券数据
      • 参数
        • account - StockAccount 资金账号
      • 返回
        • 该账户对应的可融券数据对象CreditSloCode组成的list或者None
      • 备注
        • None表示查询失败或者可融券数据列表为空
      • 示例
        • 查询信用资金账号1208970161对应的可融券数据
      account = StockAccount('1208970161', 'CREDIT')
      #xt_trader为XtQuant API实例对象
      datas = xt_trader.query_credit_slo_code(account)
      
      1
      2
      3

      # 标的担保品查询

      query_credit_assure(account)
      
      1
      • 释义
        • 查询资金账号对应的标的担保品
      • 参数
        • account - StockAccount 资金账号
      • 返回
      • 该账户对应的标的担保品对象CreditAssure组成的list或者None
      • 备注
        • None表示查询失败或者标的担保品列表为空
      • 示例
        • 查询信用资金账号1208970161对应的标的担保品
      account = StockAccount('1208970161', 'CREDIT')
      #xt_trader为XtQuant API实例对象
      datas = xt_trader.query_credit_assure(account)
      
      1
      2
      3

      # 其他查询接口

      # 新股申购额度查询

      query_new_purchase_limit(account)
      
      1
      • 释义
        • 查询新股申购额度
      • 参数
        • account - StockAccount 资金账号
      • 返回
        • dict 新股申购额度数据集
          • { type1: number1, type2: number2, ... }
            • type - str 品种类型
              • KCB - 科创板,SH - 上海,SZ - 深圳
            • number - int 可申购股数
      • 备注
        • 数据仅代表股票申购额度,债券的申购额度固定10000张

      # 当日新股信息查询

      query_ipo_data()
      
      1
      • 释义

        • 查询当日新股新债信息
      • 参数

        • 无
      • 返回

        • dict 新股新债信息数据集

          • { stock1: info1, stock2: info2, ... }

            • stock - str 品种代码,例如 '301208.SZ'
            • info - dict 新股信息
              • name - str 品种名称
              • type - str 品种类型
                • STOCK - 股票,BOND - 债券
              • minPurchaseNum / maxPurchaseNum - int 最小 / 最大申购额度
                • 单位为股(股票)/ 张(债券)
              • purchaseDate - str 申购日期
              • issuePrice - float 发行价
          • 返回值示例

            {'754810.SH': {'name': '丰山发债', 'type': 'BOND', 'maxPurchaseNum': 10000, 'minPurchaseNum': 10, 'purchaseDate': '20220627', 'issuePrice': 100.0}, '301208.SZ': {'name': '中亦科技', 'type': 'STOCK', 'maxPurchaseNum': 16500, 'minPurchaseNum': 500, 'purchaseDate': '20220627', 'issuePrice': 46.06}}
            
            1
      • 备注

        • 无

      # 账号信息查询

      query_account_infos()
      
      1
      • 释义

        • 查询所有资金账号
      • 参数

        • 无
      • 返回

        • list 账号信息列表

          • [ XtAccountInfo ]
      • 备注

        • 无

      # 约券相关接口

      # 券源费率信息查询

      query_smt_secu_rate
      
      1
      • 释义

        • 查询券源费率信息
      • 参数

        • account - StockAccount 资金账号
      • 返回

        • dict 券源费率信息数据集

          • { stock1: info1, stock2: info2, ... }

            • stock - str 证券代码,例如 '600000.SH'
            • info - dict 券源费率信息
              • success - bool
              • error - str
              • stock - str 证券代码
              • stockName - str 证券名称
              • fineStatus - str 融资状态
              • fareRatio - float 合约利率
              • subRareRatio - float 提前终止利率
              • fineRatio - float 罚息利率
              • sloRatio - float 融券保证金比例
              • sloStatus - str 融资状态
              • positionStr - str 定位串
          • 返回值示例

            {'000001': {'success': True, 'error': '', 'stock': '000001.SZ', 'stockName': '平安银行', 'fineStatus': '0', 'fareRatio': 0.05, 'subRareRatio': 0.05, 'fineRatio': 0.0, 'sloRatio': 0.5, 'sloStatus': '0', 'positionStr': '00000100002'}, '000002': {'success': True, 'error': '', 'stock': '000002.SZ', 'stockName': '万 科A', 'fineStatus': '0', 'fareRatio': 0.045, 'subRareRatio': 0.045, 'fineRatio': 0.0, 'sloRatio': 0.5, 'sloStatus': '0', 'positionStr': '00000200002'}}
            
            1
      • 备注

        • 无

      # 约券异步报单

      smt_appointment_async(account, stock_code, apt_days, apt_volume, fare_ratio, sub_rare_ratio, fine_ratio, begin_date)
      
      1
      • 释义

        • 对约券进行异步下单操作,异步下单接口如果正常返回了下单请求序号seq,会收到on_smt_appointment_async_response的委托反馈
      • 参数

        • account - StockAccount 资金账号
        • stock_code - str 证券代码, 如'600000.SH'
        • apt_days - int 约定期限
        • apt_volume - int 约定数量
        • fare_ratio - float 约券费率
        • sub_rare_ratio - float 提前归还费率
        • fine_ratio - float 违约金率
        • begin_date - str 约定日期
      • 返回

        • 返回下单请求序号seq,成功委托后的下单请求序号为大于0的正整数,如果为-1表示委托失败
      • 备注

        • 如果失败,也会通过on_smt_appointment_async_response委托反馈收到错误信息
      • 示例

        • 信用资金账号8009248627对000001.SZ约券

          account = StockAccount('8009248627')
          account.account_type = 3
          #xt_trader为XtQuant API实例对象
          seq = xt_trader.smt_appointment_async(account,'000001.SZ',10,100,0.5,0.3,0.1,'20220715')
          
          1
          2
          3
          4

      # 约券合约信息查询

      query_appointment_info
      
      1
      • 释义

        • 查询约券合约信息
      • 参数

        • account - StockAccount 资金账号
      • 返回

        • dict 约券合约信息数据集

          • { compactId1: info1, compactId2: info2, ... }

            • compactId - str 合约编号,例如 '20220429009980000000018'
            • info - dict 约券合约信息
              • success - bool
              • error - str
              • fundAccount - str 资金账号
              • origCompactId - str 原合约编号
              • exchangeType - str 交易市场类别
              • stockCode - str 证券代码
              • stockName - str 股票名称
              • contractEndDate - int 合约到期日
              • feeRatio - float 费用利率
              • compactTerm - int 合约期限
              • compactAmount - int 合约数量
              • compactRepayDate - int 合约还券日
              • compactStatus - str 合约状态
              • positionStr - str 定位串
          • 返回值示例

            {'20220429009980000000018': {'success': True, 'error': '', 'fundAccount': '8009248627', 'origCompactId': '20220223009980000004481', 'exchangeType': 'SZ', 'stockCode': '002407', 'stockName': '', 'contractEndDate': 20220306, 'feeRatio': 0.08, 'compactTerm': 12, 'compactAmount': 100, 'compactRepayDate': 0, 'compactStatus': '0', 'positionStr': ''}, '20220628009980000000031': {'success': True, 'error': '', 'fundAccount': '8009248627', 'origCompactId': '20220223009980000004534', 'exchangeType': 'SZ', 'stockCode': '002407', 'stockName': '', 'contractEndDate': 20220306, 'feeRatio': 0.08, 'compactTerm': 12, 'compactAmount': 100, 'compactRepayDate': 0, 'compactStatus': '0', 'positionStr': ''}}
            
            1
      • 备注

        • 无

      # 回调类

      class MyXtQuantTraderCallback(XtQuantTraderCallback):
          def on_disconnected(self):
              """
              连接状态回调
              :return:
              """
              print("connection lost")
          def on_account_status(self, status):
              """
              账号状态信息推送
              :param response: XtAccountStatus 对象
              :return:
              """
              print("on_account_status")
              print(status.account_id, status.account_type, status.status)
          def on_stock_asset(self, asset):
              """
              资金信息推送  注意,该回调函数目前不生效
              :param asset: XtAsset对象
              :return:
              """
              print("on asset callback")
              print(asset.account_id, asset.cash, asset.total_asset)
          def on_stock_order(self, order):
              """
              委托信息推送
              :param order: XtOrder对象
              :return:
              """
              print("on order callback:")
              print(order.stock_code, order.order_status, order.order_sysid)
          def on_stock_trade(self, trade):
              """
              成交信息推送
              :param trade: XtTrade对象
              :return:
              """
              print("on trade callback")
              print(trade.account_id, trade.stock_code, trade.order_id)
          def on_stock_position(self, position):
              """
              持仓信息推送  注意,该回调函数目前不生效
              :param position: XtPosition对象
              :return:
              """
              print("on position callback")
              print(position.stock_code, position.volume)
          def on_order_error(self, order_error):
              """
              下单失败信息推送
              :param order_error:XtOrderError 对象
              :return:
              """
              print("on order_error callback")
              print(order_error.order_id, order_error.error_id, order_error.error_msg)
          def on_cancel_error(self, cancel_error):
              """
              撤单失败信息推送
              :param cancel_error: XtCancelError 对象
              :return:
              """
              print("on cancel_error callback")
              print(cancel_error.order_id, cancel_error.error_id, cancel_error.error_msg)
          def on_order_stock_async_response(self, response):
              """
              异步下单回报推送
              :param response: XtOrderResponse 对象
              :return:
              """
              print("on_order_stock_async_response")
              print(response.account_id, response.order_id, response.seq)
          def on_smt_appointment_async_response(self, response):
              """
              :param response: XtAppointmentResponse 对象
              :return:
              """
              print("on_smt_appointment_async_response")
              print(response.account_id, response.order_sysid, response.error_id, response.error_msg, response.seq)
      
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78

      # 连接状态回调

      on_disconnected()
      
      1
      • 释义
        • 失去连接时推送信息
      • 参数
        • 无
      • 返回
        • 无
      • 备注
        • 无

      # 账号状态信息推送

      on_account_status(data)
      
      1
      • 释义
        • 账号状态信息变动推送
      • 参数
        • data - XtAccountStatus 账号状态信息
      • 返回
        • 无
      • 备注
        • 无

      # 资产信息推送

      提示

      该回调函数目前不生效

      on_stock_asset(data)
      
      1
      • 释义
        • 资产信息变动推送
      • 参数
        • data - XtAsset 资产信息
      • 返回
        • 无
      • 备注
        • 无

      # 委托信息推送

      on_stock_order(data)
      
      1
      • 释义
        • 委托信息变动推送
      • 参数
        • data - XtOrder 委托信息
      • 返回
        • 无
      • 备注
        • 无

      # 成交信息推送

      on_stock_trade(data)
      
      1
      • 释义
        • 成交信息变动推送
      • 参数
        • data - XtTrade 成交信息
      • 返回
        • 无
      • 备注
        • 无

      # 持仓信息推送

      提示

      该回调函数目前不生效

      on_stock_position(data)
      
      1
      • 释义
        • 持仓信息变动推送
      • 参数
        • data - XtPosition 持仓信息
      • 返回
        • 无
      • 备注
        • 无

      # 下单失败信息推送

      on_order_error(data)
      
      1
      • 释义
        • 下单失败信息推送
      • 参数
        • data - XtOrderError 下单失败信息
      • 返回
        • 无
      • 备注
        • 无

      # 撤单失败信息推送

      on_cancel_error(data)
      
      1
      • 释义
        • 撤单失败信息的推送
      • 参数
        • data - XtCancelError 撤单失败信息
      • 返回
        • 无
      • 备注
        • 无

      # 异步下单回报推送

      on_order_stock_async_response(data)
      
      1
      • 释义
        • 异步下单回报推送
      • 参数
        • data - XtOrderResponse 异步下单委托反馈
      • 返回
        • 无
      • 备注
        • 无

      # 异步约券回报推送

      on_smt_appointment_async_response(data)
      
      1
      • 释义
        • 异步下单回报推送
      • 参数
        • data - XtAppointmentResponse 异步约券委托反馈
      • 返回
        • 无
      • 备注
        • 无
      上次更新: 2023/10/12, 10:46:32
      上一章-快速上手
      下一章-附录

      ← 快速上手 附录→

      Copyright © 2022-2024 北京睿智融科控股股份有限公司 | 迅投官网
      请使用微信扫码联系客服
      请使用微信扫码联系客服
      点击这里给我发消息
      • 跟随系统
      • 浅色模式
      • 深色模式
      • 阅读模式