Metadata-Version: 2.4
Name: trading-static-ip
Version: 0.3.1
Summary: Monkey-patch Python broker SDK traffic through a ServLoci dedicated static IPv6.
Author: ServLoci
License-Expression: MIT
Project-URL: Homepage, https://comm.servloci.in
Project-URL: Docs, https://comm.servloci.in/docs
Project-URL: Package, https://pypi.org/project/trading-static-ip/
Keywords: servloci,trading,broker-api,socks5,proxy,ipv6,dhan,kite,zerodha,groww,fyers
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Internet :: Proxy Servers
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28
Requires-Dist: PySocks>=1.7.1
Requires-Dist: socksio>=1.0.0
Provides-Extra: socks
Requires-Dist: requests[socks]>=2.28; extra == "socks"
Requires-Dist: httpx[socks]>=0.24; extra == "socks"
Provides-Extra: httpx
Requires-Dist: httpx[socks]>=0.24; extra == "httpx"
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Dynamic: license-file

# trading-static-ip

Monkey-patch the HTTP traffic generated by official Python broker libraries so
it exits through your dedicated ServLoci IPv6.

## Install

```bash
pip install trading-static-ip
```

The PyPI distribution is named `trading-static-ip`; the Python import remains
`servloci` so existing code stays compatible.

## One-token broker SDK patch

Generate an access token in the ServLoci portal and verify the broker once.
Call `configure` before importing or constructing the broker SDK:

```python
from servloci import configure

configure(token="sl_live_...", broker="dhan")

# Import/create the official broker client after configure().
from dhanhq import dhanhq
dhan = dhanhq(client_id="YOUR_DHAN_CLIENT_ID", access_token="YOUR_DHAN_TOKEN")

# Existing SDK calls now use your ServLoci static IP without URL rewrites.
orders = dhan.get_order_list()
```

`configure` patches existing and future `requests.Session` objects, plus new
HTTPX `Client` and `AsyncClient` objects. It does not change global proxy
environment variables by default, so later `pip` commands and unrelated Colab
traffic stay direct. Your broker SDK keeps its normal URL, request body, and
authorization headers; ServLoci only provides the network route.

For another proxy-aware library that is not based on requests or HTTPX, opt in
to process and subprocess proxy variables with `configure(..., export_env=True)`.

Environment-variable setup is equally small:

```bash
export SERVLOCI_TOKEN='sl_live_...'
export SERVLOCI_BROKER='dhan'
```

```python
import os
from servloci import configure

configure(
    token=os.environ["SERVLOCI_TOKEN"],
    broker=os.environ["SERVLOCI_BROKER"],
)
```

The SOCKS route supports Dhan, Kite (Zerodha), Groww, FYERS, Upstox,
ICICI Direct, and Kotak Neo's approved dynamic production origins.

To restore the original HTTP transports and environment:

```python
from servloci import unconfigure
unconfigure()
```

## Explicit HTTP forwarder

For scripts that do not use a broker library, `Client` remains available. It
forwards supported order/trade paths through `/api/v1`:

```python
from servloci import Client

client = Client(token="sl_live_...", broker="dhan")
response = client.get(
    "/v2/orders",
    headers={"access-token": "YOUR_DHAN_ACCESS_TOKEN"},
)
response.raise_for_status()
```

## Legacy SOCKS credentials

The original helper remains backwards compatible:

```bash
pip install 'trading-static-ip[socks]'
```

```python
import servloci

servloci.configure(
    api_key="dhan:1000000001",
    api_secret="YOUR_SOCKS_PASSWORD",
)

# Import the broker SDK only after configure().
from dhanhq import dhanhq
```

The legacy `api_key` + `api_secret` call uses the same transport patches and
remains available for existing deployments.

## Security

- Treat `sl_live_...` as a password; never commit or log it.
- Access tokens are displayed once, stored server-side only as SHA-256 hashes,
  and can be rotated or revoked in the portal.
- The SOCKS server permits only the verified broker's approved HTTPS hosts.
- The explicit application forwarder remains restricted to documented
  order/trade paths.
