Place Order

View as MarkdownOpen in Claude

place_order_sync(

contract: [Contract Object](/tws-api/doc/contracts-financial-instruments/the-contract-object). Contract to trade.

order: [Order Object](/tws-api/doc/orders/the-order-and-contract-objects). Order parameters to be traded.

timeout: Integer. Uses default timeout value passed to TWSSyncClass. Please be aware the timeout is only relevant for the response details. The order will submit in accordance with the order object’s details.

)

contract = Contract()
contract.symbol = "AAPL"
contract.secType = "STK"
contract.exchange = "SMART"
contract.primaryExchange = "NASDAQ"
contract.currency = "USD"
order = Order()
order.action = "BUY"
order.orderType = "LMT"
order.totalQuantity = 100
order.lmtPrice = 250
app.place_order_sync(contract, order)

Upon placing an order, a dictionary containing all of the order status’s information will be returned. As the response is static, refer to the [get_open_orders](/tws-api/doc/synchronous-api/open-orders) function more more details on the current order status.

Response Object

{
orderId: Integer. The identifier for the order. Relevant for order tracking, modification, and cancellation.
status: String. The current status of the order. See [Order Status](/tws-api/doc/order-management/order-status/introduction-message) for more details.
filled: Decimal. The total quantity of executed shares for the order.
remaining: Decimal. The total quantity of shares that have yet to execute for the order.
avgFillPrice: Float. The average execution price across fills.
permId: Integer. The permanent identifier for the order. This is calculated based on orderId and client ID for internal order tracking.
parentId: Integer. The orderId for the parent of this contract. Will return 0 unless trading a bracket or OCA order.
lastFillPrice: Float. The price of the most recent execution for the order.
clientId: Integer. The identifier for which client ID the order was placed through. Orders can only be cancelled or modified by their on the [clientId they are bound to](/tws-api/doc/orders/modifying-orders).
whyHeld: String. In the event an order is held instead of being transmitted, the reason will be documented here.
mktCapPrice: Float. If an order is capped due to it exceeding the market price and the price is automatically modified, the modified price will be returned. Otherwise 0.0 is displayed.
}

{'orderId': 347, 'status': 'PreSubmitted', 'filled': Decimal('0'), 'remaining': Decimal('100'), 'avgFillPrice': 0.0, 'permId': 979867961, 'parentId': 0, 'lastFillPrice': 0.0, 'clientId': 8675309, 'whyHeld': '', 'mktCapPrice': 0.0}