# Event Contract K-line Push

on_recv_rsp(self, rsp_pb)

  • Description

    Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts. After receiving the event contract K-line 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_UpdateEventContractKline_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 K-line data is returned.
    str If ret != RET_OK, error description is returned.
    • K-line data format as follows:
      Field Type Description
      code str Contract code.
      pre_side PredSide Contract direction (YES/NO). Available for contract K-line; for event K-line, subject to the server return value.
      name str Contract name.
      time_key str K-line time.
      open float Open price.
      high float Highest price.
      low float Lowest price.
      close float Close price.
      volume float Volume.
  • Example

import time
from moomoo import *

class EventContractKlineTest(EventContractKlineHandlerBase):
    def on_recv_rsp(self, rsp_pb):
        ret_code, data = super(EventContractKlineTest, self).on_recv_rsp(rsp_pb)
        if ret_code != RET_OK:
            print("EventContractKlineTest: error, msg: %s" % data)
            return RET_ERROR, data
        print("EventContractKlineTest ", data)  # EventContractKlineTest custom logic
        return RET_OK, data

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = EventContractKlineTest()
quote_ctx.set_handler(handler)  # Set event contract K-line push callback
ret, data = quote_ctx.subscribe_event_contract(
    code_list=['EC.KXODIMATCH-26JUL140600INDENG-IND'],
    subtype_list=[SubType.K_DAY],
    kline_source_list=[ECKlineSource.NONE],
    subscribe_push=True)  # Subscribe to K-line 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
26
  • Output
EventContractKlineTest                                   code pre_side                      name             time_key  open  high   low  close  volume
0  EC.KXODIMATCH-26JUL140600INDENG-IND      YES  England vs India Winner?  2026-07-13 00:00:00  0.51  0.52  0.48    0.5  7831.0
1
2