--- name: quantgrid-static-ip description: "Wires a trader's own code to QuantGrid Static IP, an authenticated HTTPS proxy at proxy.quantgrid.in:3128 that sends broker API calls from the trader's own static IP, which Indian brokers require for API orders. Use when routing broker order, account or sign-in calls through a registered static IP, when setting QUANTGRID_PROXY_URL, or when the proxy refuses a connection (400, 403, 405, 407, 429, 502, 503). Only those broker calls go through it: market data, quotes, candles, websockets and instrument files stay direct." --- # QuantGrid Static IP QuantGrid Static IP gives a trader a static IP address, IPv6 or IPv4, and a proxy at proxy.quantgrid.in:3128. The trader's code sends its broker API calls through the proxy, and the broker sees them come from that address, which the trader registers with the broker. The connection to the broker stays encrypted end to end: the proxy cannot read orders, keys or sessions. Your job is to wire the trader's existing code to the proxy and nothing more. Change only how its broker calls connect. Never write, change or comment on what the code trades, when, or how much, and never add or suggest trading logic. QuantGrid Static IP supplies a static IP address and a proxy for your own broker API connection. QuantGrid is not registered with SEBI, places no orders, does not provide investment advice, and does not guarantee any return. Following your broker's and the exchange's rules for your address is your responsibility. ## Hard rules 1. **Only broker order, account and sign-in calls go through the proxy**: placing, modifying and cancelling orders, the order book and trades, positions, holdings, funds and margins, and the login and session calls. Send them through one dedicated client or session that uses the proxy. 2. **Everything else connects directly**, through a second client with no proxy: market data, quotes, LTP, depth, candles and historical data; websockets and live streams (market feeds, and order-update streams, which the proxy does not carry unless they are on its list for the broker); instrument and scrip-master file downloads, even from the same host as orders (one trader downloaded a 35 to 40 MB instrument file through the proxy several times a day and ran into the daily fair use); and anything that is not the broker (AI model APIs, databases, telemetry, package downloads). 3. **Reuse one client or session for every broker call.** Never open a new client or connection per call: each costs a new connection and handshake before the order goes, and counts against 120 new connections a minute. 4. **Never set a global proxy** (HTTPS_PROXY, ALL_PROXY, a global agent or dispatcher, system proxy settings) unless the program talks to nothing but the broker's order, account and sign-in hosts. 5. **The username and password are secrets.** Read them from the environment variable QUANTGRID_PROXY_URL (or the trader's secret store). Never write them into source, a committed file, a log line or an error message, never print the proxy URL unmasked, and never ask the trader to paste the password into the chat: ask them to set the variable themselves. ## Setup checklist 1. **An address.** The trader buys a static IP, or starts the free trial (one address for 7 days, no card), in the QuantGrid dashboard: sign up at https://app.quantgrid.in/register?product=static-ip or sign in at https://app.quantgrid.in/login?product=static-ip. Prices: https://quantgrid.in/static-ip#pricing. You cannot do this for them. 2. **Register the address with the broker.** Add the address your dashboard shows in your broker's API or developer console. Your broker's own rules apply there: some allow one change a week, and some ask you to sign in again after adding an address. Register the static IP the dashboard shows, never the proxy's host name. 3. **Set the variable** (the dashboard shows the host, port, username and password): ```bash # macOS and Linux export QUANTGRID_PROXY_URL="https://USERNAME:PASSWORD@proxy.quantgrid.in:3128" # Windows PowerShell $env:QUANTGRID_PROXY_URL = "https://USERNAME:PASSWORD@proxy.quantgrid.in:3128" ``` 4. **Verify.** Through the proxy, ip.quantgrid.in prints the address the broker sees, which must be the static IP the dashboard shows: ```bash curl --proxy "$QUANTGRID_PROXY_URL" https://ip.quantgrid.in ``` Other IP-check sites (api.ipify.org, ifconfig.me and the like) are refused with 403 Destination Not Allowed by design: only ip.quantgrid.in answers through the proxy. ## Protocol - Host proxy.quantgrid.in, port 3128. Never port 8443: it belongs to QuantGrid AlgoTrader, and failed sign-ins there block the source for 10 minutes. - `https://` (TLS to the proxy) or `http://` on the same port. Prefer `https://`, which keeps the login encrypted. A client that cannot speak TLS to a proxy, such as Java's HttpClient, uses `http://`: the broker traffic stays encrypted end to end either way. - Basic login (`Proxy-Authorization: Basic`) on the CONNECT. A client that sends it only when asked gets a 407 challenge first and then succeeds. - HTTP CONNECT to the broker's host name on port 443, with TLS end to end inside the tunnel. Only `https://` broker URLs go through it; anything that is not CONNECT is refused. - It reaches only the trading, account and sign-in hosts of the brokers on that address (up to 3, all of one address family), and ip.quantgrid.in. Never an IP address in place of a host name. - IPv4 or IPv6: QuantGrid sells IPv6 where it has confirmed the broker accepts it, otherwise IPv4. An IPv6 address works only with brokers that accept IPv6. The trader's own connection needs no IPv6: the code reaches the proxy over IPv4. Brokers ready to choose when this file was built, with the address family sold for each (it can change; https://quantgrid.in/static-ip/brokers is current, and lists the brokers available on request): Zerodha (IPv6), Angel One (IPv4), Dhan (IPv6), Upstox (IPv6), FYERS (IPv6), Groww (IPv6), Kotak Securities (IPv4), 5paisa (IPv6), Alice Blue (IPv6), Motilal Oswal (IPv4), ICICI Direct (IPv6), Shoonya (Finvasia) (IPv4), 5paisa (XTS) (IPv4), Arrow (IPv4), Axis Direct (IPv4), CompositEdge (XTS) (IPv4), Definedge (IPv4), Firstock (IPv4), Flattrade (IPv4), HDFC Securities (IPv6), HDFC Sky (IPv6), IIFL (XTS) (IPv4), IIFL Capital (IPv6), Indiabulls (XTS) (IPv4), INDmoney (IPv4), Jainam (XTS) (IPv4), m.Stock (IPv4), Nubra (IPv6), Nuvama Wealth (IPv4), Paytm Money (IPv4), Pocketful (IPv4), RMoney (XTS) (IPv4), Rupeezy (IPv6), Samco (IPv4), Tradejini (IPv4), TradeSmart (IPv4), Ventura Securities (IPv4), Wisdom Capital (XTS) (IPv4), Zebu (MYNT) (IPv4). ## Limits (per address) | Limit | Value | Past it | | --- | --- | --- | | Connections open at once | 16 | 429 Too Many Connections | | New connections a minute | 120 | 429 Too Many Connections | | Fair use a day, counted by the IST day | 200 MB | Until midnight IST no connection is refused, but each one closes once it has moved another 256 KB, and the client opens a new one | | Idle connection | closed after 120 seconds | The client opens a new one when it next needs it | Order, account and sign-in traffic is far below these. Hitting them means something else is going through the proxy, or a connection is opened per call. ## Errors The proxy answers a CONNECT it will not open with one of these status lines and closes the connection. After a `200`, every answer is the broker's own: a broker that rejects the IP needs the static IP the dashboard shows registered (step 2). | Answer | What it means | Fix | | --- | --- | --- | | 407 Proxy Authentication Required | No login was sent, or the username or password is wrong. Clients that wait to be asked (Java, .NET) see it once before they send the login. | Check QUANTGRID_PROXY_URL against the dashboard, and percent-encode any special character in the password. Do not retry in a loop: repeated failed sign-ins from one network address block it from the proxy for a time. | | 403 Destination Not Allowed | The host is not a trading, account or sign-in host of a broker on this address, nor ip.quantgrid.in; or it was an IP address instead of a host name. | Send only broker order, account and sign-in calls through the proxy, to the broker's host name on port 443. Check in the dashboard that the broker is on this address. Other IP-check sites are refused by design. | | 403 Address Suspended | The address is suspended (unpaid past its grace days, or by QuantGrid), or the account is closed. | Check the address and its payment in the dashboard. A suspended address is restored once the payment is taken. | | 403 Service Paused | QuantGrid has paused the proxy for every address. | Wait and try again later, with a pause between tries. | | 429 Too Many Connections | Over 16 connections open at once, or over 120 new connections a minute, on this address. | Reuse one client or session for every broker call instead of opening a connection per call, and wait before trying again. | | 503 Address Not Ready | The address is not set up yet, or not on the proxy's server just now. | Wait a few minutes after the purchase and try again, with a pause between tries. | | 503 Proxy Not Ready | The proxy cannot check logins just now. Your login is not the problem. | Try again shortly, with a pause between tries. | | 502 Destination Unresolvable | The broker's host has no address in this address's family, for example an IPv6 address and a host that answers only on IPv4. | Check the host name. If it is your broker's own order host, write to QuantGrid support. | | 502 Destination Unreachable | The broker's server refused the connection or did not answer in time. | Try again with a pause between tries. If it lasts, the broker's API may be down. | | 405 Method Not Allowed | The client sent a plain request instead of CONNECT: an http:// URL through the proxy. | Call the broker on https:// only, and send only https:// through the proxy. | | 400 Bad Request | The proxy could not read the request: malformed, too large or too slow. | Use a standard HTTP client's proxy setting rather than writing the CONNECT request by hand. | ## Client recipes Each recipe reads QUANTGRID_PROXY_URL, builds one client for broker order, account and sign-in calls that uses the proxy, and a second, direct client for everything else, then prints the static IP through the proxy. Keep that shape when you adapt it to the trader's code: replace the test request with their broker calls. ### Python, with requests ```python import os import requests PROXY = os.environ["QUANTGRID_PROXY_URL"] # One session for every order, account and sign-in call keeps the # tunnel to your broker open, so an order does not wait for a new # connection. session = requests.Session() session.proxies = {"http": PROXY, "https": PROXY} # Market data, quotes and instrument files: a second session, direct. data = requests.Session() data.trust_env = False # Prints the address your broker sees: your static IP. print(session.get("https://ip.quantgrid.in").text) ``` Send every order, account and sign-in call to your broker through session, and everything else through data. ### KiteConnect ```python import os from kiteconnect import KiteConnect PROXY = os.environ["QUANTGRID_PROXY_URL"] # Orders, account and sign-in calls: through your static IP. kite = KiteConnect(api_key="your_api_key", proxies={"https": PROXY}) # Instrument downloads and quotes: a second client, direct. kite_data = KiteConnect(api_key="your_api_key") ``` KiteConnect keeps one session for its calls, so orders reuse the open tunnel. Give both clients the same access token and call instruments() and quote() on kite_data: they need no static IP, and the instrument file would count against your daily fair use. Its live market-data feed connects to the broker directly, as it should. ### JavaScript, Node.js with undici ```javascript import { fetch, ProxyAgent } from "undici"; // One agent, reused for every order, account and sign-in call. const broker = new ProxyAgent(process.env.QUANTGRID_PROXY_URL); // Market data, quotes and instrument files: fetch without the // dispatcher, which goes direct. // Prints the address your broker sees: your static IP. const res = await fetch("https://ip.quantgrid.in", { dispatcher: broker }); console.log(await res.text()); ``` Install undici with npm install undici and run this as an ES module (a .mjs file). Pass dispatcher: broker on every call to your broker, and never make it the global dispatcher. ### Go, with net/http ```go package main import ( "fmt" "io" "net/http" "net/url" "os" ) // Market data, quotes and instrument files: a second client, direct. var data = &http.Client{Transport: &http.Transport{}} func main() { proxy, err := url.Parse(os.Getenv("QUANTGRID_PROXY_URL")) if err != nil { panic(err) } // One client, reused for every order, account and sign-in call. broker := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxy)}} // Prints the address your broker sees: your static IP. res, err := broker.Get("https://ip.quantgrid.in") if err != nil { panic(err) } defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` Create broker once and share it. A transport with no Proxy set, as data has, never reads HTTPS_PROXY, so market data stays direct. ### Rust, with reqwest ```rust // Cargo.toml: reqwest = { version = "0.13", features = ["blocking"] } use std::env; fn main() -> Result<(), Box> { let proxy = reqwest::Proxy::https(env::var("QUANTGRID_PROXY_URL")?)?; // One client, reused for every order, account and sign-in call. let broker = reqwest::blocking::Client::builder().proxy(proxy).build()?; // Market data, quotes and instrument files: a second client, direct. let _data = reqwest::blocking::Client::builder().no_proxy().build()?; // Prints the address your broker sees: your static IP. println!("{}", broker.get("https://ip.quantgrid.in").send()?.text()?); Ok(()) } ``` Proxy::https sends only https:// requests through the proxy, and reqwest reads the login from the URL. Clone broker to share it: a clone shares its connections. ### Java 11 and later, with HttpClient ```java import java.net.*; import java.net.http.*; public class StaticIp { public static void main(String[] args) throws Exception { // Java refuses a Basic proxy login for HTTPS unless this is // empty, the same as -Djdk.http.auth.tunneling.disabledSchemes= System.setProperty("jdk.http.auth.tunneling.disabledSchemes", ""); URI proxy = URI.create(System.getenv("QUANTGRID_PROXY_URL")); String[] login = proxy.getUserInfo().split(":", 2); // One client, reused for every order, account and sign-in call. HttpClient broker = HttpClient.newBuilder() .proxy(ProxySelector.of(new InetSocketAddress(proxy.getHost(), proxy.getPort()))) .authenticator(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return getRequestorType() == RequestorType.PROXY ? new PasswordAuthentication(login[0], login[1].toCharArray()) : null; } }) .build(); // Market data, quotes and instrument files: a second client, direct. HttpClient data = HttpClient.newBuilder().proxy(HttpClient.Builder.NO_PROXY).build(); // Prints the address your broker sees: your static IP. HttpRequest request = HttpRequest.newBuilder(URI.create("https://ip.quantgrid.in")).build(); System.out.println(broker.send(request, HttpResponse.BodyHandlers.ofString()).body()); } } ``` Set the property before the first HttpClient is built, in code as here or with -Djdk.http.auth.tunneling.disabledSchemes= on the java command line: without it Java never sends the login and every call comes back 407. Java's HttpClient cannot use TLS to a proxy, so it reaches port 3128 over plain HTTP, whatever QUANTGRID_PROXY_URL starts with: your broker traffic stays encrypted end to end, and only your proxy login travels unencrypted as far as the proxy. ### C#, .NET with HttpClient ```csharp using System.Net; var proxy = new Uri(Environment.GetEnvironmentVariable("QUANTGRID_PROXY_URL")!); var login = proxy.UserInfo.Split(':', 2); // One client, reused for every order, account and sign-in call. var broker = new HttpClient(new SocketsHttpHandler { Proxy = new WebProxy($"{proxy.Scheme}://{proxy.Authority}") { Credentials = new NetworkCredential(Uri.UnescapeDataString(login[0]), Uri.UnescapeDataString(login[1])), }, }); // Market data, quotes and instrument files: a second client, direct. var data = new HttpClient(new SocketsHttpHandler { UseProxy = false }); // Prints the address your broker sees: your static IP. Console.WriteLine(await broker.GetStringAsync("https://ip.quantgrid.in")); ``` Create broker once for the life of your program and share it. .NET sends the login once the proxy asks for it. ### A broker SDK Most broker SDKs take a proxy setting or let you pass your own HTTP session: give them the proxy client, and give their market-data, instrument and websocket parts a direct one. If an SDK can only use a global proxy, set HTTPS_PROXY only for a process that does nothing else, or list its other hosts in NO_PROXY. ## Agent checklist before finishing - [ ] Only broker order, account and sign-in calls use the proxy client; market data, websockets and instrument downloads use a direct client. - [ ] The proxy client is created once and reused for every broker call. - [ ] No global proxy, unless the program calls nothing but the broker's order, account and sign-in hosts. - [ ] The login comes only from QUANTGRID_PROXY_URL; nothing in source, committed files, logs or the chat. - [ ] Port 3128, `https://` to the proxy (`http://` only for a client that cannot speak TLS to a proxy). - [ ] Through the proxy, https://ip.quantgrid.in prints the static IP the dashboard shows. - [ ] A 407 or 403 is reported to the trader, never retried in a loop; a 429, 502 or 503 is retried only after a pause. - [ ] Nothing about what the code trades, when, or how much has changed. More: https://quantgrid.in/static-ip#setup, https://quantgrid.in/static-ip/brokers, and the Acceptable Use Policy at https://quantgrid.in/aup.