A proxy service for the Interactive Brokers API
Project description
IBKR Proxy
import json
import time
import httpx
if __name__ == "__main__":
headers = {
"Accept-Encoding": "gzip,deflate",
"Accept": "*/*",
"Connection": "keep-alive",
"User-Agent": "OAuth",
}
account_id = "DUH999999"
url = f"http://127.0.0.1:9000/v1/api/portfolio/{account_id}/summary"
response = httpx.get(url, headers=headers, verify=False, timeout=5)
response.raise_for_status()
data = response.json()
print(json.dumps(data["accountcode"], indent=2))
url = f"http://127.0.0.1:9000/v1/api/portfolio/{account_id}/allocation"
for _ in range(3):
response = httpx.get(url, headers=headers, verify=False, timeout=5)
response.raise_for_status()
time.sleep(0.5)
Setup
You need to have the following files in the local directory to enable the use of the IBKR OAuth service:
config.yamlandprivatekey.pem.
See the README for the ibauth project for documentation of the config.yaml
content.
Running Locally
uv sync
uv run ibproxy --debug
Running on EC2
To run on an EC2 instance you'd do precisely the same thing as for running
locally. Since the proxy is configured to only answer requests from localhost
this will mean that requests from outside will not reach the proxy. In general
this is a good thing.
For the purpose of illustration suppose that you are running the proxy on an EC2 instance at 3.218.141.190.
There are ways that you can expose the proxy to the outside world.
NGINX
Unless you set up authentication on the proxy this would potentially open up a can of worms.
SSH Tunnel
This is a simple and secure approach. Presumably you have SSH access to the EC2 instance. Run the following on your local machine to set up an SSH tunnel to the EC2 instance:
ssh -N -L 9000:127.0.0.1:9000 ubuntu@3.218.141.190
That will connect port 9000 on your local machine to port 9000 on the EC2 instance. Local requests on port 9000 will then be relayed via the secure tunnel to the proxy on the EC2 instance.
Development
uv sync
uv run ibproxy --debug
You can access the Swagger interface at http://127.0.0.1:9000/docs.
If you are testing changes to ibauth then you can install a local copy.
-
Add this to the end of
pyproject.toml:[tool.uv.sources] ibauth = { path = "../ibauth", editable = true } -
uv lock --upgrade -
uv sync
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ibproxy-0.0.11.tar.gz.
File metadata
- Download URL: ibproxy-0.0.11.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52c4a55faf12b70008ee14f807f187bfdae8cda1e847ecb5d860d01a67906fbc
|
|
| MD5 |
7e4d64bf67d6fdd265f9c613743ee59a
|
|
| BLAKE2b-256 |
71146548fd03054beac4603eb3e8749cb149ea18504e726a09469e0c9512869d
|
File details
Details for the file ibproxy-0.0.11-py3-none-any.whl.
File metadata
- Download URL: ibproxy-0.0.11-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa26e78133853bbf1e06d2a0e02cd6343ec7c08e994cb56c17779e8362a69052
|
|
| MD5 |
b6bc36e4747fa22c3b437f1031c91ddd
|
|
| BLAKE2b-256 |
3e12cda65a6798f5234068b83a1730137c2782d8cb6e745f85110ae1658e7570
|