# Real-time Candlestick Callback

# CurKlineHandlerBase

on_recv_rsp(self, rsp_pb)

  • Description

    Real-time candlestick callback, asynchronous processing of real-time candlestick push for subscribed stocks.

    After receiving real-time candlestick 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_UpdateKL_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, IPO data is returned.
    str If ret != RET_OK, error description is returned.
    • IPO data format as follows:
      Field Type Description
      code str Stock code.
      name str Stock name.
      time_key str Time.
      open float Open.
      close float Close.
      high float High.
      low float Low.
      volume int Volume.
      turnover float Turnover.
      pe_ratio float P/E ratio.
      turnover_rate float Turnover rate.
      last_close float Yesterday's close.
      k_type KLType Candlestick type.
  • Example

import time
from futu import *
class CurKlineTest(CurKlineHandlerBase):
     def on_recv_rsp(self, rsp_pb):
        ret_code, data = super(CurKlineTest,self).on_recv_rsp(rsp_pb)
        if ret_code != RET_OK:
            print("CurKlineTest: error, msg: %s"% data)
            return RET_ERROR, data
        print("CurKlineTest ", data) # CurKlineTest's own processing logic
        return RET_OK, data
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = CurKlineTest()
quote_ctx.set_handler(handler) # Set real-time candlestick callback
ret, data = quote_ctx.subscribe(['HK.00700'], [SubType.K_1M]) # Subscribe to the candlestick data type, 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
  • Output
CurKlineTest         code     name             time_key   open  close   high    low   volume     turnover k_type  last_close
0  HK.00700  TENCENT  2023-07-19 16:00:00  332.6  333.0  333.0  332.4  1766300  588143620.0   K_1M         0.0
1
2

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 Candlestick 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.
  • Options related candlestick data, only supports 1 day, 1 minute, 5 minutes, 15 minutes and 60 minutes.