{"id":9487,"date":"2020-08-28T15:13:00","date_gmt":"2020-08-28T19:13:00","guid":{"rendered":"https:\/\/ibkrcampus.eu\/trading-lessons\/python-complex-orders\/"},"modified":"2024-07-02T19:59:35","modified_gmt":"2024-07-02T19:59:35","slug":"python-complex-orders","status":"publish","type":"trading-lessons","link":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/","title":{"rendered":"TWS Python API Placing Complex Orders"},"content":{"rendered":"<p>In this lesson, we will cover information about placing complex orders.<\/p>\n<p>Before we begin, we will need to add some new imports compared to our usual two. <strong>First, be sure to include \u201cfrom ibapi.tag_value import TagValue\u201d. Then, be sure to add \u201cfrom ibapi.contract import ComboLeg\u201d.<\/strong><\/p>\n<p>Let\u2019s begin by placing some more complex orders. Let\u2019s start by making a Stock Combo, though this same process could be used for Futures or Options Spreads, with different contract details. In this case, I want to simultaneous buy TSLA and sell AAPL as a stock combo.<\/p>\n<p>While moving through this lesson, please keep an open mind as to what Buy\/Sell and Long\/Short mean with respect to combos.<\/p>\n<p><strong>For example, when I enter a short position I need to sell a stock when I have a position of 0.<\/strong><\/p>\n<ul>\n<li>Some traders can be confused by selling shares to enter a position, and \u201cbuying\u201d shares can be used to close a position.<\/li>\n<li>This logic can doubly apply to combo orders. This is because I can BUY a combo, which will leave me short in a position, or I can SELL a combo, which could make me long in that position.<\/li>\n<\/ul>\n<p>To further explain this, let\u2019s start with a brief example. Let\u2019s assume I want to be Long for the total trade. Right now, TSLA currently has a higher share price than AAPL, so I will use that as my base value.<\/p>\n<p>So, if I want to be long for the whole combo, I can enter the trade by either:<\/p>\n<ol>\n<li><strong>Buy the combo, using a positive ratio on TSLA, and a negative ratio on AAPL.<\/strong><\/li>\n<\/ol>\n<p><strong>OR<\/strong><\/p>\n<ol start=\"2\">\n<li><strong>Sell the combo, using a negative ratio on TSLA, and a positive ratio on AAPL. <\/strong><\/li>\n<\/ol>\n<p><strong>This structure is just like a vector-scalar multiplication<\/strong>:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-medium wp-image-15016 lazyload\" data-src=\"\/campus\/wp-content\/uploads\/sites\/3\/2024\/01\/Screen-Shot-2022-11-22-at-1.50.30-PM.png\" alt=\"\" width=\"960\" height=\"236\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 960px; aspect-ratio: 960\/236;\" \/><\/p>\n<p>You can think of buy as a positive one and sell as a negative one.<\/p>\n<p>So, in this matrix you can see that I am trying to buy the whole of the share, and therefore, TSLA as a buy order times the whole of the buy order for the combo will net me a positive TSLA position. Similarly, if I buy the SELL of an AAPL position, I will wholly be negative on that.<\/p>\n<p>We can invert this, and I can then do a sell order for the full combo. If I am selling the TSLA order and selling the whole of the combo, in reality, that is a negative one times a negative one, which brings me to a positive one, or a buy in this example.<\/p>\n<p>Similarly, a negative one, or a sell for the combo times a positive one, or a buy for the AAPL shares, will then give me an overall position of negative or shorting the APPL stock.<\/p>\n<p><strong>Combo Order<\/strong><\/p>\n<p>To start, let\u2019s take a look at our contract. We will be introducing a new concept here. As usual, I will have my contract object, mycontract. For the example, I will include both of my underlyings. In the stock combo example, I will be using AAPL,TSLA; however, for a future or option spread, you will just use your one underlying value, such as ES or SPX respectively. Now, for the secType, I will use BAG. This indicates that I am using a combo order to the system. Exchange and Currency will remain the same as usual.<\/p>\n<p>Now I can begin to add legs to my order. I will create my first leg. To do so, I will create leg1 and set it equal to ComboLeg().<\/p>\n<p>Then I will add my leg\u2019s contract ID, in this case I will use TSLA, 76792991. I will be using a ratio of 1; however, you are welcome to change this value to a higher number as needed. I\u2019ll add my leg\u2019s action, or BUY per my ratio before, and then set my leg\u2019s exchange as SMART.<\/p>\n<p>Then, I can edit my second leg, which I will call leg2. Just like before, I will add AAPL\u2019s conid, another ratio of 1, and exchange of SMART. However, this time I will set my action to SELL.<\/p>\n<p>Now that we have our legs, we can attach them to our contract object. To do this, I will type \u201cmycontract.comboLegs = []\u201d.<\/p>\n<p>Then I can append each leg to my list, \u201cmycontract.comboLegs.append(leg1)\u201d, \u201cmycontract.comboLegs.append(leg2)\u201d.<\/p>\n<p>Keep in mind, I am only doing a 2-leg stock combo. Just like in TWS, I could have up to six legs on a guaranteed spread.<\/p>\n<p>This is everything we need for our contract. Let\u2019s get started with our order object. We have our usual options of a Market or Limit Order; but there are alternative order types such as REL+MKT that we would recommend investigating further in our documentation\u2019s Order section. In this case, I will use a LMT order.<\/p>\n<p>As I mentioned before, TSLA is at about $225 and AAPL is about $150. If we do the math, we know our order would put us at a current price of about $75. I will set my limit price to $80.<\/p>\n<p>Our other order attributes will be the same, except in my case I will be adding myorder.smartComboRoutingParams as an empty list. These are for unique values for combo orders. In particular, because I am using a Non-guaranteed order, I will need to approve this for the system. To do so, I will append to that list, \u201cTagValue(\u2018NonGuaranteed\u2019, \u20181\u2019)\u201d to approve the use of non-guaranteed orders.<\/p>\n<p>With that set, I can now submit my order. If we look at the order in TWS, we will see this order pair reflected appropriately.<\/p>\n<p>Before moving on, I would like to note that this combo order structure is the same structure used for Bear Call\/Bull Put orders, Iron Condors, and more. Please reference our documentation for further information.<\/p>\n<p><strong>Bracket Order<\/strong><\/p>\n<p>With the Combo order complete, I would like to now build out a bracket order. For bracket orders, we can use a different approach than what was used for combos. Here, I will only be making a profit-taker and stop-loss bracket order for an AAPL stock order. This will start as a standard Limit order just like in our prior videos. I will add my action here as a BUY, though instead of my usual \u201cmyorder\u201d name, I will call this \u201cparent\u201d. <strong>I will also add \u201cparent.transmit = False\u201d so we do not prematurely submit and\/or execute a trade.<\/strong><\/p>\n<p>Now I have my parent order, but I need to go ahead and build my profit taker initially. To do so, I will create my order object, profit_taker. Now I\u2019ll set my order ID to my parentId + 1, and then my parent ID accordingly. I\u2019ll set my action to SELL, another orderType of LMT, and a limit price. Once again, I\u2019ll leave my profit_taker.transmit = False.<\/p>\n<p>And now making this one last order, this time for stop loss. Like before, I will set my stop_loss as my order object name. Then I can deem my stop_loss action as a SELL.<\/p>\n<p>Now I can set my orderType to \u201cSTP\u201d in my stop loss, and then set my stop_loss.auxPrice for the stop price. In this instance, I will change my stop_loss.transmit value to TRUE now that I have all of my orders.<\/p>\n<p>Now we can place all of these orders. As usual, I can use my self.placeOrder() request to start placing my orders. I will go ahead and place my order for my parent order, with my parent orderId, mycontract, and then the parent object.<\/p>\n<p>We will then do the same for my profit_taker, with its respective values, and then finally we can end with our stop_loss. I would note that we have to use the parent first, as the other two pieces of the order build off the parent order ID.<\/p>\n<p>Conversely, we must end with the stop loss in this scenario as this contains the final order transmission from that transmit.true or transmit=false.<\/p>\n<p>If we run our code, we can see in Trader Workstation our bracket order posted in our orders summary. We will be able to see these values in our openOrder or orderStatus callbacks.<\/p>\n<p>Bracket orders use the same structure as Hedging orders, and OCA orders. We would advise reviewing our documentation further if you are interested in using these order types.<\/p>\n<p><strong>Order Management<\/strong><\/p>\n<p>It is important to bear in mind the <strong>order efficiency ratio<\/strong> which tracks the ratio of messages sent or submissions, modifications, and cancellations, to the number of orders which actually execute. In general, this ratio is expected to be around <strong>20 or less<\/strong> and is automatically tracked by the Interactive Brokers servers. Please review our IBKRinfo articles describing this topic for more information as well as the calculations to find these values.<\/p>\n<p>This concludes our video on Complex Orders in the TWS API. Thank you for watching, and we look forward to having you join us for more TWS Python API lessons.<\/p>\n<p><strong>Code Snippet: Bracket Order\u00a0<\/strong><\/p>\n<h4>\u00a0<\/h4>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from ibapi.client import *\nfrom ibapi.wrapper import *\nfrom ibapi.contract import ComboLeg\nfrom ibapi.tag_value import TagValue\n\nclass TestApp(EClient, EWrapper):\n    def __init__(self):\n        EClient.__init__(self, self)\n\n    def nextValidId(self, orderId: int):\n        # Order info\n        mycontract = Contract()\n        mycontract.symbol = \"AAPL\"\n        mycontract.secType = \"STK\"\n        mycontract.exchange = \"SMART\"\n        mycontract.currency = \"USD\"\n\n        parent = Order()\n        parent.orderId = orderId\n        parent.orderType = \"LMT\"\n        parent.lmtPrice = 140\n        parent.action = \"BUY\"\n        parent.totalQuantity = 10\n        parent.transmit = False\n\n        profit_taker = Order()\n        profit_taker.orderId = parent.orderId + 1\n        profit_taker.parentId = parent.orderId\n        profit_taker.action = \"SELL\"\n        profit_taker.orderType = \"LMT\"\n        profit_taker.lmtPrice = 137\n        profit_taker.totalQuantity = 10\n        profit_taker.transmit = False\n\n        stop_loss = Order()\n        stop_loss.orderId = parent.orderId + 2\n        stop_loss.parentId = parent.orderId\n        stop_loss.orderType = \"STP\"\n        stop_loss.auxPrice = 155\n        stop_loss.action = \"SELL\"\n        stop_loss.totalQuantity = 10\n        stop_loss.transmit = True\n\n        self.placeOrder(parent.orderId, mycontract, parent)\n        self.placeOrder(profit_taker.orderId, mycontract, profit_taker)\n        self.placeOrder(stop_loss.orderId, mycontract, stop_loss)\n\n    def openOrder(self, orderId: OrderId, contract: Contract, order: Order, orderState: OrderState):\n        print(f\"openOrder: {orderId}, contract: {contract}, order: {order}, Maintenance Margin: {orderState.maintMarginChange}\")\n\n    def orderStatus(self, orderId: OrderId, status: str, filled: float, remaining: float, avgFillPrice: float, permId: int, parentId: int, lastFillPrice: float, clientId: int, whyHeld: str, mktCapPrice: float):\n        print(f\"orderStatus. orderId: {orderId}, status:  {status}, filled: {filled}, remaining: {remaining}, avgFillPrice: {avgFillPrice}, permId: {permId}, parentId: {parentId}, lastFillPrice: {lastFillPrice}, clientId: {clientId}, whyHeld: {whyHeld}, mktCapPrice: {mktCapPrice}\")\n\n    def execDetails(self, reqId: int, contract: Contract, execution: Execution):\n        print(f\"execDetails. reqId: {reqId}, contract: {contract}, execution:  {execution}\")\n\napp = TestApp()\napp.connect(\"127.0.0.1\", 7497, 1000)\napp.run()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Combo Order Snippet<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from ibapi.client import *\nfrom ibapi.wrapper import *\nfrom ibapi.contract import ComboLeg\nfrom ibapi.tag_value import TagValue\n\nclass TestApp(EClient, EWrapper):\n    def __init__(self):\n        EClient.__init__(self, self)\n\n    def nextValidId(self, orderId: int):\n        # Order info\n        mycontract = Contract()\n        mycontract.symbol = \"AAPL,TSLA\"\n        mycontract.secType = \"BAG\"\n        mycontract.exchange = \"SMART\"\n        mycontract.currency = \"USD\"\n\n        leg1 = ComboLeg()\n        leg1.conId = 76792991\n        leg1.ratio = 1\n        leg1.action = \"BUY\"\n        leg1.exchange = \"SMART\"\n\n        leg2 = ComboLeg()\n        leg2.conId = 265598\n        leg2.ratio = 1\n        leg2.action = \"SELL\"\n        leg2.exchange = \"SMART\"\n\n        mycontract.comboLegs = []\n        mycontract.comboLegs.append(leg1)\n        mycontract.comboLegs.append(leg2)\n\n        myorder = Order()\n        myorder.orderId = orderId\n        myorder.action = \"BUY\"\n        myorder.orderType = \"LMT\"\n        myorder.lmtPrice = 80\n        myorder.totalQuantity = 10\n        myorder.tif = \"GTC\"\n        myorder.smartComboRoutingParams = []\n        myorder.smartComboRoutingParams.append(TagValue('NonGuaranteed', '1'))\n\n        self.placeOrder(orderId, mycontract, myorder)\n\n\n    def openOrder(self, orderId: OrderId, contract: Contract, order: Order, orderState: OrderState):\n        print(f\"orderId: {orderId}, contract: {contract}, order: {order}, Maintenance Margin: {orderState.maintMarginChange}\")\n\n    def orderStatus(self, orderId: OrderId, status: str, filled: float, remaining: float, avgFillPrice: float, permId: int, parentId: int, lastFillPrice: float, clientId: int, whyHeld: str, mktCapPrice: float):\n        print(f\"orderStatus. orderId: {orderId}, status:  {status}, filled: {filled}, remaining: {remaining}, avgFillPrice: {avgFillPrice}, permId: {permId}, parentId: {parentId}, lastFillPrice: {lastFillPrice}, clientId: {clientId}, whyHeld: {whyHeld}, mktCapPrice: {mktCapPrice}\")\n\n    def execDetails(self, reqId: int, contract: Contract, execution: Execution):\n        print(f\"execDetails. reqId: {reqId}, contract: {contract}, execution:  {execution}\")\n\napp = TestApp()\napp.connect(\"127.0.0.1\", 7497, 1000)\napp.run()\n    <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this lesson, we will walk through placing complex orders, such as a Bracket and Combo orders, using the TWS Python API.<\/p>\n","protected":false},"author":850,"featured_media":195703,"parent":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":true,"footnotes":""},"contributors-categories":[149],"traders-academy":[101,103,105],"class_list":["post-9487","trading-lessons","type-trading-lessons","status-publish","has-post-thumbnail","contributors-categories-interactive-brokers","traders-academy-intermediate-trading","traders-academy-level","traders-academy-trading-lesson"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Archives | Traders&#039; Academy | IBKR Campus<\/title>\n<meta name=\"description\" content=\"In this lesson, we will walk through placing complex orders, such as a Bracket and Combo orders, using the TWS Python API.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/trading-lessons\/9487\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TWS Python API Placing Complex Orders\" \/>\n<meta property=\"og:description\" content=\"In this lesson, we will walk through placing complex orders, such as a Bracket and Combo orders, using the TWS Python API.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus EU\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-02T19:59:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.eu\/campus\/wp-content\/uploads\/sites\/3\/2020\/08\/less8-py.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"TWS Python API Placing Complex Orders\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/python-complex-orders\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/python-complex-orders\\\/\",\n\t            \"name\": \"TWS Python API Placing Complex Orders\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.eu\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/python-complex-orders\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/python-complex-orders\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/3\\\/2020\\\/08\\\/less8-py.jpg\",\n\t            \"datePublished\": \"2020-08-28T19:13:00+00:00\",\n\t            \"dateModified\": \"2024-07-02T19:59:35+00:00\",\n\t            \"description\": \"In this lesson, we will walk through placing complex orders, such as a Bracket and Combo orders, using the TWS Python API.\",\n\t            \"breadcrumb\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/python-complex-orders\\\/#breadcrumb\"\n\t            },\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/python-complex-orders\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/python-complex-orders\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/3\\\/2020\\\/08\\\/less8-py.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/3\\\/2020\\\/08\\\/less8-py.jpg\",\n\t            \"width\": 1920,\n\t            \"height\": 1080,\n\t            \"caption\": \"Working on laptop, graphic\"\n\t        },\n\t        {\n\t            \"@type\": \"BreadcrumbList\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/python-complex-orders\\\/#breadcrumb\",\n\t            \"itemListElement\": [\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 1,\n\t                    \"name\": \"Home\",\n\t                    \"item\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/\"\n\t                },\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 2,\n\t                    \"name\": \"Academy Lessons\",\n\t                    \"item\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/\"\n\t                },\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 3,\n\t                    \"name\": \"TWS Python API Placing Complex Orders\"\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.eu\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.eu\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus EU\",\n\t            \"description\": \"\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.eu\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Archives | Traders' Academy | IBKR Campus","description":"In this lesson, we will walk through placing complex orders, such as a Bracket and Combo orders, using the TWS Python API.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/trading-lessons\/9487\/","og_locale":"en_US","og_type":"article","og_title":"TWS Python API Placing Complex Orders","og_description":"In this lesson, we will walk through placing complex orders, such as a Bracket and Combo orders, using the TWS Python API.","og_url":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/","og_site_name":"IBKR Campus EU","article_modified_time":"2024-07-02T19:59:35+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/www.interactivebrokers.eu\/campus\/wp-content\/uploads\/sites\/3\/2020\/08\/less8-py.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_title":"TWS Python API Placing Complex Orders","twitter_misc":{"Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/","url":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/","name":"TWS Python API Placing Complex Orders","isPartOf":{"@id":"https:\/\/ibkrcampus.eu\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.eu\/campus\/wp-content\/uploads\/sites\/3\/2020\/08\/less8-py.jpg","datePublished":"2020-08-28T19:13:00+00:00","dateModified":"2024-07-02T19:59:35+00:00","description":"In this lesson, we will walk through placing complex orders, such as a Bracket and Combo orders, using the TWS Python API.","breadcrumb":{"@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/#primaryimage","url":"https:\/\/www.interactivebrokers.eu\/campus\/wp-content\/uploads\/sites\/3\/2020\/08\/less8-py.jpg","contentUrl":"https:\/\/www.interactivebrokers.eu\/campus\/wp-content\/uploads\/sites\/3\/2020\/08\/less8-py.jpg","width":1920,"height":1080,"caption":"Working on laptop, graphic"},{"@type":"BreadcrumbList","@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/python-complex-orders\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.interactivebrokers.eu\/campus\/"},{"@type":"ListItem","position":2,"name":"Academy Lessons","item":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/"},{"@type":"ListItem","position":3,"name":"TWS Python API Placing Complex Orders"}]},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.eu\/campus\/#website","url":"https:\/\/ibkrcampus.eu\/campus\/","name":"IBKR Campus EU","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.eu\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/trading-lessons\/9487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/trading-lessons"}],"about":[{"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/types\/trading-lessons"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/users\/850"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/comments?post=9487"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/trading-lessons\/9487\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/media\/195703"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/media?parent=9487"}],"wp:term":[{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/contributors-categories?post=9487"},{"taxonomy":"traders-academy","embeddable":true,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/traders-academy?post=9487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}