openalgo


Nameopenalgo JSON
Version 1.0.8 PyPI version JSON
download
home_pagehttps://docs.openalgo.in
SummaryPython library for algorithmic trading with OpenAlgo - Accounts, Orders, Strategy Management and Market Data APIs
upload_time2025-01-10 16:43:05
maintainerNone
docs_urlNone
authorOpenAlgo
requires_python>=3.7
licenseNone
keywords trading algorithmic-trading finance stock-market api-wrapper openalgo market-data trading-api stock-trading
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # OpenAlgo Python Library

A Python library for algorithmic trading using OpenAlgo's REST APIs. This library provides a comprehensive interface for order management, market data, account operations, and strategy automation.

## Installation

```bash
pip install openalgo
```

## Quick Start

```python
from openalgo import api

# Initialize the client
client = api(
    api_key="your_api_key",
    host="http://127.0.0.1:5000"  # or your OpenAlgo server URL
)
```

## API Categories

### 1. Strategy API

#### Strategy Management Module
OpenAlgo's Strategy Management Module allows you to automate your trading strategies using webhooks. This enables seamless integration with any platform or custom system that can send HTTP requests. The Strategy class provides a simple interface to send signals that trigger orders based on your strategy configuration in OpenAlgo.

```python
from openalgo import Strategy
import requests

# Initialize strategy client
client = Strategy(
    host_url="http://127.0.0.1:5000",  # Your OpenAlgo server URL
    webhook_id="your-webhook-id"        # Get this from OpenAlgo strategy section
)

try:
    # Long entry (BOTH mode with position size)
    response = client.strategyorder("RELIANCE", "BUY", 1)
    print(f"Long entry successful: {response}")

    # Short entry
    response = client.strategyorder("ZOMATO", "SELL", 1)
    print(f"Short entry successful: {response}")

    # Close positions
    response = client.strategyorder("RELIANCE", "SELL", 0)  # Close long
    response = client.strategyorder("ZOMATO", "BUY", 0)     # Close short

except requests.exceptions.RequestException as e:
    print(f"Error sending order: {e}")
```

Strategy Modes:
- **LONG_ONLY**: Only processes BUY signals for long-only strategies
- **SHORT_ONLY**: Only processes SELL signals for short-only strategies
- **BOTH**: Processes both BUY and SELL signals with position sizing

The Strategy Management Module can be integrated with:
- Custom trading systems
- Technical analysis platforms
- Alert systems
- Automated trading bots
- Any system capable of making HTTP requests

### 2. Accounts API

#### Funds
Get funds and margin details of the trading account.
```python
result = client.funds()
# Returns:
{
    "data": {
        "availablecash": "18083.01",
        "collateral": "0.00",
        "m2mrealized": "0.00",
        "m2munrealized": "0.00",
        "utiliseddebits": "0.00"
    },
    "status": "success"
}
```

#### Orderbook
Get orderbook details with statistics.
```python
result = client.orderbook()
# Returns order details and statistics including:
# - Total buy/sell orders
# - Total completed/open/rejected orders
# - Individual order details with status
```

#### Tradebook
Get execution details of trades.
```python
result = client.tradebook()
# Returns list of executed trades with:
# - Symbol, action, quantity
# - Average price, trade value
# - Timestamp, order ID
```

#### Positionbook
Get current positions across all segments.
```python
result = client.positionbook()
# Returns list of positions with:
# - Symbol, exchange, product
# - Quantity, average price
```

#### Holdings
Get stock holdings with P&L details.
```python
result = client.holdings()
# Returns:
# - List of holdings with quantity and P&L
# - Statistics including total holding value
# - Total investment value and P&L
```

### 3. Orders API

#### Place Order
Place a regular order.
```python
result = client.placeorder(
    symbol="RELIANCE",
    exchange="NSE",
    action="BUY",
    quantity=1,
    price_type="MARKET",
    product="MIS"
)
```

#### Place Smart Order
Place an order with position sizing.
```python
result = client.placesmartorder(
    symbol="RELIANCE",
    exchange="NSE",
    action="BUY",
    quantity=1,
    position_size=100,
    price_type="MARKET",
    product="MIS"
)
```

#### Basket Order
Place multiple orders simultaneously.
```python
orders = [
    {
        "symbol": "RELIANCE",
        "exchange": "NSE",
        "action": "BUY",
        "quantity": 1,
        "pricetype": "MARKET",
        "product": "MIS"
    },
    {
        "symbol": "INFY",
        "exchange": "NSE",
        "action": "SELL",
        "quantity": 1,
        "pricetype": "MARKET",
        "product": "MIS"
    }
]
result = client.basketorder(orders=orders)
```

