# Place Orders

place_order(price, qty, code, trd_side, order_type=OrderType.NORMAL, adjust_limit=0, trd_env=TrdEnv.REAL, acc_id=0, acc_index=0, remark=None, time_in_force=TimeInForce.DAY, fill_outside_rth=False, aux_price=None, trail_type=None, trail_value=None, trail_spread=None)

  • Description

    Place order

    Tips

    The Python API is synchronous, but the network transport is asynchronous. When the receiving time interval is very short between the response packet of place_order and Order Fill Push Callback or Order Push Callback, it may happen that the response packet of place_order returns first, but the callback function is called first. For example: Order Push Callback may be called first, and then the place_order interface returns.

  • Parameters

    Parameter Type Description
    price float Order price.
    qty float Order quantity.
    code str Code.
    trd_side TrdSide Transaction direction.
    order_type OrderType Order type.
    adjust_limit float Price adjustment range.
    trd_env TrdEnv Trading environment.
    acc_id int Trading account ID.
    acc_index int The account number in the trading account list.
    remark str Remark.
    time_in_force TimeInForce Valid period.
    fill_outside_rth bool Whether allow to execute the order during pre-market or after-hours market trades.
    aux_price float Trigger price.
    trail_type TrailType Trailing type.
    trail_value float Trailing amount/ratio.
    trail_spread float Specify spread.
  • 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.
      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 futu import *
pwd_unlock = '123456'
trd_ctx = OpenSecTradeContext(filter_trdmarket=TrdMarket.HK, host='127.0.0.1', port=11111, security_firm=SecurityFirm.FUTUSECURITIES)
ret, data = trd_ctx.unlock_trade(pwd_unlock)  # If you use a live trading account to place an order, you need to unlock the account first. The example here is to place an order on a paper trading account, and unlocking is not necessary.
if ret == RET_OK:
    ret, data = trd_ctx.place_order(price=510.0, qty=100, code="HK.00700", trd_side=TrdSide.BUY, trd_env=TrdEnv.SIMULATE)
    if ret == RET_OK:
        print(data)
        print(data['order_id'][0])  # Get the order ID of the placed order
        print(data['order_id'].values.tolist())  # Convert to list
    else:
        print('place_order error: ', data)
else:
    print('unlock_trade failed: ', data)
trd_ctx.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  • Output

       code stock_name trd_side order_type order_status           order_id    qty  price          create_time         updated_time  dealt_qty  dealt_avg_price last_err_msg remark time_in_force fill_outside_rth aux_price trail_type trail_value trail_spread currency
0  HK.00700       Tencent      BUY     NORMAL   SUBMITTING  38196006548709500  100.0  420.0  2021-11-04 11:38:19  2021-11-04 11:38:19        0.0              0.0                               DAY              N/A       N/A        N/A         N/A          N/A      HKD
38196006548709500
['38196006548709500']
1
2
3
4
5

Interface Limitations

  • A maximum of 15 requests per 30 seconds, and the interval between two consecutive requests cannot be less than 0.02 seconds.
  • When using live trading accounts, you need to unlock trade before calling Place Order interface, but when using paper trading accounts, you do not need to unlock trade.

Tips

  • Required parameters for each order type: Click here to learn more.
  • Locking position is not supported for shortable securities, that means you can not hold a long position and a short position at the same time.
  • If you want to close out position of a shortable securities, you need to get the direction of the position and send an opposite order with the same quantity.
  • If you want to reversing trade of a shortable securities, there are 2 steps: 1. you need to get the direction of the position and send an opposite order with the same quantity. 2. Send an opposite order again to open the reverse trade. For example: If you want to reverse trade of 1 long position of HK.HSI2012, you need to close the long position first and then sell short the contract.