ibgateway-api-client


Nameibgateway-api-client JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/logycon/ibgateway-api-client
SummaryPython client library for Interactive Brokers Gateway running in Kubernetes (K3s) environments
upload_time2025-09-13 17:58:16
maintainerNone
docs_urlNone
authorLogycon
requires_python>=3.8
licenseMIT
keywords interactive-brokers trading api kubernetes k3s ib-gateway
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # IB Gateway API Client

A Python client library for connecting to Interactive Brokers Gateway running in Kubernetes (K3s) environments for both paper and live trading.

## Features

- 🚀 **Easy Integration**: Simple Python API for connecting to IB Gateway
- 🔄 **Async Support**: Built on `ib-insync` with full async/await support
- 🏗️ **K3s Ready**: Automatically detects K3s node IPs and service endpoints
- 📊 **Account Management**: Get account information, positions, and trading data
- 🔒 **Secure**: Random client ID generation to prevent connection conflicts
- 📦 **PyPI Ready**: Installable via pip from PyPI

## Installation

```bash
pip install ibgateway-api-client
```

## Quick Start

### Paper Trading

```python
import asyncio
from ibgateway_api_client import K3sPaperClient

async def main():
    client = K3sPaperClient(host="192.168.1.222", port=32002)
    
    if await client.connect():
        await client.get_account_info()
        await client.get_positions()
        await client.disconnect()

asyncio.run(main())
```

### Live Trading

```python
import asyncio
from ibgateway_api_client import K3sLiveClient

async def main():
    client = K3sLiveClient(host="192.168.1.222", port=32001)
    
    if await client.connect():
        await client.get_account_info()
        await client.get_positions()
        await client.disconnect()

asyncio.run(main())
```

### Auto-Detection (K3s)

```python
import asyncio
from ibgateway_api_client import K3sPaperClient, get_k3s_node_ip

async def main():
    # Automatically detect K3s node IP
    host = get_k3s_node_ip()
    client = K3sPaperClient(host=host, port=32002)
    
    if await client.connect():
        await client.get_account_info()
        await client.disconnect()

asyncio.run(main())
```

## Configuration

### Environment Variables

Create a `.env` file or set environment variables:

```bash
# Paper Trading
K3S_PAPER_HOST=192.168.1.222
K3S_PAPER_PORT=32002
K3S_PAPER_CLIENT_ID=1001

# Live Trading
K3S_LIVE_HOST=192.168.1.222
K3S_LIVE_PORT=32001
K3S_LIVE_CLIENT_ID=1002
```

### Configuration File

```python
# config.json
{
    "connection": {
        "host": "192.168.1.222",
        "port": 32002,
        "client_id": 1001,
        "timeout": 10
    }
}

# Usage
client = K3sPaperClient(config_file="config.json")
```

## API Reference

### K3sPaperClient

Paper trading client for K3s environments.

```python
client = K3sPaperClient(host=None, port=32002, client_id=None, config_file=None)
```

**Parameters:**
- `host` (str, optional): Gateway host IP. Defaults to auto-detection.
- `port` (int, optional): Gateway port. Defaults to 32002 for paper trading.
- `client_id` (int, optional): Client ID. Defaults to random (1000-9999).
- `config_file` (str, optional): Path to JSON configuration file.

**Methods:**
- `async connect()`: Connect to the gateway
- `async get_account_info()`: Get account summary information
- `async get_positions()`: Get current positions
- `async disconnect()`: Disconnect from the gateway

### K3sLiveClient

Live trading client for K3s environments.

```python
client = K3sLiveClient(host=None, port=32001, client_id=None, config_file=None)
```

**Parameters:**
- `host` (str, optional): Gateway host IP. Defaults to auto-detection.
- `port` (int, optional): Gateway port. Defaults to 32001 for live trading.
- `client_id` (int, optional): Client ID. Defaults to random (1000-9999).
- `config_file` (str, optional): Path to JSON configuration file.

**Methods:**
- `async connect()`: Connect to the gateway
- `async get_account_info()`: Get account summary information
- `async get_positions()`: Get current positions
- `async disconnect()`: Disconnect from the gateway

### Utility Functions

```python
from ibgateway_api_client import get_k3s_node_ip, test_connection

# Get K3s node IP automatically
host = get_k3s_node_ip()

# Test connection
success = await test_connection(host, 32002, "Paper Trading")
```

## Command Line Tools

The package includes command-line tools for testing connections:

```bash
# Test paper trading connection
ibgateway-test-paper

# Test live trading connection
ibgateway-test-live

# Test both connections
python -m ibgateway_api_client.test_connection
```

## Requirements

- Python 3.8+
- Interactive Brokers Gateway running in K3s
- `ib-insync` library
- `kubectl` configured for K3s cluster access

## Development

### Setup

