Skip to main content

A proxy service for the Interactive Brokers API

Project description

IBKR Proxy

codecov

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.yaml and
  • privatekey.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.

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

ibproxy-0.0.6.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ibproxy-0.0.6-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file ibproxy-0.0.6.tar.gz.

File metadata

  • Download URL: ibproxy-0.0.6.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.2

File hashes

Hashes for ibproxy-0.0.6.tar.gz
Algorithm Hash digest
SHA256 ef35c5df2a00ff2a4b9414fdbd9e8fb74019232f043ce40e9afd84f6bff6b863
MD5 8ca64edc81f0a255462d4b700c421a07
BLAKE2b-256 826860f3462d6db6cdfd96c8efdc21994e96def8ac7bb4af988057c1ac954f9c

See more details on using hashes here.

File details

Details for the file ibproxy-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: ibproxy-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.2

File hashes

Hashes for ibproxy-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ebe2ffba4968adccb3de9fa40827fe76c0738bfacc51eb27ee25a8bea76d6c85
MD5 30179f02fa0e35b8c7b962c4caa7a8f1
BLAKE2b-256 9152b080e5ea32184b35568e452abc27b2a426c97e224bbdf0d2d5071fce8023

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page