# Deals Push Callback

# TradeDealHandlerBase

on_recv_rsp(self, rsp_pb)

  • Description

    In response to the transaction push, asynchronously process the transaction status information pushed by OpenD. After receiving the order fill information pushed by OpenD, this function is called. You need to override on_recv_rsp in the derived class.
    This feature is only available for live trading and not for paper trading.

  • Parameters

    Parameter Type Description
    rsp_pb Trd_UpdateOrderFill_pb2.Response This parameter does not need to be processed in the derived class.
  • Return

    Field Type Description
    ret RET_CODE Interface result.
    data pd.DataFrame If ret == RET_OK, transaction list is returned.
    str If ret != RET_OK, error description is returned.
    • Transaction list format as follows:
      Field Type Description
      trd_side TrdSide Trading direction.
      deal_id str Deal number.
      order_id str Order ID.
      code str Security code.
      stock_name str Security name.
      qty float Quantity of shares bought/sold on this fill.
      price float Fill price.
      create_time str Create time.
      counter_broker_id int Counter broker ID.
      counter_broker_name str Counter broker name.
      status DealStatus Deal status.
  • Example

from futu import *
from time import sleep
class TradeDealTest(TradeDealHandlerBase):
    """ order update push"""
    def on_recv_rsp(self, rsp_pb):
        ret, content = super(TradeDealTest, self).on_recv_rsp(rsp_pb)
        if ret == RET_OK:
            print("TradeDealTest content={}".format(content))
        return ret, content

trd_ctx = OpenSecTradeContext(filter_trdmarket=TrdMarket.HK, host='127.0.0.1', port=11111, security_firm=SecurityFirm.FUTUSECURITIES)
trd_ctx.set_handler(TradeDealTest())
print(trd_ctx.place_order(price=595.0, qty=100, code="HK.00700", trd_side=TrdSide.BUY))

sleep(15)
trd_ctx.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  • Output
TradeDealTest content=  trd_env      code stock_name              deal_id             order_id    qty  price trd_side              create_time  counter_broker_id counter_broker_name trd_market status
0    REAL  HK.00700       Tencent  2511067564122483295  8561504228375901919  100.0  518.0      BUY  2021-11-04 11:29:41.595                  5                   5         HK     OK
1
2