# 事件合约逐笔推送

on_recv_rsp(self, rsp_pb)

  • 介绍

    事件合约逐笔推送回调,异步处理已订阅事件合约的实时逐笔推送。
    在收到事件合约逐笔数据推送后会回调到该函数,您需要在派生类中覆盖 on_recv_rsp。

  • 参数

    参数 类型 说明
    rsp_pb Qot_UpdateEventContractTicker_pb2.Response 派生类中不需要直接处理该参数
  • 返回

    参数 类型 说明
    ret RET_CODE 接口调用结果
    data pd.DataFrame 当 ret == RET_OK,返回事件合约逐笔数据
    str 当 ret != RET_OK,返回错误描述
    • 逐笔数据格式如下:
      字段 类型 说明
      code str 合约代码
      time str 成交时间
      yes_price float YES 成交价格
      no_price float NO 成交价格
      volume float 成交数量
      side PredSide 逐笔方向(YES/NO)
      sequence str 逐笔序号
  • Example

import time
from moomoo import *

class TickerTest(EventContractTickerHandlerBase):
    def on_recv_rsp(self, rsp_pb):
        ret_code, data = super(TickerTest, self).on_recv_rsp(rsp_pb)
        if ret_code != RET_OK:
            print("TickerTest: error, msg: %s" % data)
            return RET_ERROR, data
        print("TickerTest ", data)  # TickerTest 自己的处理逻辑
        return RET_OK, data

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = TickerTest()
quote_ctx.set_handler(handler)  # 设置事件合约逐笔推送回调
ret, data = quote_ctx.subscribe_event_contract(
    code_list=['EC.KXODIMATCH-26JUL140600INDENG-IND'],
    subtype_list=[SubType.TICKER],
    subscribe_push=True)  # 订阅事件合约逐笔类型,OpenD 开始持续收到服务器的推送
if ret == RET_OK:
    print(data)
else:
    print('error:', data)
time.sleep(15)  # 设置脚本接收 OpenD 的推送持续时间为15秒
quote_ctx.close()  # 关闭当条连接,OpenD 会在1分钟后自动取消相应合约相应类型的订阅
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
  • Output
TickerTest                                   code                 time  yes_price  no_price  volume side             sequence
0  EC.KXODIMATCH-26JUL140600INDENG-IND  2026-07-13 04:27:13        0.5       0.5   96.61  YES  7661926304047955968
1
2