# Real-time Quote Callback

# StockQuoteHandlerBase

on_recv_rsp(self, rsp_pb)

  • Description

    Real-time quotation callback, asynchronous processing of real-time quotation push of subscribed stocks. After receiving the real-time quote 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_UpdateBasicQot_pb2.Response This parameter does not need to be processed in the derived class.
  • Return

    Parameter Type Description
    ret RET_CODE Interface result.
    data pd.DataFrame If ret == RET_OK, quotation data is returned.
    str If ret != RET_OK, error description is returned.
    • quotation data format as follows:
      Field Type Description
      code str Stock code.
      name str Stock name.
      data_date str Date.
      data_time str Time of latest price.
      last_price float Latest price.
      open_price float Open.
      high_price float High.
      low_price float Low.
      prev_close_price float Yesterday's close.
      volume int Volume.
      turnover float Turnover.
      turnover_rate float Turnover rate.
      amplitude int Amplitude.
      suspension bool Whether trading is suspended.
      listing_date str Listing date.
      price_spread float Spread.
      dark_status DarkStatus Grey market transaction status.
      sec_status SecurityStatus Stock status.
      strike_price float Strike price.
      contract_size float Contract size.
      open_interest int Number of open positions.
      implied_volatility float Implied volatility.
      premium float Premium.
      delta float Greek value Delta.
      gamma float Greek value Gamma.
      vega float Greek value Vega.
      theta float Greek value Theta.
      rho float Greek value Rho.
      index_option_type IndexOptionType Index option type.
      net_open_interest int Net open contract number.
      expiry_date_distance int The number of days from the expiry date.
      contract_nominal_value float Contract nominal amount.
      owner_lot_multiplier float Equal number of underlying stocks.
      option_area_type OptionAreaType Option type (by exercise time).
      contract_multiplier float Contract multiplier.
      pre_price float Pre-market price.
      pre_high_price float Pre-market high.
      pre_low_price float Pre-market low.
      pre_volume int Pre-market volume.
      pre_turnover float Pre-market turnover.
      pre_change_val float Pre-market change.
      pre_change_rate float Pre-market change rate.
      pre_amplitude float Pre-market amplitude.
      after_price float After-hours price.
      after_high_price float After-hours high.
      after_low_price float After-hours high.
      after_volume int After-hours volume.
      After_turnover float After-hours turnover.
      after_change_val float After-hours change.
      after_change_rate float After-hours change rate.
      after_amplitude float After-hours amplitude.
      last_settle_price float Yesterday's close.
      position float Holding position.
      position_change float Daily position change.
  • Example

import time
from futu import *

class StockQuoteTest(StockQuoteHandlerBase):
    def on_recv_rsp(self, rsp_pb):
        ret_code, data = super(StockQuoteTest,self).on_recv_rsp(rsp_pb)
        if ret_code != RET_OK:
            print("StockQuoteTest: error, msg: %s"% data)
            return RET_ERROR, data
        print("StockQuoteTest ", data) # StockQuoteTest's own processing logic
        return RET_OK, data
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = StockQuoteTest()
quote_ctx.set_handler(handler) # Set real-time quote callback
ret, data = quote_ctx.subscribe(['HK.00700'], [SubType.QUOTE]) # Subscribe to the real-time quotation type, Futu 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 Futu OpenD push duration to 15 seconds
quote_ctx.close() # Close the current link, Futu 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
    StockQuoteTest         code     name   data_date data_time  last_price  open_price  high_price  low_price  prev_close_price    volume      turnover  turnover_rate  amplitude  suspension listing_date  price_spread dark_status sec_status strike_price contract_size open_interest implied_volatility premium delta gamma vega theta  rho net_open_interest expiry_date_distance contract_nominal_value owner_lot_multiplier option_area_type contract_multiplier last_settle_price position position_change index_option_type pre_price pre_high_price pre_low_price pre_volume pre_turnover pre_change_val pre_change_rate pre_amplitude after_price after_high_price after_low_price after_volume after_turnover after_change_val after_change_rate after_amplitude
0  HK.00700  TENCENT  2023-07-19  16:08:14       333.0       330.6       333.8      327.0             336.4  21913296  7.240461e+09          0.229      2.021       False   2004-06-16           0.2         N/A     NORMAL          N/A           N/A           N/A                N/A     N/A   N/A   N/A  N/A   N/A  N/A               N/A                  N/A                    N/A                  N/A              N/A                 N/A               N/A      N/A             N/A               N/A       N/A            N/A           N/A        N/A          N/A            N/A             N/A           N/A         N/A              N/A             N/A          N/A            N/A              N/A               N/A             N/A

1
2
3

Tips