Keyboard Shortcuts
Likes
Search
Why does placeOrder() require orderId when order already contains orderId?
The short answer to the OP's question is, that the orderId field of the Order object is irrelevant for requests. The orderId is specified only by the "id" parameter of the? request. You can see this even in the code samples IBKR provides in the section of the API documentation, where the Order.orderId field is not explicitly set. Once the order is accepted and placed, TWS/IBGW provides you with a fully initialized Order object through the callback. That object does not only have the orderId initialized (to the "id" value of ) but also fields such as permId and several others. From an API design, this makes a lot of sense. The "id" parameter for each API request establishes a common identifier between your client and TWS/IBGW for all subsequent exchanges related to that request. TWSAPI cannot assume that the complex objects you provide have been initialized properly (they might just contain garbage) and TWS/IBGW needs to have a fail-safe way to inform your client in case the request needs to be rejected. Any error messages related to that request will be tagged with the "id" parameter your client specified in the request. From an application design point of view, your client should never call TWS API requests directly. So you will find yourselves making a small layer between your client and TWSAPI that hides a lot of these details. For order placement, you might want to think about a few helper functions such as "placeMarketOrder", "placeLimitOrder", or "placeBracketOrder" that handle all Order object initialization details. These functions select orderIds and call accordingly. These calls could return the selected orderId (or orderIds) to the trading logic in your client. ´³¨¹°ù²µ±ð²Ô On Sun, Dec 3, 2023 at 01:21 PM, <web3ninja@...> wrote:
Did you get an answer for this ? Why are there two orderIds being sent during placeOrder ? On Sun, May 1, 2022 at 04:30 PM, Drew Carlton wrote: In the Python ?placeOrder(self, orderId:OrderId , contract:Contract, order:Order), the "order" argument already contains an instance variable "". So you are in fact sending two orderIds to placeOrder(). Anybody knows why? Is the "orderId" member variable in "order" even used? |