{"id":18005613,"url":"https://github.com/areed1192/interactive-broker-python-api","last_synced_at":"2025-04-13T00:48:36.644Z","repository":{"id":44890638,"uuid":"232837137","full_name":"areed1192/interactive-broker-python-api","owner":"areed1192","description":"A python packaged used to interact with the Interactive Brokers REST API.","archived":false,"fork":false,"pushed_at":"2023-08-02T12:11:08.000Z","size":11522,"stargazers_count":403,"open_issues_count":11,"forks_count":128,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-04-13T00:48:33.066Z","etag":null,"topics":["api","fianance","interactive-brokers","python","rest-api","trading"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/areed1192.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["areed1192"],"patreon":"sigmacoding","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-01-09T15:13:44.000Z","updated_at":"2025-04-05T10:42:43.000Z","dependencies_parsed_at":"2023-10-20T17:31:39.045Z","dependency_job_id":null,"html_url":"https://github.com/areed1192/interactive-broker-python-api","commit_stats":{"total_commits":51,"total_committers":6,"mean_commits":8.5,"dds":0.0980392156862745,"last_synced_commit":"e158d67a7cc682fc6a3add34dbe4020276540a29"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/areed1192%2Finteractive-broker-python-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/areed1192%2Finteractive-broker-python-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/areed1192%2Finteractive-broker-python-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/areed1192%2Finteractive-broker-python-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/areed1192","download_url":"https://codeload.github.com/areed1192/interactive-broker-python-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650436,"owners_count":21139672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","fianance","interactive-brokers","python","rest-api","trading"],"created_at":"2024-10-30T00:20:47.460Z","updated_at":"2025-04-13T00:48:36.623Z","avatar_url":"https://github.com/areed1192.png","language":"Python","readme":"# UPDATE\n\nThis repo will soon be updated to include the new \u003chttps://github.com/areed1192/interactive-brokers-api\u003e\nlibrary. The master branch will be overwritten and the old code will need to be updated to reflect\nthe new changes. If you would like to start rewriting your old code, please refer to the new\nbranch `merge-new-repo` or go the link above.\n\n## Unofficial Interactive Brokers API\n\n## Table of Contents\n\n- [Overview](#overview)\n- [What's in the API](#whats-in-the-api)\n- [Setup Requirements](#setup-requirements)\n- [Setup Client Portal](#setup-client-portal)\n- [Setup API Key \u0026 Credentials](#setup-api-key-and-credentials)\n- [Setup Installation](#setup-installation)\n- [Setup Writing Account Information](#setup-writing-account-information)\n- [Usage](#usage)\n- [Features](#features)\n- [Documentation \u0026 Resources](#documentation-and-resources)\n- [Support These Projects](#support-these-projects)\n\n## Overview\n\nThe unofficial Python API client library for Interactive Broker Client Portal Web API allows individuals with Interactive Broker accounts to manage trades, pull historical and real-time data, manage their accounts, create and modify orders all using the Python programming language.\n\nInteractive Broker offers multiple APIs for their clients. If you would like to learn more about their API offerings click on the links below:\n\n- Trade Workstation API, please refer to the [official documentation](http://interactivebrokers.github.io/tws-api/)\n- Client Portal API, please refer to the [official documentation](https://interactivebrokers.github.io/cpwebapi/)\n- Third Party API, plesfe refer to the [official documentation](https://www.interactivebrokers.com/webtradingapi/)\n\n## What's in the API\n\n- Authentication\n- Account Endpoints\n- Market Data Endpoints\n- Trade Endpoints\n- Portfolio Endpoints\n- Scanner Endpoints\n- Portfolio Analysis Endpoints\n- Web Streaming\n\n## Setup Requirements\n\nThe following requirements must be met to use this API:\n\n- A Interactive Broker account, you'll need your account password and account number to use the API.\n- [Java 8](https://developers.redhat.com/products/openjdk/download) update 192 or higher installed (gateway is compatible with higher Java versions including OpenJDK 11).\n- Download the [Beta Client Portal Gateway](https://www.interactivebrokers.com/en/index.php?f=45185)\n\n## Setup Client Portal\n\nOnce you've downloaded the latest client portal or if you chose to use the one provided by the repo. You need to unzip the folder and place it in the repo where this code is stored.\n\n## Setup API Key and Credentials\n\nThe API does not require any API keys to use it, all of the authentication is handled by the Client Portal Gateway. Everytime a user starts a new session with the API they will need to proivde their login credentials for the account they wish to use. The Interactive Broker Web API does offer the ability to use the API using a paper account.\n\n**Important:** Your account number and account password should be kept secret.\n\n## Setup Installation\n\n```console\npip install interactive-broker-python-web-api\n```\n\n## Setup Writing Account Information\n\nThe Client needs specific account information to create a and validate a new session. Where you choose to store this information is up to you, but I'll layout some options here.\n\n**Write a Config File:**\n\nIt's common in Python to have a config file that contains information you need to use during the setup of a script. Additionally, you can make this file in a standard way so that way it's easy to read everytime. In Python, there is a module called `configparser` which can be used to create config files that mimic that of Windows INI files.\n\nTo create a config file using hte `configparser` module, run the script below in a separate file or go to the [Resources Folder](https://github.com/areed1192/interactive-broker-python-api/tree/master/resources) and run the `write_config.py` file.\n\n```python\nimport pathlib\nfrom configparser import ConfigParser\n\n# Initialize a new instance of the `ConfigParser` object.\nconfig = ConfigParser()\n\n# Define a new section called `main`.\nconfig.add_section('main')\n\n# Set the values for the `main` section.\nconfig.set('main', 'REGULAR_ACCOUNT', 'YOUR_ACCOUNT_NUMBER')\nconfig.set('main', 'REGULAR_USERNAME', 'YOUR_ACCOUNT_USERNAME')\n\nconfig.set('main', 'PAPER_ACCOUNT', 'YOUR_ACCOUNT_NUMBER')\nconfig.set('main', 'PAPER_USERNAME', 'YOUR_ACCOUNT_USERNAME')\n\n# Make the `config` folder for the user.\nnew_directory = pathlib.Path(\"config/\").mkdir(parents=True, exist_ok=True)\n\n# Write the contents of the `ConfigParser` object to the `config.ini` file.\nwith open('config/config.ini', 'w+') as f:\n    config.write(f)\n```\n\n**Store the Variables in the Script:**\n\nIf you plan to not share the script with anyone else, then you can store the account info inside the script itself. However, please make sure that you do not make the file public to individuals you don't know.\n\n## Usage\n\nThis example demonstrates how to login to the API and demonstrates sending a request using the `market_data_history` endpoint, using your API key.\n\n```python\nfrom ibw.client import IBClient\n\nREGULAR_ACCOUNT = 'MY_ACCOUNT_NUMBER'\nREGULAR_USERNAME = 'MY_ACCOUNT_USERNAME'\n\n# Create a new session of the IB Web API.\nib_client = IBClient(\n    username=REGULAR_USERNAME,\n    account=REGULAR_ACCOUNT,\n    is_server_running=True\n)\n\n# create a new session.\nib_client.create_session()\n\n# grab the account data.\naccount_data = ib_client.portfolio_accounts()\n\n# print the data.\nprint(account_data)\n\n# Grab historical prices.\naapl_prices = ib_client.market_data_history(conid=['265598'], period='1d', bar='5min')\n\n# print the prices.\nprint(aapl_prices)\n\n# close the current session.\nib_client.close_session()\n```\n\n## Features\n\n### Request Validation\n\nFor certain requests, in a limited fashion, it will help validate your request when possible. For example, when grabbing real-time quotes using the `market_data` endpoint, it will validate the fields you request to ensure they're valid fields for that endpoint.\n\n### Endpoint Verification\n\nTo use certain endpoints, you must call other endpoints before you use it. To help limit the amount of confusion for users, the library will call those endpoints for you behind the scenes so that way you don't need to worry about it.\n\n### Client Portal Download\n\nIf the user doesn't have the clientportal gateway downloaded, then the library will download a copy it, unzip it for you, and quickly allow you to get up and running with your scripts.\n\n## Documentation and Resources\n\n- [Getting Started](https://interactivebrokers.github.io/cpwebapi/index.html#login)\n- [Endpoints](https://interactivebrokers.com/api/doc.html)\n- [Websockets](https://interactivebrokers.github.io/cpwebapi/RealtimeSubscription.html)\n\n## Support these Projects\n\n**Patreon:**\nHelp support this project and future projects by donating to my [Patreon Page](https://www.patreon.com/sigmacoding). I'm always looking to add more content for individuals like yourself, unfortuantely some of the APIs I would require me to pay monthly fees.\n\n**YouTube:**\nIf you'd like to watch more of my content, feel free to visit my YouTube channel [Sigma Coding](https://www.youtube.com/c/SigmaCoding).\n\n**Hire Me:**\nIf you have a project, you think I can help you with feel free to reach out at [coding.sigma@gmail.com](mailto:coding.sigma@gmail.com?subject=[GitHub]%20Project%20Proposal) or fill out the [contract request form](https://forms.office.com/Pages/ResponsePage.aspx?id=DQSIkWdsW0yxEjajBLZtrQAAAAAAAAAAAAa__aAmF1hURFg5ODdaVTg1TldFVUhDVjJHWlRWRzhZRy4u)\n","funding_links":["https://github.com/sponsors/areed1192","https://patreon.com/sigmacoding","https://www.patreon.com/sigmacoding"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fareed1192%2Finteractive-broker-python-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fareed1192%2Finteractive-broker-python-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fareed1192%2Finteractive-broker-python-api/lists"}