```bash
git clone https://github.com/logycon/ibgateway-api-client
cd ibgateway-api-client
pip install -e ".[dev]"
```

### Testing

```bash
pytest
```

### Building

```bash
python -m build
```

### Publishing

```bash
python -m twine upload dist/*
```

## License

MIT License - see LICENSE file for details.

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request

## Support

- 📖 [Documentation](https://github.com/logycon/ibgateway-api-client#readme)
- 🐛 [Issue Tracker](https://github.com/logycon/ibgateway-api-client/issues)
- 💬 [Discussions](https://github.com/logycon/ibgateway-api-client/discussions)

## Disclaimer

This library is for educational and development purposes. Always test thoroughly in paper trading before using with live accounts. The authors are not responsible for any financial losses.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/logycon/ibgateway-api-client",
    "name": "ibgateway-api-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "interactive-brokers, trading, api, kubernetes, k3s, ib-gateway",
    "author": "Logycon",
    "author_email": "Logycon <dev@logycon.com>",
    "download_url": "https://files.pythonhosted.org/packages/f0/b8/870bd52fd7d04325a95f3a0c3b41f074570a24d4a603417f284db47f5fb8/ibgateway_api_client-0.1.1.tar.gz",
    "platform": null,
    "description": "# IB Gateway API Client\n\nA Python client library for connecting to Interactive Brokers Gateway running in Kubernetes (K3s) environments for both paper and live trading.\n\n## Features\n\n- \ud83d\ude80 **Easy Integration**: Simple Python API for connecting to IB Gateway\n- \ud83d\udd04 **Async Support**: Built on `ib-insync` with full async/await support\n- \ud83c\udfd7\ufe0f **K3s Ready**: Automatically detects K3s node IPs and service endpoints\n- \ud83d\udcca **Account Management**: Get account information, positions, and trading data\n- \ud83d\udd12 **Secure**: Random client ID generation to prevent connection conflicts\n- \ud83d\udce6 **PyPI Ready**: Installable via pip from PyPI\n\n## Installation\n\n```bash\npip install ibgateway-api-client\n```\n\n## Quick Start\n\n### Paper Trading\n\n```python\nimport asyncio\nfrom ibgateway_api_client import K3sPaperClient\n\nasync def main():\n    client = K3sPaperClient(host=\"192.168.1.222\", port=32002)\n    \n    if await client.connect():\n        await client.get_account_info()\n        await client.get_positions()\n        await client.disconnect()\n\nasyncio.run(main())\n```\n\n### Live Trading\n\n```python\nimport asyncio\nfrom ibgateway_api_client import K3sLiveClient\n\nasync def main():\n    client = K3sLiveClient(host=\"192.168.1.222\", port=32001)\n    \n    if await client.connect():\n        await client.get_account_info()\n        await client.get_positions()\n        await client.disconnect()\n\nasyncio.run(main())\n```\n\n### Auto-Detection (K3s)\n\n```python\nimport asyncio\nfrom ibgateway_api_client import K3sPaperClient, get_k3s_node_ip\n\nasync def main():\n    # Automatically detect K3s node IP\n    host = get_k3s_node_ip()\n    client = K3sPaperClient(host=host, port=32002)\n    \n    if await client.connect():\n        await client.get_account_info()\n        await client.disconnect()\n\nasyncio.run(main())\n```\n\n## Configuration\n\n### Environment Variables\n\nCreate a `.env` file or set environment variables:\n\n```bash\n# Paper Trading\nK3S_PAPER_HOST=192.168.1.222\nK3S_PAPER_PORT=32002\nK3S_PAPER_CLIENT_ID=1001\n\n# Live Trading\nK3S_LIVE_HOST=192.168.1.222\nK3S_LIVE_PORT=32001\nK3S_LIVE_CLIENT_ID=1002\n```\n\n### Configuration File\n\n```python\n# config.json\n{\n    \"connection\": {\n        \"host\": \"192.168.1.222\",\n        \"port\": 32002,\n        \"client_id\": 1001,\n        \"timeout\": 10\n    }\n}\n\n# Usage\nclient = K3sPaperClient(config_file=\"config.json\")\n```\n\n## API Reference\n\n### K3sPaperClient\n\nPaper trading client for K3s environments.\n\n```python\nclient = K3sPaperClient(host=None, port=32002, client_id=None, config_file=None)\n```\n\n**Parameters:**\n- `host` (str, optional): Gateway host IP. Defaults to auto-detection.\n- `port` (int, optional): Gateway port. Defaults to 32002 for paper trading.\n- `client_id` (int, optional): Client ID. Defaults to random (1000-9999).\n- `config_file` (str, optional): Path to JSON configuration file.\n\n**Methods:**\n- `async connect()`: Connect to the gateway\n- `async get_account_info()`: Get account summary information\n- `async get_positions()`: Get current positions\n- `async disconnect()`: Disconnect from the gateway\n\n### K3sLiveClient\n\nLive trading client for K3s environments.\n\n```python\nclient = K3sLiveClient(host=None, port=32001, client_id=None, config_file=None)\n```\n\n**Parameters:**\n- `host` (str, optional): Gateway host IP. Defaults to auto-detection.\n- `port` (int, optional): Gateway port. Defaults to 32001 for live trading.\n- `client_id` (int, optional): Client ID. Defaults to random (1000-9999).\n- `config_file` (str, optional): Path to JSON configuration file.\n\n**Methods:**\n- `async connect()`: Connect to the gateway\n- `async get_account_info()`: Get account summary information\n- `async get_positions()`: Get current positions\n- `async disconnect()`: Disconnect from the gateway\n\n### Utility Functions\n\n```python\nfrom ibgateway_api_client import get_k3s_node_ip, test_connection\n\n# Get K3s node IP automatically\nhost = get_k3s_node_ip()\n\n# Test connection\nsuccess = await test_connection(host, 32002, \"Paper Trading\")\n```\n\n## Command Line Tools\n\nThe package includes command-line tools for testing connections:\n\n```bash\n# Test paper trading connection\nibgateway-test-paper\n\n# Test live trading connection\nibgateway-test-live\n\n# Test both connections\npython -m ibgateway_api_client.test_connection\n```\n\n## Requirements\n\n- Python 3.8+\n- Interactive Brokers Gateway running in K3s\n- `ib-insync` library\n- `kubectl` configured for K3s cluster access\n\n## Development\n\n### Setup\n\n```bash\ngit clone https://github.com/logycon/ibgateway-api-client\ncd ibgateway-api-client\npip install -e \".[dev]\"\n```\n\n### Testing\n\n```bash\npytest\n```\n\n### Building\n\n```bash\npython -m build\n```\n\n### Publishing\n\n```bash\npython -m twine upload dist/*\n```\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests\n5. Submit a pull request\n\n## Support\n\n- \ud83d\udcd6 [Documentation](https://github.com/logycon/ibgateway-api-client#readme)\n- \ud83d\udc1b [Issue Tracker](https://github.com/logycon/ibgateway-api-client/issues)\n- \ud83d\udcac [Discussions](https://github.com/logycon/ibgateway-api-client/discussions)\n\n## Disclaimer\n\nThis library is for educational and development purposes. Always test thoroughly in paper trading before using with live accounts. The authors are not responsible for any financial losses.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python client library for Interactive Brokers Gateway running in Kubernetes (K3s) environments",
    "version": "0.1.1",
    "project_urls": {
        "Documentation": "https://github.com/logycon/ibgateway-api-client#readme",
        "Homepage": "https://github.com/logycon/ibgateway-api-client",
        "Issues": "https://github.com/logycon/ibgateway-api-client/issues",
        "Repository": "https://github.com/logycon/ibgateway-api-client"
    },
    "split_keywords": [
        "interactive-brokers",
        " trading",
        " api",
        " kubernetes",
        " k3s",
        " ib-gateway"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6c1d29196de4984c6fec5c2925c72037dd55ac3e7185bd600bf9bc1bbc7bebb9",
                "md5": "fceeadf1e73101465fa09fee01e6a027",
                "sha256": "62ec565ecb2758e23d7e8f91b8d39cbe55fef180b7474da0aa78f5043ca97916"
            },
            "downloads": -1,
            "filename": "ibgateway_api_client-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fceeadf1e73101465fa09fee01e6a027",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10341,
            "upload_time": "2025-09-13T17:58:15",
            "upload_time_iso_8601": "2025-09-13T17:58:15.244584Z",
            "url": "https://files.pythonhosted.org/packages/6c/1d/29196de4984c6fec5c2925c72037dd55ac3e7185bd600bf9bc1bbc7bebb9/ibgateway_api_client-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f0b8870bd52fd7d04325a95f3a0c3b41f074570a24d4a603417f284db47f5fb8",
                "md5": "7b06d34eae09757f94715c614eaf647e",
                "sha256": "577aab55c92232f723d9fb797c202d0c413f4e1b95dbb886a71d15fb33df457a"
            },
            "downloads": -1,
            "filename": "ibgateway_api_client-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7b06d34eae09757f94715c614eaf647e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10496,
            "upload_time": "2025-09-13T17:58:16",
            "upload_time_iso_8601": "2025-09-13T17:58:16.455697Z",
            "url": "https://files.pythonhosted.org/packages/f0/b8/870bd52fd7d04325a95f3a0c3b41f074570a24d4a603417f284db47f5fb8/ibgateway_api_client-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-13 17:58:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "logycon",
    "github_project": "ibgateway-api-client",
    "github_not_found": true,
    "lcname": "ibgateway-api-client"
}
        
Elapsed time: 1.13622s