Place Order
place_order Place Order
TradeClient.place_order():
Description
Interface for placing order. This method allows you to set order types, quantity, buy/sell, of you choice, please see below for more information. **Please read the Introduction section of this documentation, as well as FAQ-Trade-Supported Order Types section,to make sure that the order types involved in your program are actually allowed ** If this method returns an error, or that your order gets canceled by the system, it is recommended that you refer to FAQ-Trade section for a quick inspection yourself.
When a order is successfully placed, the id attribute in Order object will be filled (order.id
). This id can be used to identify a unique order and thus can be used to modify or cancel an order.
Market Order(MKT)and Stop Order(STP)do not support pre-market and post-market transactions. When placing the order, you need to set 'outside_rth' to false
For the symbol that can be shorted, the lock-up function is not currently supported, so it is impossible to hold long and short positions of the same symbol at the same time
Attached Order currently only supports limit orders
Market Order(MKT) and the paper trade account,GTC is not supported for 'time_in_force' parameter
The paper trade account currently does not support warrants and CBBC orders
Order Status Explanation
- How can I determine the partial fulfillment status of my Prime or Paper accounts?
When the order status is not FILLED (may be NEW, CANCELLED, EXPIRED, REJECTED one of them), it may be a partially filled status, which can be judged by whether the number of orders filled is greater than 0.
- How to determine the partial transaction status of Global Account?
The order status is FILLED, and the order quantity is greater than 0
Order Status Flow
Other Information
- Trading of ETF options that expire on Wednesdays and are based on the underlying assets of the three ETFs, namely 【IWM/SPY/QQQ】, is supported. Other index options that do not expire on Fridays are not supported.
- Directly opening a reverse position is not allowed. For example, selling 200 shares when holding 100 shares is not permitted. The position must be closed first.
Parameters
Order
Object (tigeropen.trade.domain.order.Order
)
You can construct an Order
Object using the functions defined in tigeropen.common.util.order_utils
, such as limit_order() or market_order(). Please see Order Object - Construction for details. Another construction method is to use TradeClient.create_order()
to request an order_id to create an order object (deprecated)
Parameter | Type | Description | Market Order (Quantity) | Market Order (Cash) | Limit Order | Limit Order with Legs | Stop Order | Stop Limit Order | Trailing Stop Order | Auction Market Order | Auction Limit Order | Algorithmic Order | OCA Order |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
account | str | The account to which the order belongs | |||||||||||
id | long | Global order ID | |||||||||||
order_id | int | Account auto-increment order number (deprecated) | |||||||||||
parent_id | long | Parent order ID, currently only used for attached orders in the TigerTrade App | |||||||||||
order_time | int | Order time, a 13-digit timestamp in milliseconds | |||||||||||
trade_time | int | Order status update time. Completed orders: completion time Canceled orders: Successful cancellation time The timestamp is in milliseconds with 13 digits | |||||||||||
update_time | int | Order update time given in milliseconds with 13 digits | |||||||||||
expire_time | int | GTD (Good Till Date) order expiration time, in milliseconds with a 13-digit timestamp | |||||||||||
reason | str | Upon failure, the description of the reason for the failure will be returned | |||||||||||
action | str | Trade direction: 'BUY' / 'SELL' | |||||||||||
quantity | int | Order quantity | |||||||||||
quantity_scale | int | The offset of the order quantity, defaulting to 0. For fractional share orders, the combination of quantity and quantity_scale represents the actual order quantity. For example, if quantity=111 and quantity_scale=2, the real quantity would be 111 * 10^(-2) = 1.11 | |||||||||||
total_cash_amount | float | The total order amount, which is None when the order is placed by number of shares | |||||||||||
filled_cash_amount | float | The total amount executed, which is None when the order is placed by number of shares | |||||||||||
refund_cash_amount | float | The returned amount, which equals the total order amount minus the executed amount. It is None when the order is placed by number of shares or if the order is not finalized | |||||||||||
filled | int | Executed Quantity | |||||||||||
avg_fill_price | float | Average Execution Price Excluding Commission | |||||||||||
commission | float | Includes commission, stamp duty, securities regulatory fees, and other related charges | |||||||||||
gst | float | Goods and Service Tax | |||||||||||
realized_pnl | float | Realized profit and loss | |||||||||||
trail_stop_price | float | Trailing stop price | |||||||||||
limit_price | float | Limit order price | |||||||||||
aux_price | float | Stop-loss order: price at which the stop-loss order is triggered Trailing stop order: price difference being tracked. | |||||||||||
trailing_percent | float | Trailing stop order - Percentage, with a value range from 0 to 100 | |||||||||||
percent_offset | float | <This field is not used> | |||||||||||
order_type | str | Order type: 'MKT': Market Order' LMT': Limit Order 'STP': Stop Order 'STP_LMT': Stop Limit Order 'TRAIL': Trailing Stop Order | |||||||||||
time_in_force | str | Validity: 'DAY': Valid for the day 'GTC': Valid untill cancelled 'GTD': Valid until a specified date (requires expire_time ) | |||||||||||
outside_rth | bool | Supports pre-market and after-market trading, exclusive to US stocks | |||||||||||
trading_session_type | str | Night trading | |||||||||||
contract | Contract | tigeropen.trade.domain.contract.Contract Contract Object | |||||||||||
status | OrderStatus | tigeropen.common.consts.OrderStatus OrderStatus Enum | |||||||||||
remaining | int | Unfilled quantity | |||||||||||
sub_ids | list[int] | List of sub-order IDs for attached orders (this field will only have a value when attaching an order) | |||||||||||
adjust_limit | float | Price adjustment range (default 0 means no adjustment, positive number means adjust upward, negative number means adjust downward). The price will be automatically adjusted to a valid price. For example, 0.001 means adjusting upward with a range not exceeding 0.1%; -0.001 means adjusting downward with a range not exceeding 0.1%. Default 0 means no adjustment | |||||||||||
user_mark | str | User-defined remarks | |||||||||||
latest_price | float | Market price at the time of placing the order | |||||||||||
charges | tigeropen.trade.domain.order.Charge | Order commission and other fee details (only available for individual order queries via TradeClient.get_order). See below for specifics |
- Order Leg Parameters
- Order Leg refers to an order that can have a take-profit or stop-loss effect on the main order through an attached sub-order. Stop loss order (can be used to stop loss). Additional orders can be achieved by adding the following parameters
Parameter | Type | Description | Additional Stop Loss | Additional Take Profit | LIMIT/STOP/STOP_LIMIT (Only for One-Cancels-All) |
---|---|---|---|---|---|
leg_type | str | Additional order type: PROFIT - Take Profit order type, LOSS - Stop Loss order type; LMT / STP / STP_LMT are only supported for OCA (One-Cancels-All) orders | |||
price | float | Trigger price for the additional order | |||
time_in_force | str | Validity period 'DAY': Valid for the current day 'GTC': Good till cancel 'GTD': Good till date | optional | optional | optional |
outside_rth | bool | Whether pre-market and after-hours trading are allowed (US stocks only) | optional | optional | optional |
limit_price | float | Limit order price | not filled | not filled | |
trailing_percent | float | Trailing stop loss order-stop loss percentage, when trailing stop loss order, one of the stop loss percentage (stopLossTrailingPercent) and stop loss amount (stopLossTrailingAmount) must be filled in, if both are filled, the stop loss percentage will be used as the parameter | optional | not filled | not filled |
trailing_amount | float | Trailing stop loss order-stop loss amount, when trailing stop loss order, one of stop loss percentage (stopLossTrailingPercent) and stop loss amount (stopLossTrailingAmount) must be filled in, if both are filled, the stop loss percentage will be used as parameter | optional | not filled | not filled |
quantity | int | Order quantity |
Response
If the order is successfully placed, the function will return True
,otherwise it will throw an exception If the order is successfully placed, The 'id' attribute of the Order object will be filled in with the actual order
Build Contract
from tigeropen.common.util.contract_utils import stock_contract, option_contract, option_contract_by_symbol,
future_contract, war_contract_by_symbol, iopt_contract_by_symbol
# US stock
contract = stock_contract(symbol='TIGR', currency='USD')
# HK stock
contract = stock_contract(symbol='00700', currency='HKD')
# US option
contract = option_contract(identifier='AAPL 190118P00160000')
contract = option_contract_by_symbol('JD', expiry='20211015', strike=45.0, put_call='PUT', currency='USD')
# Futures
contract = future_contract(symbol='CL', currency='USD', expiry='20190328', multiplier=1.0, exchange='SGX')
# HK warrant
contract = war_contract_by_symbol('01810', '20221116', 14.52, 'CALL', local_symbol='14759', multiplier=2000,
currency='HKD')
# HK CBBC
contract = iopt_contract_by_symbol('02318', '20200420', 87.4, 'CALL', local_symbol='63379', currency='HKD')
Limit Order (LMT)
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import limit_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# generate stock contracts
contract = stock_contract(symbol='AAPL', currency='USD')
# generate order object
order = limit_order(account=client_config.account, contract=contract, action='BUY', limit_price=0.1, quantity=1)
# order
oid = trade_client. place_order(order)
print(order)
# Order({'account': '111111', 'id': 249891111111111111, 'order_id': None, 'parent_id': None, 'order_time': None, 'reason': None, 'trade_time': None , 'action': 'BUY', 'quantity': 1, 'filled': 0, 'avg_fill_price': 0, 'commission': None, 'realized_pnl': None, 'trail_stop_price': None, 'limit_price': 0.1 , 'aux_price': None, 'trailing_percent': None, 'percent_offset': None, 'order_type': 'LMT', 'time_in_force': None, 'outside_rth': None, 'order_legs': None, 'algo_params': None , 'secret_key': None, 'contract': AAPL/STK/USD, 'status': 'NEW', 'remaining': 1})
print(order.status) # order status
print(order.reason) # If the order fails, reason is the reason for the failure
# If the order is placed successfully, order.id is the id of the order, and you can use this id to query the order or cancel the order
my_order = trade_client.get_order(id=order.id)
oid = trade_client.cancel_order(id=order.id)
# Or operate the order object to modify the order
trade_client.modify_order(order, limit_price=190.5)
Market Order (MKT)
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import market_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# generate stock contracts
contract = stock_contract(symbol='AAPL', currency='USD')
# generate order object
order = market_order(account=client_config.account, contract=contract, action='BUY', quantity=1)
# order
oid = trade_client.place_order(order)
Market Order by Amount(MKT)
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import market_order_by_amount
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# generate stock contracts
contract = stock_contract(symbol='AAPL', currency='USD')
# generate order object
order = market_order_by_amount(account=client_config.account, contract=contract, action='BUY', amount =100)
# order
oid = trade_client.place_order(order)
Stop Loss Order (STP)
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import stop_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# generate stock contracts
contract = stock_contract(symbol='AAPL', currency='USD')
# generate order object
order = stop_order(account=client_config.account, contract=contract, action='SELL', aux_price=1, quantity=1)
# order
oid = trade_client.place_order(order)
Stop Limit Order (STP_LMT)
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import stop_limit_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# generate stock contracts
contract = stock_contract(symbol='AAPL', currency='USD')
# generate order object
order = stop_limit_order(account=client_config.account, contract=contract, action='SELL', limit_price=200.0, aux_price=180.0, quantity=1)
# order
oid = trade_client.place_order(order)
Trailing Stop Order (TRAIL)
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import trail_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# generate stock contracts
contract = stock_contract(symbol='AAPL', currency='USD')
# generate order object
order = trail_order(account=client_config.account, contract=contract, action='SELL', quantity=1, trailing_percent=8.0, )
# order
oid = trade_client.place_order(order)
Additional Orders
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import limit_order, limit_order_with_legs, order_leg, algo_order_params, \
algo_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
contract = stock_contract(symbol='AAPL', currency='USD')
# Limit order + additional order (additional orders are only supported when the main order is a limit order)
stop_loss_order_leg = order_leg('LOSS', 8.0, time_in_force='GTC',outside_rth=False) # additional stop loss
stop_loss_order_leg1 = order_leg('LOSS', 8.0, limit_price=7.5,outside_rth=False) # additional stop loss limit order
stop_loss_order_leg2 = order_leg('LOSS', 8.0, trailing_percent=0.8,outside_rth=False) # Additional stop loss trailing order (proportional)
stop_loss_order_leg3 = order_leg('LOSS', 8.0, trailing_amount=2.0,outside_rth=False) # Additional stop loss trailing order (by amount)
profit_taker_order_leg = order_leg('PROFIT', 12.0, time_in_force='GTC',outside_rth=False) # additional take profit
main_order = limit_order_with_legs(account=client_config.account, contract=contract, action='BUY', quantity=100, limit_price=10.0,
order_legs=[profit_taker_order_leg, stop_loss_order_leg])
oid = trade_client. place_order(main_order)
# Query the additional orders associated with the main order
order_legs = trade_client.get_open_orders(account=client_config.account, parent_id=main_order.id)
print(order_legs)
OCA order
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import order_leg, oca_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
contract = stock_contract(symbol='BILI', currency=Currency.USD)
# stop_loss_order_leg = order_leg('STP', price=8.0)
stop_loss_order_leg = order_leg('STP_LMT', price=8.0, limit_price=7.5,outside_rth=False)
profit_taker_order_leg = order_leg('LMT', limit_price=30.0,outside_rth=False)
my_oca_order = oca_order(client_config.account, contract, 'BUY',
order_legs=[stop_loss_order_leg, profit_taker_order_leg],
quantity=1000)
trade_client.place_order(my_oca_order)
Algorithmic order
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import limit_order, limit_order_with_legs, order_leg, algo_order_params, \
algo_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# Algorithmic order
contract = stock_contract(symbol='AAPL', currency='USD')
params = algo_order_params(start_time='2022-01-19 23:00:00', end_time='2022-11-19 23:50:00', no_take_liq=True,
allow_past_end_time=True, participation_rate=0.1)
order = algo_order(account, contract, 'BUY', 1000, 'VWAP', algo_params=params, limit_price=100.0)
oid = trade_client. place_order(order)
Auction order
auction_limit_order auction limit orderauction_market_order auction market order
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import market_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# generate stock contracts
contract = stock_contract(symbol='01810', currency='HKD')
# Auction limit order, time_in_force is set to OPG means to participate in the pre-market auction, and the intraday time that has not been traded before the market will continue to be placed, and will not participate in the after-hours auction; set to DAY means it is only valid after the market
order = auction_limit_order(account=client_config.account, contract=contract, action='BUY', quantity=200,
limit_price='10', time_in_force='OPG')
# Auction market order
# order = auction_market_order(account=client_config.account, contract=contract, action='BUY', quantity=200, time_in_force='OPG')
# order
oid = trade_client. place_order(order)
Overnight/Full-time order
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import limit_order
from tigeropen.common.consts import TradingSessionType
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
contract = stock_contract(symbol='AAPL', currency='USD')
order = limit_order(account=client_config.account, contract=contract, action='BUY', limit_price=120, quantity=1)
# Overnight trading
# order.trading_session_type = TradingSessionType.OVERNIGHT
# Full-time trading
order.trading_session_type = TradingSessionType.FULL
# order
oid = trade_client.place_order(order)
Other examples
Place an order for Hong Kong stocks When placing an order for Hong Kong stocks, the order quantity needs to match the lot size of the stock. For example, the lot size of 00700
is 100, then the order size can only be integer multiples of 100, 200, 500, etc. You can use QuoteClient.get_trade_metas
to get the number of shares per lot of a stock in advance.
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.order_utils import limit_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
quote_client = QuoteClient(client_config)
symbol = '00700'
# Get the number of shares per lot
metas = quote_client. get_trade_metas([symbol])
lot_size = int(metas['lot_size'].iloc[0])
# generate stock contracts
contract = stock_contract(symbol=symbol, currency='HKD')
# generate order object
order = limit_order(account=client_config.account, contract=contract, action='BUY', limit_price=400.0, quantity=2 * log_size)
# order
oid = trade_client. place_order(order)
Order Futures
from tigeropen.common.util.contract_utils import future_contract
from tigeropen.common.util.order_utils import limit_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# generate futures contract
contract = future_contract(symbol='CL', currency='USD')
# generate order object
order = limit_order(account=client_config.account, contract=contract, action='BUY', limit_price=0.1, quantity=1)
# order
oid = trade_client. place_order(order)
Order Options
from tigeropen.common.consts import ComboType
from tigeropen.common.util.contract_utils import option_contract, option_contract_by_symbol
from tigeropen.common.util.order_utils import combo_order, contract_leg, limit_order
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# order single option
contract = option_contract(identifier='AAPL 190118P00160000')
# or
contract = option_contract_by_symbol('AAPL', '20200110', strike=280.0, put_call='PUT', currency='USD')
order = limit_order(account=client_config.account, contract=contract, action='BUY', limit_price=0.1, quantity=1)
oid = trade_client.place_order(order)
# order option combination
contract_leg1 = contract_leg(symbol='TSLA', sec_type='OPT', expiry='20230616', strike=220, put_call='CALL',
action='BUY', ratio=1)
contract_leg2 = contract_leg(symbol='TSLA', sec_type='OPT', expiry='20230616', strike=225, put_call='CALL',
action='SELL', ratio=1)
order = combo_order(client_config.account, [contract_leg1, contract_leg2], combo_type=ComboType.VERTICAL,
action='BUY', quantity=1, order_type='LMT', limit_price=1.0)
res = trade_client.place_order(order)
print(res)
Check the contract and place an order
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# Get stock contracts (not recommended)
contract = trade_client.get_contract('AAPL', sec_type=SecurityType.STK)
# Get the order object (not recommended)
order = trade_client.create_order(account=client_config.account, contract=contract, action='SELL', order_type='LMT', quantity=1, limit_price=200.0)
# order
oid = trade_client. place_order(order)
Set order attributes An example of using unusual attributes of orders. Such as user_mark
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# generate stock contracts
contract = stock_contract(symbol='AAPL', currency='USD')
# generate order object
order = limit_order(account=client_config.account, contract=contract, action='BUY', limit_price=0.1, quantity=1)
# Modify order custom remarks (Global account needs to contact the platform in advance to enable this function)
order.user_mark = 'my-custom-remark'
# Modify the order validity period to GTC
#order.time_in_force = 'GTC'
# Modify the order to GTD (good till date, valid until the specified date)
#order.time_in_force = 'GTD'
#order.expire_time = 1700496000000 # must specify the expiration time
# order
trade_client. place_order(order)
my_order = trade_client.get_order(id=order.id)
print(my_order. user_mark)
Correction order price Use contract information and PriceUtil
to correct the order price. When the contract price is in different gears, there will be different precision. When specifying a price with inappropriate precision as the order price, an error will be returned. Here, the queried contract tick specification data is used to correct the price with tools.
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.common.util.price_util import PriceUtil
from tigeropen.common.consts import SecurityType
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
# get stock contracts
contract = trade_client.get_contract(symbol='AAPL', sec_type=SecurityType.STK)
limit_price = 150.173
# Check if the price meets the contract's tick specification
is_price_ok = PriceUtil.match_tick_size(price, contract.tick_sizes)
# Correct the price (if the is_up parameter is set to True, the price will be adjusted upwards. Default False, the price will be adjusted downwards)
# If the contract price is 1~1000, the tick specification is 0.01, then 150.173 is adjusted to 150.17; after upward adjustment, it is 150.18
limit_price = PriceUtil.fix_price_by_tick_size(price, contract.tick_sizes)
# generate order object
order = limit_order(account=client_config.account, contract=contract, action='BUY', limit_price=limit_price, quantity=1)
# order
trade_client. place_order(order)
create_order Request to create an order
TradeClient.create_order(account, contract, action, order_type, quantity, limit_price=None, aux_price=None, trail_stop_price=None, trailing_percent=None, percent_offset=None, time_in_force=None, outside_rth=None, order_legs=None, algo_params=None, **kwargs):
Description
Request an order number and create an order object. It is recommended to use the utility functions under tigeropen.common.util.order_utils
to create orders locally, such as limit_order
, market_order
.
Parameters
Parameter | Type | Description | Market Order | Limit Order | Stop Order | Stop Limit Order | Trailing Stop Order | Auction Limit Order | Auction Market Order |
---|---|---|---|---|---|---|---|---|---|
account | str | Account id, If not passed, all associated accounts will be returned | optional | optional | optional | optional | optional | optional | optional |
contract | Contract | Contract object | |||||||
action | str | Business direction, 'BUY': buy, 'SELL': sell | |||||||
order_type | str | order type, 'MKT' market order/ 'LMT' limit order/ 'STP' stop loss order/ 'STP_LMT' stop loss limit order/ 'TRAIL' trailing stop order | MKT | LMT | STP | STP_LMT | TRAIL | AL | AM |
quantity | int | order quantity, an integer greater than 0 | |||||||
limit_price | float | limit order price, required when the order type is LMT or STP_LMT or AL | |||||||
aux_price | float | Indicates the stop loss price in the stop loss order; indicates the price difference in the trailing stop loss order | optional | optional | optional | ||||
trail_stop_price | float | Trailing stop order--the price that triggers the stop loss order | |||||||
trailing_percent | float | Trailing stop loss order--percentage (fill in at least one of trailing stop loss order aux_price and trailing_percent) | optional | ||||||
time_in_force | str | The validity period of the order can only be DAY (valid on the day) and GTC (valid before cancellation), the default is DAY.(Hong Kong stock auction order Pre-orders need to be set to OPG, after-hours needs to be DAY) | optional | optional | optional | optional | optional | optional | optional |
outside_rth | bool | True: Allow pre-market and after-hours trading (exclusive to US stocks), False: Not allowed, the default is True. (The market order is only valid in the intraday, and the outside_rth parameter will be ignored) | optional | optional | optional | ||||
order_legs | object | additional order list, example above the parameters | optional | optional | optional | optional | optional | ||
algo_params | object | Algo order parameters, refer to the example above | optional | optional | optional | optional | optional |
example
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
contract = stock_contract(symbol='AAPL', currency='USD')
order = openapi_client.create_order(account, contract, 'BUY', 'LMT', 100, limit_price=5.0)
trade_client. place_order(order)
place_forex_order
TradeClient.place_forex_order(seg_type, source_currency, target_currency, source_amount)
Description
Currency exchange order, return Order object
Parameters
Parameter | Type | Description |
---|---|---|
seg_type | SegmentType | Account segment. Available: SegmentType.SEC for Securities; SegmentType.FUT for Commodities, can be imported from tigeropen.common.consts.SegmentType |
source_currency | Currency | Currency to be converted |
target_currency | Currency | Currency to be received after conversion |
source_amount | Float | Amount of source_currency to convert |
example
from tigeropen.common.util.contract_utils import stock_contract
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
order = trade_client.place_forex_order(seg_type='FUT', source_currency='USD', target_currency='HKD',
source_amount=50)
print(order)
Response Example
Order({'account': '11111', 'id': 30323340487950336, 'order_id': 1447, 'parent_id': None, 'order_time': 1680247928000, 'reason': '', 'trade_time': 1680247928000, 'action': 'SELL', 'quantity': 50, 'filled': 0, 'avg_fill_price': 0.0, 'commission': 0.0, 'realized_pnl': 0.0, 'trail_stop_price': None, 'limit_price': 7.74991, 'aux_price': None, 'trailing_percent': None, 'percent_offset': None, 'order_type': 'LMT', 'time_in_force': 'DAY', 'outside_rth': False, 'order_legs': None, 'algo_params': None, 'algo_strategy': 'LMT', 'secret_key': None, 'liquidation': False, 'discount': 0.0, 'attr_desc': None, 'source': 'OpenApi', 'adjust_limit': None, 'sub_ids': None, 'user_mark': '', 'update_time': 1680247928000, 'expire_time': None, 'can_modify': True, 'contract': USD.HKD/FOREX/HKD, 'status': 'NEW', 'remaining': 50})