#### Split Order
Split a large order into smaller ones.
```python
result = client.splitorder(
    symbol="YESBANK",
    exchange="NSE",
    action="SELL",
    quantity=105,
    splitsize=20,
    price_type="MARKET",
    product="MIS"
)
```

#### Order Status
Check status of a specific order.
```python
result = client.orderstatus(
    order_id="24120900146469",
    strategy="Test Strategy"
)
```

#### Open Position
Get current open position for a symbol.
```python
result = client.openposition(
    symbol="YESBANK",
    exchange="NSE",
    product="CNC"
)
```

#### Modify Order
Modify an existing order.
```python
result = client.modifyorder(
    order_id="24120900146469",
    symbol="RELIANCE",
    action="BUY",
    exchange="NSE",
    quantity=2,
    price="2100",
    product="MIS",
    price_type="LIMIT"
)
```

#### Cancel Order
Cancel a specific order.
```python
result = client.cancelorder(
    order_id="24120900146469"
)
```

#### Cancel All Orders
Cancel all open orders.
```python
result = client.cancelallorder()
```

#### Close Position
Close all open positions.
```python
result = client.closeposition()
```

### 4. Data API

#### Quotes
Get real-time quotes for a symbol.
```python
result = client.quotes(
    symbol="RELIANCE",
    exchange="NSE"
)
```

#### Market Depth
Get market depth (order book) data.
```python
result = client.depth(
    symbol="RELIANCE",
    exchange="NSE"
)
```

#### Historical Data
Get historical price data.
```python
result = client.history(
    symbol="RELIANCE",
    exchange="NSE",
    interval="5m",
    start_date="2024-01-01",
    end_date="2024-01-31"
)
```

#### Intervals
Get supported time intervals for historical data.
```python
result = client.interval()
```

## Examples

Check the examples directory for detailed usage:
- account_test.py: Test account-related functions
- order_test.py: Test order management functions
- data_examples.py: Test market data functions

## Publishing to PyPI

1. Update version in `openalgo/__init__.py`

2. Build the distribution:
```bash
python -m pip install --upgrade build
python -m build
```

3. Upload to PyPI:
```bash
python -m pip install --upgrade twine
python -m twine upload dist/*
```

## License

