# Event Contract Ticker Push

on_recv_rsp(self, rsp_pb)

  • Description

    Event contract tick-by-tick push callback, asynchronously processing the real-time push of subscribed event contracts. After receiving the event contract tick-by-tick data push, it will call back to this function. You need to override on_recv_rsp in the derived class.

  • Parameters

    Parameter Type Description
    rsp_pb Qot_UpdateEventContractTicker_pb2.Response This parameter does not need to be processed directly in the derived class.
  • Return

    Field Type Description
    ret RET_CODE Interface result.
    data pd.DataFrame If ret == RET_OK, event contract tick-by-tick data is returned.
    str If ret != RET_OK, error description is returned.
    • Tick-by-tick data format as follows:
      Field Type Description
      code str Contract code.
      time str Transaction time.
      yes_price float YES transaction price.
      no_price float NO transaction price.
      volume float Volume.
      side PredSide Tick-By-Tick direction (YES/NO).
      sequence str Sequence number.
  • 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 custom logic
        return RET_OK, data

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = TickerTest()
quote_ctx.set_handler(handler)  # Set event contract tick-by-tick push callback
ret, data = quote_ctx.subscribe_event_contract(
    code_list=['EC.KXODIMATCH-26JUL140600INDENG-IND'],
    subtype_list=[SubType.TICKER],
    subscribe_push=True)  # Subscribe to event contract tick-by-tick type, OpenD starts receiving continuous push from the server
if ret == RET_OK:
    print(data)
else:
    print('error:', data)
time.sleep(15)  # Set the duration for receiving OpenD push to 15 seconds
quote_ctx.close()  # Close the connection, OpenD will automatically unsubscribe the corresponding contract and type after 1 minute
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