# Orders Push Callback

on_recv_rsp(self, rsp_pb)

  • Description

    In response to orders push, asynchronously process the order status information pushed by OpenD. After receiving the order status information pushed by OpenD, this function is called.. You need to override on_recv_rsp in the derived class.

  • Parameters

    Parameter Type Description
    rsp_pb Trd_UpdateOrder_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, order list is returned.
    str If ret != RET_OK, error description is returned.
    • Order list format as follows:
      Field Type Description
      trd_side TrdSide Trading direction.
      order_type OrderType Order type.
      order_status OrderStatus Order status.
      order_id str Order ID.
      code str Security code.
      stock_name str Security name.
      qty float Order quantity.
      price float Order price.
      currency Currency Transaction currency.
      create_time str Create time.
      updated_time str Last update time.
      dealt_qty float Deal quantity
      dealt_avg_price float Average deal price.
      last_err_msg str The last error description.
      remark str Identification of remarks when placing an order.
      time_in_force TimeInForce Valid period.
      fill_outside_rth bool Whether pre-market and after-hours are needed.
      aux_price float Traget price.
      trail_type TrailType Trailing type.
      trail_value float Trailing amount/ratio.
      trail_spread float Specify spread.
  • Example

from moomoo import *
from time import sleep
class TradeOrderTest(TradeOrderHandlerBase):
    """ order update push"""
    def on_recv_rsp(self, rsp_pb):
        ret, content = super(TradeOrderTest, self).on_recv_rsp(rsp_pb)
        if ret == RET_OK:
            print("* TradeOrderTest content={}\n".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(TradeOrderTest())
print(trd_ctx.place_order(price=518.0, qty=100, code="HK.00700", trd_side=TrdSide.SELL))

sleep(15)
trd_ctx.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  • Output
* TradeOrderTest content=  trd_env      code stock_name  dealt_avg_price  dealt_qty    qty           order_id order_type  price order_status          create_time         updated_time trd_side last_err_msg trd_market remark time_in_force fill_outside_rth aux_price trail_type trail_value trail_spread currency
0    REAL  HK.00700       Tencent              0.0        0.0  100.0  72625263708670783     NORMAL  518.0   SUBMITTING  2021-11-04 11:26:27  2021-11-04 11:26:27      BUY                      HK                  DAY              N/A       N/A        N/A         N/A          N/A      HKD
1
2