This project is licensed under the MIT License - see the LICENSE file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://docs.openalgo.in",
    "name": "openalgo",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "trading, algorithmic-trading, finance, stock-market, api-wrapper, openalgo, market-data, trading-api, stock-trading",
    "author": "OpenAlgo",
    "author_email": "support@openalgo.in",
    "download_url": "https://files.pythonhosted.org/packages/1b/28/2485f3eab72911b0ddecd200548653e8eaf863c61b756764ea0095ab5ae4/openalgo-1.0.8.tar.gz",
    "platform": null,
    "description": "# OpenAlgo Python Library\n\nA Python library for algorithmic trading using OpenAlgo's REST APIs. This library provides a comprehensive interface for order management, market data, account operations, and strategy automation.\n\n## Installation\n\n```bash\npip install openalgo\n```\n\n## Quick Start\n\n```python\nfrom openalgo import api\n\n# Initialize the client\nclient = api(\n    api_key=\"your_api_key\",\n    host=\"http://127.0.0.1:5000\"  # or your OpenAlgo server URL\n)\n```\n\n## API Categories\n\n### 1. Strategy API\n\n#### Strategy Management Module\nOpenAlgo's Strategy Management Module allows you to automate your trading strategies using webhooks. This enables seamless integration with any platform or custom system that can send HTTP requests. The Strategy class provides a simple interface to send signals that trigger orders based on your strategy configuration in OpenAlgo.\n\n```python\nfrom openalgo import Strategy\nimport requests\n\n# Initialize strategy client\nclient = Strategy(\n    host_url=\"http://127.0.0.1:5000\",  # Your OpenAlgo server URL\n    webhook_id=\"your-webhook-id\"        # Get this from OpenAlgo strategy section\n)\n\ntry:\n    # Long entry (BOTH mode with position size)\n    response = client.strategyorder(\"RELIANCE\", \"BUY\", 1)\n    print(f\"Long entry successful: {response}\")\n\n    # Short entry\n    response = client.strategyorder(\"ZOMATO\", \"SELL\", 1)\n    print(f\"Short entry successful: {response}\")\n\n    # Close positions\n    response = client.strategyorder(\"RELIANCE\", \"SELL\", 0)  # Close long\n    response = client.strategyorder(\"ZOMATO\", \"BUY\", 0)     # Close short\n\nexcept requests.exceptions.RequestException as e:\n    print(f\"Error sending order: {e}\")\n```\n\nStrategy Modes:\n- **LONG_ONLY**: Only processes BUY signals for long-only strategies\n- **SHORT_ONLY**: Only processes SELL signals for short-only strategies\n- **BOTH**: Processes both BUY and SELL signals with position sizing\n\nThe Strategy Management Module can be integrated with:\n- Custom trading systems\n- Technical analysis platforms\n- Alert systems\n- Automated trading bots\n- Any system capable of making HTTP requests\n\n### 2. Accounts API\n\n#### Funds\nGet funds and margin details of the trading account.\n```python\nresult = client.funds()\n# Returns:\n{\n    \"data\": {\n        \"availablecash\": \"18083.01\",\n        \"collateral\": \"0.00\",\n        \"m2mrealized\": \"0.00\",\n        \"m2munrealized\": \"0.00\",\n        \"utiliseddebits\": \"0.00\"\n    },\n    \"status\": \"success\"\n}\n```\n\n#### Orderbook\nGet orderbook details with statistics.\n```python\nresult = client.orderbook()\n# Returns order details and statistics including:\n# - Total buy/sell orders\n# - Total completed/open/rejected orders\n# - Individual order details with status\n```\n\n#### Tradebook\nGet execution details of trades.\n```python\nresult = client.tradebook()\n# Returns list of executed trades with:\n# - Symbol, action, quantity\n# - Average price, trade value\n# - Timestamp, order ID\n```\n\n#### Positionbook\nGet current positions across all segments.\n```python\nresult = client.positionbook()\n# Returns list of positions with:\n# - Symbol, exchange, product\n# - Quantity, average price\n```\n\n#### Holdings\nGet stock holdings with P&L details.\n```python\nresult = client.holdings()\n# Returns:\n# - List of holdings with quantity and P&L\n# - Statistics including total holding value\n# - Total investment value and P&L\n```\n\n### 3. Orders API\n\n#### Place Order\nPlace a regular order.\n```python\nresult = client.placeorder(\n    symbol=\"RELIANCE\",\n    exchange=\"NSE\",\n    action=\"BUY\",\n    quantity=1,\n    price_type=\"MARKET\",\n    product=\"MIS\"\n)\n```\n\n#### Place Smart Order\nPlace an order with position sizing.\n```python\nresult = client.placesmartorder(\n    symbol=\"RELIANCE\",\n    exchange=\"NSE\",\n    action=\"BUY\",\n    quantity=1,\n    position_size=100,\n    price_type=\"MARKET\",\n    product=\"MIS\"\n)\n```\n\n#### Basket Order\nPlace multiple orders simultaneously.\n```python\norders = [\n    {\n        \"symbol\": \"RELIANCE\",\n        \"exchange\": \"NSE\",\n        \"action\": \"BUY\",\n        \"quantity\": 1,\n        \"pricetype\": \"MARKET\",\n        \"product\": \"MIS\"\n    },\n    {\n        \"symbol\": \"INFY\",\n        \"exchange\": \"NSE\",\n        \"action\": \"SELL\",\n        \"quantity\": 1,\n        \"pricetype\": \"MARKET\",\n        \"product\": \"MIS\"\n    }\n]\nresult = client.basketorder(orders=orders)\n```\n\n#### Split Order\nSplit a large order into smaller ones.\n```python\nresult = client.splitorder(\n    symbol=\"YESBANK\",\n    exchange=\"NSE\",\n    action=\"SELL\",\n    quantity=105,\n    splitsize=20,\n    price_type=\"MARKET\",\n    product=\"MIS\"\n)\n```\n\n#### Order Status\nCheck status of a specific order.\n```python\nresult = client.orderstatus(\n    order_id=\"24120900146469\",\n    strategy=\"Test Strategy\"\n)\n```\n\n#### Open Position\nGet current open position for a symbol.\n```python\nresult = client.openposition(\n    symbol=\"YESBANK\",\n    exchange=\"NSE\",\n    product=\"CNC\"\n)\n```\n\n#### Modify Order\nModify an existing order.\n```python\nresult = client.modifyorder(\n    order_id=\"24120900146469\",\n    symbol=\"RELIANCE\",\n    action=\"BUY\",\n    exchange=\"NSE\",\n    quantity=2,\n    price=\"2100\",\n    product=\"MIS\",\n    price_type=\"LIMIT\"\n)\n```\n\n#### Cancel Order\nCancel a specific order.\n```python\nresult = client.cancelorder(\n    order_id=\"24120900146469\"\n)\n```\n\n#### Cancel All Orders\nCancel all open orders.\n```python\nresult = client.cancelallorder()\n```\n\n#### Close Position\nClose all open positions.\n```python\nresult = client.closeposition()\n```\n\n### 4. Data API\n\n#### Quotes\nGet real-time quotes for a symbol.\n```python\nresult = client.quotes(\n    symbol=\"RELIANCE\",\n    exchange=\"NSE\"\n)\n```\n\n#### Market Depth\nGet market depth (order book) data.\n```python\nresult = client.depth(\n    symbol=\"RELIANCE\",\n    exchange=\"NSE\"\n)\n```\n\n#### Historical Data\nGet historical price data.\n```python\nresult = client.history(\n    symbol=\"RELIANCE\",\n    exchange=\"NSE\",\n    interval=\"5m\",\n    start_date=\"2024-01-01\",\n    end_date=\"2024-01-31\"\n)\n```\n\n#### Intervals\nGet supported time intervals for historical data.\n```python\nresult = client.interval()\n```\n\n## Examples\n\nCheck the examples directory for detailed usage:\n- account_test.py: Test account-related functions\n- order_test.py: Test order management functions\n- data_examples.py: Test market data functions\n\n## Publishing to PyPI\n\n1. Update version in `openalgo/__init__.py`\n\n2. Build the distribution:\n```bash\npython -m pip install --upgrade build\npython -m build\n```\n\n3. Upload to PyPI:\n```bash\npython -m pip install --upgrade twine\npython -m twine upload dist/*\n```\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python library for algorithmic trading with OpenAlgo - Accounts, Orders, Strategy Management and Market Data APIs",
    "version": "1.0.8",
    "project_urls": {
        "Documentation": "https://docs.openalgo.in",
        "Homepage": "https://docs.openalgo.in",
        "Source": "https://github.com/openalgo/openalgo-python",
        "Tracker": "https://github.com/openalgo/openalgo-python/issues"
    },
    "split_keywords": [
        "trading",
        " algorithmic-trading",
        " finance",
        " stock-market",
        " api-wrapper",
        " openalgo",
        " market-data",
        " trading-api",
        " stock-trading"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e04361dca6834cd8a72ac69a8f7bb9ebf0af2665c6cd52b3d7fc8f6ba9904596",
                "md5": "8146336496c3765aef50848091bf1b03",
                "sha256": "dcd1eda53fd297d4fd7af6b4604b606c6245d2c0f6666462dd7a8a5805195bdc"
            },
            "downloads": -1,
            "filename": "openalgo-1.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8146336496c3765aef50848091bf1b03",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 12123,
            "upload_time": "2025-01-10T16:43:01",
            "upload_time_iso_8601": "2025-01-10T16:43:01.912646Z",
            "url": "https://files.pythonhosted.org/packages/e0/43/61dca6834cd8a72ac69a8f7bb9ebf0af2665c6cd52b3d7fc8f6ba9904596/openalgo-1.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1b282485f3eab72911b0ddecd200548653e8eaf863c61b756764ea0095ab5ae4",
                "md5": "b57004cdb9d44c3686aabdd6737464e5",
                "sha256": "addd20570b341a75208afcdd1942ef852c8e991097dac01478ebb28e1a0046ff"
            },
            "downloads": -1,
            "filename": "openalgo-1.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "b57004cdb9d44c3686aabdd6737464e5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 12195,
            "upload_time": "2025-01-10T16:43:05",
            "upload_time_iso_8601": "2025-01-10T16:43:05.765220Z",
            "url": "https://files.pythonhosted.org/packages/1b/28/2485f3eab72911b0ddecd200548653e8eaf863c61b756764ea0095ab5ae4/openalgo-1.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-10 16:43:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "openalgo",
    "github_project": "openalgo-python",
    "github_not_found": true,
    "lcname": "openalgo"
}
        
Elapsed time: 0.44255s