Skip to main content

Interactive Brokers OAuth

Project description

IBKR Authentication Workflow

import logging
import time

import ibauth

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s [%(levelname)7s] %(message)s",
)

logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("charset_normalizer").setLevel(logging.WARNING)

if __name__ == "__main__":
    auth = ibauth.auth_from_yaml("config.yaml")

    auth.get_access_token()
    auth.get_bearer_token()

    auth.ssodh_init()
    auth.validate_sso()

    # This will keep session alive.
    for _ in range(3):
        auth.tickle()
        time.sleep(10)

    # Dynamically change the API domain.
    #
    auth.domain = "5.api.ibkr.com"

    auth.tickle()

    auth.logout()

Documentation for the IBKR Web API is here.

  1. Pull the repository.

  2. Create and activate a virtual environment.

  3. Install dependencies from requirements.txt.

  4. Create a YAML configuration file:

    client_id: ""
    client_key_id: ""
    credential: ""
    private_key_file: ""
    domain: "api.ibkr.com"
    

    The private key file will usually have a .pem extension. The domain will normally be api.ibkr.com but it's also possible to access the API via other sub-domains like 1.api.ibkr.com.

  5. Run the test script.

    python auth.py
    

Installation

You can install from GitHub.

pip3 install git+https://github.com/datawookie/ibkr-oauth-flow

Deploying to PyPi

This requires UV_PUBLISH_TOKEN to be set to a PyPi token in environment.

make deploy

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

ibauth-0.0.6.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

ibauth-0.0.6-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ibauth-0.0.6.tar.gz
Algorithm Hash digest
SHA256 be2c13a37833d4387c0b55abcfad81e7a32b36979cec20aec471aa3dc2dfc242
MD5 160634443c51cfc15c5740f6cd9b0b06
BLAKE2b-256 47c468a6c2e35fe9c57cd1ddce24afad94df542545c0a8c99a44821360355ae2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ibauth-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6f795bb21b87029b19cd1599d34a7ed0789c88e07da4662e0059c2244890476d
MD5 a760cc3ee7053480e6fe084827f79cdb
BLAKE2b-256 2537a4fb35046192059a475f2b51761fb028410fb959d8da7accd306504caeb5

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