{"id":213838,"date":"2024-10-17T12:31:03","date_gmt":"2024-10-17T16:31:03","guid":{"rendered":"https:\/\/ibkrcampus.com\/campus\/?p=213838"},"modified":"2024-11-04T10:49:44","modified_gmt":"2024-11-04T15:49:44","slug":"automate-trading-strategies-with-the-powerful-ib-api","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/","title":{"rendered":"Automate Trading Strategies with the Powerful IB API"},"content":{"rendered":"\n<p><em>The article \u201cAutomate Trading Strategies with the Powerful IB API\u201d was originally on <a href=\"https:\/\/www.pyquantnews.com\/the-pyquant-newsletter\/automate-trading-strategies-powerful-ib-api\">PyQuantNews<\/a>.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-automate-trading-strategies-with-the-powerful-ib-api\">Automate trading strategies with the powerful IB API<\/h2>\n\n\n\n<p>Trading in 2024 is overwhelming.<\/p>\n\n\n\n<p>Especially when it comes to automating trading strategies.<\/p>\n\n\n\n<p>Many traders rely on manual processes or basic automation, which often fall short by being too slow or not adaptable enough. I\u2019ve been there myself, trying to juggle automation with using my own intuition.<\/p>\n\n\n\n<p>The good news is you can solve this problem by using Python to automate your trading strategies with the Interactive Brokers API (IB API).<\/p>\n\n\n\n<p>I\u2019ve been using Interactive Brokers for more than 10 years. The IB API is infamous because of how complicated it can be to get up and running.<\/p>\n\n\n\n<p>In today\u2019s newsletter, I put it altogether so you can quickly use the IB API to automate your first trading strategy.<\/p>\n\n\n\n<p>Let\u2019s go!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-automate-trading-strategies-with-the-powerful-ib-api-0\">Automate trading strategies with the powerful IB API<\/h2>\n\n\n\n<p>Automating trading strategies is a powerful tool for traders seeking efficiency. Interactive Brokers offers a Python API that automates trading strategies.<\/p>\n\n\n\n<p>This API provides access to market data, account information, and order management.<\/p>\n\n\n\n<p>Professionals leverage the API for algorithmic trading, using predefined rules and models for executing trades. The API&#8217;s comprehensive functionality is great for both novice and experienced traders aiming for precise control over their trading strategies.<\/p>\n\n\n\n<p>Let&#8217;s see how it works with Python.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Imports and set up<\/h3>\n\n\n\n<p>You can download and install the Interactive Brokers API from GitHub. Here&#8217;s&nbsp;<a href=\"https:\/\/www.notion.so\/ac387acbb07c4f70850827b387c93ffb?pvs=21\">a step-by-step guide<\/a>. Once the libraries are installed, you can import them.<\/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=\"\">import time\nimport threading\nfrom datetime import datetime\nfrom typing import Dict, Optional\nimport pandas as pd\nimport warnings\n\nfrom ibapi.client import EClient\nfrom ibapi.wrapper import EWrapper\nfrom ibapi.contract import Contract\nfrom ibapi.order import Order\nfrom ibapi.common import BarData<\/pre>\n\n\n\n<p>Our strategy will look for breakouts using a popular technical indicator called Donchian Channels.<\/p>\n\n\n\n<p>Here, we define a function to calculate Donchian Channels for given price data over a specified period. It calculates the upper and lower bands and the middle line.<\/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=\"\">def donchian_channel(df: pd.DataFrame, period: int = 30) -&gt; pd.DataFrame:\n\n    df[\"upper\"] = df[\"high\"].rolling(window=period).max()\n\n    df[\"lower\"] = df[\"low\"].rolling(window=period).min()\n\n    df[\"mid\"] = (df[\"upper\"] + df[\"lower\"]) \/ 2\n\n    return df<\/pre>\n\n\n\n<p>This function takes a DataFrame containing price data and a period for the calculation. It computes the upper band as the highest high over the period and the lower band as the lowest low. The middle line is calculated as the average of the upper and lower bands.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create a class to interact with Interactive Brokers API<\/h3>\n\n\n\n<p>This section defines a TradingApp class that interacts with the IB API. This class handles connections, data retrieval, and order placement. It\u2019s our trading app.<\/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=\"\">class TradingApp(EClient, EWrapper):\n\n    def __init__(self) -&gt; None:\n\n        EClient.__init__(self, self)\n        self.data: Dict[int, pd.DataFrame] = {}\n        self.nextOrderId: Optional[int] = None\n\n    def error(self, reqId: int, errorCode: int, errorString: str, advanced: any) -&gt; None:\n\n        print(f\"Error: {reqId}, {errorCode}, {errorString}\")\n\n    def nextValidId(self, orderId: int) -&gt; None:\n\n        super().nextValidId(orderId)\n        self.nextOrderId = orderId\n\n    def get_historical_data(self, reqId: int, contract: Contract) -&gt; pd.DataFrame:\n\n        self.data[reqId] = pd.DataFrame(columns=[\"time\", \"high\", \"low\", \"close\"])\n        self.data[reqId].set_index(\"time\", inplace=True)\n        self.reqHistoricalData(\n            reqId=reqId,\n            contract=contract,\n            endDateTime=\"\",\n            durationStr=\"1 D\",\n            barSizeSetting=\"1 min\",\n            whatToShow=\"MIDPOINT\",\n            useRTH=0,\n            formatDate=2,\n            keepUpToDate=False,\n            chartOptions=[],\n        )\n        time.sleep(5)\n        return self.data[reqId]\n\n    def historicalData(self, reqId: int, bar: BarData) -&gt; None:\n\n        df = self.data[reqId]\n\n        df.loc[\n            pd.to_datetime(bar.date, unit=\"s\"), \n            [\"high\", \"low\", \"close\"]\n        ] = [bar.high, bar.low, bar.close]\n\n        df = df.astype(float)\n\n        self.data[reqId] = df\n\n    @staticmethod\n    def get_contract(symbol: str) -&gt; Contract:\n\n        contract = Contract()\n        contract.symbol = symbol\n        contract.secType = \"STK\"\n        contract.exchange = \"SMART\"\n        contract.currency = \"USD\"\n        return contract\n\n    def place_order(self, contract: Contract, action: str, order_type: str, quantity: int) -&gt; None:\n\n        order = Order()\n        order.action = action\n        order.orderType = order_type\n        order.totalQuantity = quantity\n\n        self.placeOrder(self.nextOrderId, contract, order)\n        self.nextOrderId += 1\n        print(\"Order placed\")<\/pre>\n\n\n\n<p>The TradingApp class extends EClient and EWrapper to interact with the IB API.<\/p>\n\n\n\n<p>It initializes the client and wrapper components and sets up data storage. The error method handles API errors, while nextValidId sets the next valid order ID. The get_historical_data method requests historical market data for a given contract, storing it in a DataFrame. The historicalData method processes and stores the received data.<\/p>\n\n\n\n<p>The get_contract method creates a stock contract, and the place_order method places trades using the provided contract, action, order type, and quantity.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Connect the trading app and request data<\/h3>\n\n\n\n<p>Once we build our trading app, we will connect to it and look for signals.<\/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=\"\">app = TradingApp()\n\napp.connect(\"127.0.0.1\", 7497, clientId=5)\n\nthreading.Thread(target=app.run, daemon=True).start()\n\nwhile True:\n    if isinstance(app.nextOrderId, int):\n        print(\"connected\")\n        break\n    else:\n        print(\"waiting for connection\")\n        time.sleep(1)\n\n\nnvda = TradingApp.get_contract(\"NVDA\")<\/pre>\n\n\n\n<p>Once the app is connected, you can download historical data.<\/p>\n\n\n\n<p><br><\/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=\"\">data = app.get_historical_data(99, nvda)\ndata.tail()<\/pre>\n\n\n\n<p>The code creates an instance of the TradingApp class and connects it to the IB API using the IP address, port, and client ID. Note the port is the default for the IB paper trading account.<\/p>\n\n\n\n<p>It then starts the app on a separate thread to allow code execution to continue. A loop checks for a successful connection by verifying the nextOrderId.<\/p>\n\n\n\n<p>Once connected, it defines a contract for the stock symbol NVDA and requests historical data for the last trading day using a specified request ID. The Donchian Channels are then calculated for the acquired data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Implement trading logic based on Donchian Channels<\/h3>\n\n\n\n<p>Now, we check for breakouts and places buy or sell orders accordingly.<\/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=\"\">period = 30\n\nwhile True:\n\n    print(\"Getting data for contract...\")\n    data = app.get_historical_data(99, nvda)\n\n    if len(data) &lt; period:\n        print(f\"There are only {len(data)} bars of data, skipping...\")\n        continue\n\n    print(\"Computing the Donchian Channel...\")\n    donchian = donchian_channel(data, period=period)\n\n    last_price = data.iloc[-1].close\n\n    upper, lower = donchian[[\"upper\", \"lower\"]].iloc[-1]\n\n    print(f\"Check if last price {last_price} is outside the channels {upper} and {lower}\")\n\n    if last_price &gt;= upper:\n        print(\"Breakout detected, going long...\")\n        app.place_order(nvda, \"BUY\", \"MKT\", 10)\n\n    elif last_price &lt;= lower:\n        print(\"Breakout detected, going short...\")\n        app.place_order(nvda, \"SELL\", \"MKT\", 10)<\/pre>\n\n\n\n<p>The code sets the period for the Donchian Channels to 30. It enters an infinite loop to request data and check for trading opportunities continuously.<\/p>\n\n\n\n<p>It retrieves historical data for the NVDA contract and skips further processing if there is insufficient data. It then calculates the Donchian Channels and gets the last traded price.<\/p>\n\n\n\n<p>The code compares the last price with the upper and lower channels to detect breakouts. If a breakout to the upside is detected, it places a buy market order for 10 shares. If a breakout to the downside is detected, it places a sell market order for 10 shares.<\/p>\n\n\n\n<p>To exit this loop, stop the Python kernel. Once you\u2019re done, disconnect the app.<\/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=\"\">app.disconnect()<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Your next steps<\/h3>\n\n\n\n<p>This is a simple example of downloading historical market data, looking for signals, and executing trades with Python. It lacks risk and position management, which you should implement based on your experience and risk tolerance. The biggest area for improvement is checking for existing positions before entering new trades.<\/p>\n\n\n\n<p>Finally, make sure to run this code in your paper trading account. Trading it live will expose you to risk of loss.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Automate trading strategies with the powerful IB API.<\/p>\n","protected":false},"author":1518,"featured_media":213915,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":true,"footnotes":""},"categories":[339,340,343,349,338,341],"tags":[851,17900,1014,1015,575,595],"contributors-categories":[17813],"class_list":{"0":"post-213838","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-api-development","9":"category-programing-languages","10":"category-python-development","11":"category-ibkr-quant-news","12":"category-quant-development","13":"tag-algo-trading","14":"tag-donchian-channels","15":"tag-eclient","16":"tag-ewrapper","17":"tag-ibkr-api","18":"tag-python","19":"contributors-categories-pyquantnews"},"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 v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Automate Trading Strategies with the Powerful IB API<\/title>\n<meta name=\"description\" content=\"Automate trading strategies with the powerful IB 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\/posts\/213838\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automate Trading Strategies with the Powerful IB API\" \/>\n<meta property=\"og:description\" content=\"Automate trading strategies with the powerful IB API.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-17T16:31:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-04T15:49:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/10\/ibkr-api-programming-blue-background.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Jason\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jason\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 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\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Jason\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/41e9bacc875edb13ed6288f4ffb2afec\"\n\t            },\n\t            \"headline\": \"Automate Trading Strategies with the Powerful IB API\",\n\t            \"datePublished\": \"2024-10-17T16:31:03+00:00\",\n\t            \"dateModified\": \"2024-11-04T15:49:44+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/\"\n\t            },\n\t            \"wordCount\": 820,\n\t            \"commentCount\": 14,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/10\\\/ibkr-api-programming-blue-background.png\",\n\t            \"keywords\": [\n\t                \"Algo Trading\",\n\t                \"Donchian Channels\",\n\t                \"EClient\",\n\t                \"EWrapper\",\n\t                \"IBKR API\",\n\t                \"Python\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"IBKR API Development\",\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/\",\n\t            \"name\": \"Automate Trading Strategies with the Powerful IB API | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/10\\\/ibkr-api-programming-blue-background.png\",\n\t            \"datePublished\": \"2024-10-17T16:31:03+00:00\",\n\t            \"dateModified\": \"2024-11-04T15:49:44+00:00\",\n\t            \"description\": \"Automate trading strategies with the powerful IB API.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/\"\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.com\\\/campus\\\/ibkr-quant-news\\\/automate-trading-strategies-with-the-powerful-ib-api\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/10\\\/ibkr-api-programming-blue-background.png\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/10\\\/ibkr-api-programming-blue-background.png\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"API\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/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            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/41e9bacc875edb13ed6288f4ffb2afec\",\n\t            \"name\": \"Jason\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/jasonpyquantnews\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Automate Trading Strategies with the Powerful IB API","description":"Automate trading strategies with the powerful IB 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\/posts\/213838\/","og_locale":"en_US","og_type":"article","og_title":"Automate Trading Strategies with the Powerful IB API","og_description":"Automate trading strategies with the powerful IB API.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/","og_site_name":"IBKR Campus US","article_published_time":"2024-10-17T16:31:03+00:00","article_modified_time":"2024-11-04T15:49:44+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/10\/ibkr-api-programming-blue-background.png","type":"image\/png"}],"author":"Jason","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jason","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/"},"author":{"name":"Jason","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/41e9bacc875edb13ed6288f4ffb2afec"},"headline":"Automate Trading Strategies with the Powerful IB API","datePublished":"2024-10-17T16:31:03+00:00","dateModified":"2024-11-04T15:49:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/"},"wordCount":820,"commentCount":14,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/10\/ibkr-api-programming-blue-background.png","keywords":["Algo Trading","Donchian Channels","EClient","EWrapper","IBKR API","Python"],"articleSection":["Data Science","IBKR API Development","Programming Languages","Python Development","Quant","Quant Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/","name":"Automate Trading Strategies with the Powerful IB API | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/10\/ibkr-api-programming-blue-background.png","datePublished":"2024-10-17T16:31:03+00:00","dateModified":"2024-11-04T15:49:44+00:00","description":"Automate trading strategies with the powerful IB API.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/automate-trading-strategies-with-the-powerful-ib-api\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/10\/ibkr-api-programming-blue-background.png","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/10\/ibkr-api-programming-blue-background.png","width":1000,"height":563,"caption":"API"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/41e9bacc875edb13ed6288f4ffb2afec","name":"Jason","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/jasonpyquantnews\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/10\/ibkr-api-programming-blue-background.png","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/213838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/1518"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=213838"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/213838\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/213915"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=213838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=213838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=213838"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=213838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}