Skip to content

DanielGMorena/ibkr-web-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📈 IBKR Web API

Build Linted with Ruff Typed with Mypy License Platform

An easy-to-use local web API for accessing Interactive Brokers (IBKR) using ib_insync. Designed for end users to run a standalone executable (ibkr-web-api.exe) and interact with their local IB TWS or IB Gateway instance via HTTP calls.


🚀 Overview

  • ✅ Single-file executable for Windows users: ibkr-web-api.exe
  • 🧠 Configuration via external config.yml
  • 🔌 Connects directly to a local TWS or Gateway instance
  • 🌐 Exposes a RESTful FastAPI server to query IBKR-TWS data.
  • 🔐 Intended for local use only (due to TWS dependency)

📦 Getting Started

1. Download the executable

Download the latest release from the GitHub Releases page.

2. Prepare a config.yml file

Create a config.yml file in the same folder or any path of your choice. You can pass its path via command-line argument.

Example:

ib:
  host: localhost
  port: 7497

logging:
  level: DEBUG

fastapi:
  title: IBKR Web API
  description: RESTful API for accessing Interactive Brokers historical market data
  version: "1.0"
  docs_url: /docs
  redoc_url: /redoc
  openapi_url: /openapi.json
  debug: false
  allow_origins: ["*"]

uvicorn:
  host: "127.0.0.1"
  port: 8000

▶️ Running the App

Ensure your IB TWS or IB Gateway is running locally on the specified port (default: 7497).

Then, launch the API server:

ibkr-web-api.exe --config path\to\your\config.yml

If --config is omitted, it will use the specified default config.

Once running, access the API via browser or HTTP client:


⚠️ Important Notes

  • This app is intended to run on the same machine as your IBKR TWS/Gateway.
  • It is not designed to be publicly hosted — all communication is assumed to be local (localhost).
  • All data comes via your authenticated TWS-IBKR session.

🛠️ Advanced Usage (Developers)

If you're a developer and prefer running from source:

git clone https://github.com/danielgmorena/ibkr-web-api.git
cd ibkr-web-api
poetry install
poetry run uvicorn app.main:app --reload

🤝 Contributing

Contributions are welcome!

You can extend this project by wrapping more ib_insync functionality as API endpoints. New endpoints should be placed under the app/api/ directory.

Before submitting a pull request, make sure your code is:

  • Type-safe via mypy
  • Linted via ruff
  • Tested with pytest and includes coverage

Example

To add support for a new IBKR data method:

  1. Create a file under app/api/ (e.g. app/api/open_orders.py)
  2. Register the router in app/main.py or similar
  3. Write tests under tests/
  4. Run:
mypy app
ruff check .
pytest .

Then open a pull request! 🚀


About

FastAPI wrapper for handling Interactive Brokers TWS ib_insync functions

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •