# Real-time Time Frame Callback

on_recv_rsp(self, rsp_pb)

  • Description

    Real-time Time Frame callback, asynchronous processing of real-time Time Frame push of subscribed stocks. After receiving the real-time Time Frame 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_UpdateRT_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, Time Frame data is returned.
    str If ret != RET_OK, error description is returned.
    • Time Frame data format as follows:
      Field Type Description
      code str Stock code.
      name str Stock name.
      time str Time.
      is_blank bool Data status.
      opened_mins int How many minutes have passed from 0 o'clock.
      cur_price float Current price.
      last_close float Yesterday's close.
      avg_price float Average price.
      volume float Volume.
      turnover float Transaction amount.
  • Example

import time
from futu import *

class RTDataTest(RTDataHandlerBase):
    def on_recv_rsp(self, rsp_pb):
        ret_code, data = super(RTDataTest, self).on_recv_rsp(rsp_pb)
        if ret_code != RET_OK:
            print("RTDataTest: error, msg: %s"% data)
            return RET_ERROR, data
        print("RTDataTest ", data) # RTDataTest's own processing logic
        return RET_OK, data
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = RTDataTest()
quote_ctx.set_handler(handler) # Set real-time Time Frame push callback
ret, data = quote_ctx.subscribe(['HK.00700'], [SubType.RT_DATA]) # Subscribe to the Time Frame type, OpenD starts to continuously receive pushes 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
RTDataTest         code     name                 time  is_blank  opened_mins  cur_price  last_close   avg_price     turnover   volume
0  HK.00700  TENCENT  2023-07-19 16:00:00     False          960      333.0       336.4  330.400642  588143620.0  1766300
1
2

Tips