# Real-time Tick-by-Tick Callback

# TickerHandlerBase

on_recv_rsp(self, rsp_pb)

  • Description

    Real-time callback, asynchronously processing the real-time push of subscribed stocks. After receiving real-time 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_UpdateTicker_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, 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 Stock code.
      name str Stock name.
      sequence int Sequence number.
      time str Transaction time.
      price float Transaction price.
      volume int Volume.
      turnover float Transaction amount.
      ticker_direction TickerDirect Tick-By-Tick direction.
      type TickerType Tick-By-Tick type.
      push_data_type PushDataType Source of data.
  • Example

import time
from moomoo import *

class TickerTest(TickerHandlerBase):
    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's own processing logic
        return RET_OK, data
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = TickerTest()
quote_ctx.set_handler(handler) # Set real-time push callback
ret, data = quote_ctx.subscribe(['HK.00700'], [SubType.TICKER]) # Subscribe to the type by transaction, OpenD starts to receive continuous push from the server
if ret == RET_OK:
    print(data)
else:
    print('error:', data)
time.sleep(15) # Set the script to receive OpenD push duration to 15 seconds
quote_ctx.close() # Close the current link, OpenD will automatically cancel the corresponding type of subscription for the corresponding stock after 1 minute
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  • Output
TickerTest         code     name                 time  price   volume     turnover ticker_direction             sequence     type push_data_type
0  HK.00700  TENCENT  2023-07-19 16:08:12  333.0  1667000  555111000.0          NEUTRAL  7257438563422200985  AUCTION          CACHE

1
2
3

Tips

  • This interface provides the function of continuously obtaining pushed data. If you need to obtain real-time data at one time, please refer to the Get Real-time Tick-By-Tick API.
  • For the difference between get real-time data and real-time data callback, please refer to How to Get Real-time Quotes Through Subscription Interface.
  • After the market connection is reconnected, during the disconnected period of OpenD pulls, the nearest (up to 50) Tick-By-Tick data is pushed, which can be distinguished by the Tick-By-Tick push type field