# Real-time Broker Queue Callback

on_recv_rsp(self, rsp_pb)

  • Description

    Real-time broker queue callback, asynchronous processing of real-time broker queue push of subscribed stocks. After receiving the real-time broker queue 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_UpdateBroker_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 tuple If ret == RET_OK, broker queue data is returned.
    str If ret != RET_OK, error description is returned.
    • Broker queue data format as follows:

      Field Type Description
      stock_code str Stock code.
      bid_frame_table pd.DataFrame Data from bid.
      ask_frame_table pd.DataFrame Data from ask.
      • Bid_frame_table format as follows:
        Field Type Description
        code str Stock code.
        name str Stock name.
        bid_broker_id int Bid broker ID.
        bid_broker_name str Bid broker name.
        bid_broker_pos int Broker level.
        order_id int Exchange order ID.
        order_volume int Order volume.
      • Ask_frame_table format as follows:
        Field Type Description
        code str Stock code.
        name str Stock name.
        ask_broker_id int Ask Broker ID.
        ask_broker_name str Ask Broker name.
        ask_broker_pos int Broker level.
        order_id int Exchange order ID.
        order_volume int Order volume.
  • Example

import time
from futu import *
    
class BrokerTest(BrokerHandlerBase):
    def on_recv_rsp(self, rsp_pb):
        ret_code, err_or_stock_code, data = super(BrokerTest, self).on_recv_rsp(rsp_pb)
        if ret_code != RET_OK:
            print("BrokerTest: error, msg: {}".format(err_or_stock_code))
            return RET_ERROR, data
        print("BrokerTest: stock: {} data: {} ".format(err_or_stock_code, data)) # BrokerTest's own processing logic
        return RET_OK, data
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = BrokerTest()
quote_ctx.set_handler(handler) # Set real-time broker push callback
ret, data = quote_ctx.subscribe(['HK.00700'], [SubType.BROKER]) # Subscribe to the broker 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
21
  • Output
BrokerTest: stock: HK.00700 data: [        code     name  bid_broker_id                                    bid_broker_name  bid_broker_pos order_id order_volume
0   HK.00700  TENCENT           5338            J.P. Morgan Broking (Hong Kong) Limited               1      N/A          N/A
..       ...      ...            ...                                                ...             ...      ...          ...
36  HK.00700  TENCENT           8305  Futu Securities International (Hong Kong) Limited               4      N/A          N/A

[37 rows x 7 columns],         code     name  ask_broker_id                                ask_broker_name  ask_broker_pos order_id order_volume
0   HK.00700  TENCENT           1179  Huatai Financial Holdings (Hong Kong) Limited               1      N/A          N/A
..       ...      ...            ...                                            ...             ...      ...          ...
39  HK.00700  TENCENT           6996  China Investment Information Services Limited               1      N/A          N/A

[40 rows x 7 columns]] 
1
2
3
4
5
6
7
8
9
10
11

Tips