Broker Auth: Fyers¶
Authenticate and place a demo order via the FYERS API over your static IP.
Part 05 of 20 in the ServLoci algo/options trading notebook series — full index in notebooks/README.md.
Setup¶
# Get your dedicated static IPv6 + SOCKS5 credentials free:
# https://comm.servloci.in/register (or /auth/google?free=1 for an instant trial)
# Your api_key / api_secret pair shows up in the portal after signup:
# https://comm.servloci.in/user
!pip install -q "requests[socks]"
!curl -sL https://comm.servloci.in/sdk/servloci.py -o servloci.py
import os
from servloci import ServLoci
SERVLOCI_API_KEY = os.environ.get("SERVLOCI_API_KEY", "dhan:1000000001") # broker:client_id
SERVLOCI_API_SECRET = os.environ.get("SERVLOCI_API_SECRET", "") # from the portal — leave blank to run this notebook in demo mode
sl = None
if SERVLOCI_API_SECRET:
sl = ServLoci(api_key=SERVLOCI_API_KEY, api_secret=SERVLOCI_API_SECRET)
print("ServLoci configured:", sl.host, sl.port)
else:
print("SERVLOCI_API_SECRET not set — running in demo mode (no live proxy calls).")
Support level: Confirmation flow for individual and family accounts — FYERS support verifies the requesting IP before enabling API trading.
if sl:
sl.attach() # BEFORE importing fyers-apiv3 — it creates a requests.Session at import time
from fyers_apiv3 import fyersModel
fyers = fyersModel.FyersModel(client_id=os.environ.get("FYERS_CLIENT_ID", ""),
token=os.environ.get("FYERS_ACCESS_TOKEN", ""), is_async=False)
print("Fyers client ready")
# order = fyers.place_order(data={"symbol": "NSE:INFY-EQ", "qty": 1, "type": 2,
# "side": 1, "productType": "INTRADAY"})
else:
print("Demo mode — set SERVLOCI_API_SECRET above to run this against your Fyers account.")
Install the broker SDK separately: !pip install -q fyers-apiv3. Full whitelist steps: https://comm.servloci.in/docs/brokers.
« Previous: Broker Auth: Groww
Next: Black-Scholes Pricing & Greeks »
Try the concepts above interactively: Options Strategy Builder · Docs · Get your static IP