---
name: zero-ip
description: Set up and use Snipy Zero IP, the dedicated static IPv6 egress for Indian broker order APIs (Zerodha Kite, Upstox, Dhan, Fyers, Groww, Kotak Neo and others). Use when a trading bot must place, modify or cancel orders from a whitelisted static IP, when configuring an HTTPS proxy with a zero_ip_ key, or when debugging 403/407/429 responses from zeroip.snipy.in. Zero IP is for order traffic only; never route market data, LLM, or general API calls through it.
---

# Zero IP

Zero IP gives a Snipy account one or two dedicated IPv6 addresses. A bot tunnels
its broker **order** calls through `zeroip.snipy.in:8443`, and the broker sees
them coming from that fixed address, which the user whitelists once with the
broker (SEBI retail algo framework static-IP requirement).

## Hard rules

1. **Orders only.** Send through Zero IP only the broker calls that must come
   from the whitelisted IP: place, modify, cancel order (and GTT/basket order
   endpoints), plus login/session-token calls if the broker ties them to the
   static IP. Everything else goes direct: quotes, LTP, market depth,
   historical candles, instruments dumps, option chains, public websockets/streaming,
   portfolio reads that do not need the static IP, LLM/AI APIs, webhooks,
   telemetry, package downloads.
2. **Never set Zero IP as a global proxy.** Do not export `HTTPS_PROXY` /
   `ALL_PROXY` for the whole process, do not configure it system-wide, and do
   not wrap a shared HTTP client. Build one dedicated order client and keep a
   separate direct client for everything else.
3. **Only allowlisted broker hosts on port 443.** Any other host, raw IP, or
   port is rejected with `403`. Do not try to reach other services, other
   brokers' data hosts, or tunnel non-TLS traffic; the proxy checks that the
   inner TLS SNI matches the CONNECT host and closes the tunnel otherwise.
4. **Respect the per-IP caps** (see Limits). Reuse one keep-alive connection
   for orders instead of opening a tunnel per request.
5. **Treat the key as a secret.** `zero_ip_...` keys go in env vars or a secret
   store, never in source, logs, commits, or prompts. The key must be sent to
   the **proxy** (CONNECT request), never as a header on the broker request.

## Setup checklist

1. Sign in at https://snipy.in/zero-ip#get-started and click **Request IP**.
   Copy the IPv6 address and the `zero_ip_...` proxy API key.
2. Whitelist that IPv6 address in the broker's API app settings (Kite
   developer console, Upstox app, Dhan, Fyers, etc.). The broker must accept
   IPv6; Zero IP egress is IPv6 only.
3. Store credentials:
   ```bash
   ZERO_IP_PROXY_URL=https://zeroip.snipy.in:8443
   ZERO_IP_API_KEY=zero_ip_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   ZERO_IP_IPV6=2406:xxxx:xxxx::xxxx   # optional; defaults to the first active IP
   ```
4. Verify with curl (should return the broker's normal response, not a proxy error):
   ```bash
   curl --proxy "$ZERO_IP_PROXY_URL" \
     --proxy-header "Proxy-Authorization: Bearer $ZERO_IP_API_KEY" \
     --proxy-header "X-Snipy-Proxy-IPv6: $ZERO_IP_IPV6" \
     https://api.kite.trade/
   ```

## Protocol

- Proxy: `https://zeroip.snipy.in:8443`. The connection **to the proxy** is
  TLS (an HTTPS proxy, not plain HTTP). Use a client that supports HTTPS proxies.
- Method: HTTP `CONNECT broker-host:443`. The broker TLS session runs end to
  end inside the tunnel; Zero IP never decrypts it.
- CONNECT headers (proxy headers, not request headers):
  - `Proxy-Authorization: Bearer <ZERO_IP_API_KEY>`, required
  - `X-Snipy-Proxy-IPv6: <one of your active IPs>`, optional
- Allowlisted hosts include `api.kite.trade`, `api.upstox.com`,
  `api-hft.upstox.com`, `api.dhan.co`, `api-t1.fyers.in`, `api.groww.in`,
  `openapi.5paisa.com`, `a3.aliceblueonline.com`, `piconnect.flattrade.in`,
  `authapi.flattrade.in`, `api.icicidirect.com`, `api.iiflcapital.com`,
  `mis.kotaksecurities.com`, `cis.kotaksecurities.com`, `e21/e22/e41/e43.kotaksecurities.com`,
  `trade.shoonya.com`, `api.nubra.io`, `vortex-api.rupeezy.in`,
  `api.india.delta.exchange`, `socket.india.delta.exchange`.
  The current list is on https://snipy.in/zero-ip.

## Client recipes

Pattern in every language: one **order client** with the proxy configured,
one **data client** without it.

### Python (requests)

`requests` sends `headers=` to the broker, not the proxy. Put the proxy headers
on the adapter so they go on the CONNECT:

```python
import os
import requests
from requests.adapters import HTTPAdapter

class ZeroIpAdapter(HTTPAdapter):
    def proxy_headers(self, proxy):
        headers = super().proxy_headers(proxy)
        headers["Proxy-Authorization"] = f"Bearer {os.environ['ZERO_IP_API_KEY']}"
        if os.environ.get("ZERO_IP_IPV6"):
            headers["X-Snipy-Proxy-IPv6"] = os.environ["ZERO_IP_IPV6"]
        return headers

def order_session() -> requests.Session:
    s = requests.Session()
    s.trust_env = False  # ignore any global HTTPS_PROXY
    s.proxies = {"https": os.environ.get("ZERO_IP_PROXY_URL", "https://zeroip.snipy.in:8443")}
    s.mount("https://", ZeroIpAdapter())
    return s

orders = order_session()          # place / modify / cancel only
data = requests.Session()         # quotes, candles, instruments: direct

orders.post(
    "https://api.kite.trade/orders/regular",
    headers={"X-Kite-Version": "3", "Authorization": f"token {api_key}:{access_token}"},
    data={"exchange": "NSE", "tradingsymbol": "INFY", "transaction_type": "BUY",
          "quantity": 1, "order_type": "MARKET", "product": "CNC", "validity": "DAY"},
    timeout=10,
)
```

Requires `urllib3>=2` for HTTPS proxies. Broker SDKs (kiteconnect, upstox,
dhanhq, fyers) usually accept a `requests.Session` or a `proxies` argument.
Pass the order session only to the order-placing instance; if the SDK cannot
take a session, wrap only its order methods with the order session.

### Delta Exchange India

- Only Delta Exchange **India** production works: REST `https://api.india.delta.exchange`,
  private websocket `wss://socket.india.delta.exchange`. Global (`api.delta.exchange`)
  and testnet hosts are not allowlisted.
- Create the API key with Trading permission and whitelist the Zero IP IPv6
  address on it. Delta accepts IPv6 and only allows Indian IPs, which Zero IP is.
- Always send a `User-Agent` header. Delta's CDN returns an HTML `403` without one.
- Signatures are `HMAC_SHA256(secret, method + timestamp + path + query + body)`;
  the timestamp must be within 5 seconds of Delta's clock, so keep NTP in sync
  and sign right before sending.
- `delta-rest-client` (Python) exposes `client.session`; configure that session
  as the order session above:
  ```python
  from delta_rest_client import DeltaRestClient
  delta = DeltaRestClient(base_url="https://api.india.delta.exchange",
                          api_key=DELTA_KEY, api_secret=DELTA_SECRET)
  delta.session.trust_env = False
  delta.session.proxies = {"https": os.environ.get("ZERO_IP_PROXY_URL", "https://zeroip.snipy.in:8443")}
  delta.session.mount("https://", ZeroIpAdapter())
  delta.place_order(product_id=27, size=1, side="buy", limit_price="60000", order_type="limit_order")
  ```
  Use a separate client without the proxy for public market data.
- The private websocket checks the whitelisted IP on `key-auth`, so it may go
  through Zero IP. Keep one long-lived connection, subscribe only to private
  channels (orders, positions, fills), and take public feeds from
  `wss://public-socket.india.delta.exchange` directly. Delta allows 150 new
  websocket connections per IP per 5 minutes.

### Node.js (undici)

```ts
import { ProxyAgent, fetch } from "undici";

const orderDispatcher = new ProxyAgent({
  uri: process.env.ZERO_IP_PROXY_URL ?? "https://zeroip.snipy.in:8443",
  token: `Bearer ${process.env.ZERO_IP_API_KEY}`,          // sent on CONNECT
  headers: process.env.ZERO_IP_IPV6
    ? { "X-Snipy-Proxy-IPv6": process.env.ZERO_IP_IPV6 }   // sent on CONNECT
    : undefined,
});

// Orders: proxied.
await fetch("https://api.kite.trade/orders/regular", {
  method: "POST",
  dispatcher: orderDispatcher,
  headers: { "X-Kite-Version": "3", Authorization: `token ${apiKey}:${accessToken}` },
  body: new URLSearchParams({ exchange: "NSE", tradingsymbol: "INFY", transaction_type: "BUY",
    quantity: "1", order_type: "MARKET", product: "CNC", validity: "DAY" }),
});

// Market data: plain fetch, no dispatcher.
await fetch("https://api.kite.trade/quote?i=NSE:INFY", { headers: { /* ... */ } });
```

Do not use `setGlobalDispatcher(orderDispatcher)`.

### Go

```go
proxyURL, _ := url.Parse("https://zeroip.snipy.in:8443")
connectHeaders := http.Header{"Proxy-Authorization": {"Bearer " + os.Getenv("ZERO_IP_API_KEY")}}
if ip := os.Getenv("ZERO_IP_IPV6"); ip != "" {
    connectHeaders.Set("X-Snipy-Proxy-IPv6", ip)
}
orderClient := &http.Client{
    Timeout: 10 * time.Second,
    Transport: &http.Transport{
        Proxy:              http.ProxyURL(proxyURL),
        ProxyConnectHeader: connectHeaders, // headers for CONNECT, not the broker
        MaxIdleConnsPerHost: 2,
        IdleConnTimeout:    90 * time.Second,
    },
}
dataClient := &http.Client{Timeout: 10 * time.Second} // direct
```

### Rust (reqwest)

```rust
use reqwest::{header::HeaderValue, Proxy};

let key = std::env::var("ZERO_IP_API_KEY")?;
let proxy = Proxy::https("https://zeroip.snipy.in:8443")?
    .custom_http_auth(HeaderValue::from_str(&format!("Bearer {key}"))?);
let orders = reqwest::Client::builder().proxy(proxy).build()?; // orders only
let data = reqwest::Client::builder().no_proxy().build()?;    // everything else
```

`custom_http_auth` sets `Proxy-Authorization` on the CONNECT. The default
egress IP (first active) is used unless your client can add
`X-Snipy-Proxy-IPv6` to the CONNECT.

Java's built-in `HttpClient` cannot send a Bearer `Proxy-Authorization` on
CONNECT. Use a sidecar in Go/Python/Node for order calls, or a client that
exposes CONNECT headers.

## Limits (per egress IPv6)

| Limit | Default |
| --- | --- |
| New tunnels | 60 per minute |
| Open tunnels at once | 8 |
| Requests (TLS records from client) | 10/s sustained, burst 20 |
| Requests per UTC day | 20,000 |
| Failed auth per client IP | 20 per 10 min, then locked out |

Over the sustained rate, requests are delayed up to 2 s, then the tunnel is
closed. New tunnels over a cap get `429` with `Retry-After`. Order bots stay
well under these numbers. Hitting them means market data or polling is going
through Zero IP; move it to the direct client.

## Errors

| Response | Meaning | Fix |
| --- | --- | --- |
| `407 Missing/Invalid proxy API key` | Key absent, wrong, or sent to the broker instead of the proxy | Put `Proxy-Authorization: Bearer zero_ip_...` on CONNECT; rotate if leaked |
| `403 Zero IP only reaches allowlisted broker order APIs` | Host not allowlisted | Call it directly, not through Zero IP |
| `403 Only port 443 is allowed` / `Raw IP targets are not allowed` | Non-HTTPS port or IP literal | Use the broker hostname on 443 |
| `403 Requested proxy IPv6 does not belong to this API key` | Wrong `X-Snipy-Proxy-IPv6` | Use an active IP from the dashboard, or omit the header |
| `429` + `Retry-After` | Per-IP cap hit | Reuse connections, slow down, move non-order calls off Zero IP |
| Tunnel closes right after `200` | Inner traffic was not TLS, or SNI did not match the CONNECT host | Use `https://` URLs for the same host you CONNECT to |
| `502 No usable IPv6 address` | Broker host has no AAAA record | That host cannot be used over Zero IP |
| Broker rejects with IP error | IPv6 not whitelisted at broker | Whitelist the exact IPv6 shown in the dashboard |

## Agent checklist before finishing

- [ ] Only order place/modify/cancel (and required auth) calls use the proxied client
- [ ] No global proxy env vars or global dispatcher
- [ ] Key and IPv6 read from env/secret store, not hardcoded
- [ ] Proxy credentials sent as CONNECT headers, not broker request headers
- [ ] Order client reuses connections (keep-alive) and has timeouts
- [ ] 429 handled with `Retry-After` backoff; no tight retry loops on orders
