Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Member Polls
whats your favorite language

Setting Up Static IP for FlatTrade API Trading

Last updated on 1 day ago
C
caaSuper Admin
Posted 1 day ago
How to Run: Save as .py, fill in your details, run from terminal. If token gen fails, their docs have a curl example – adapt it.
Tweaks: For real trading, add error handling, loops for polling, etc. Don't hardcode passwords – use env vars.
Debug: If IP issues, you'll get a rejection error. Logs in SDK help.
Their full docs at pi.flattrade.in/docs have more endpoints like modify/cancel orders.
C
caaSuper Admin
Posted 1 day ago
Sample Python Program for FlatTrade REST API
This logs in, places a buy order for a stock (e.g., CANBK-EQ on NSE), checks order book, and gets some market data. Run it from your static IP machine. Replace placeholders with your actual creds.

# sample_flattrade_api.py
# Quick demo for FlatTrade REST API in Python
# Run: python sample_flattrade_api.py
# Needs: pip install requests pyotp (for TOTP if needed)
# And their SDK: download from github.com/flattrade/pythonAPI/dist and pip install the .whl

import json
import requests
from api_helper import FlatTradeAPI # From their SDK, rename if needed

# Your creds from portal
USER_ID = 'YOUR_CLIENT_ID' # e.g., FT123456
PASSWORD = 'YourPassword@123'
TOTP_KEY = 'Your32DigitTOTPKey' # From auth app setup
API_KEY = 'YourGeneratedAPIKey' # From Pi portal
API_SECRET = 'YourGeneratedSecret'

# Step 1: Generate access token (manual-ish, automate if you want)
def get_access_token():
url = 'https://authapi.flattrade.in/ftauth/User/Session'
payload = {
'UserId': USER_ID,
'Password': PASSWORD,
'TOTPSecret': TOTP_KEY # Or generate OTP with pyotp if dynamic
}
headers = {'Content-Type': 'application/json'}
response = requests.post(url, json=payload)
if response.status_code == 200:
data = response.json()
return data.get('Token') # Or whatever the key is, check docs
else:
print(f"Login failed: {response.text}")
return None

# Main stuff
token = get_access_token()
if not token:
print("Can't proceed without token. Check creds.")
exit()

# Init the API client from their SDK
api = FlatTradeAPI(API_KEY, API_SECRET, token) # Adjust if SDK params differ

# Step 2: Place a sample buy order (CNC, limit)
ret = api.place_order(
buy_or_sell='B', # B for buy, S for sell
product_type='C', # C for CNC (delivery)
exchange='NSE',
tradingsymbol='CANBK-EQ', # Stock symbol
quantity=1,
discloseqty=0,
price_type='LMT', # Limit order
price=500.00, # Your limit price
trigger_price=None,
retention='DAY', # Valid for day
remarks='TestOrder123'
)
print("Order placement response:", json.dumps(ret, indent=4))

# Step 3: Check order book
order_book = api.get_order_book()
print("Order Book:", json.dumps(order_book, indent=4))

# Step 4: Get some market quote
quote = api.get_quotes('NSE', 'CANBK-EQ')
print("Market Quote for CANBK:", json.dumps(quote, indent=4))

# Bonus: If you want websocket for live data (not REST, but handy)
# api.start_websocket() or something – check their example_market.py

print("Done! Check your FlatTrade app for order status.")
C
caaSuper Admin
Posted 1 day ago
Register the IP with FlatTrade:
Log in to their portal: wall.flattrade.in (use your client ID, password, and TOTP/OTP).
Go to the top menu > "Pi" > "Create New API Key".
Fill in:
App Name: Whatever, like "MyTradingApp".
App Short Name: Short version, e.g., "MTA".
Redirect URL: This is for auth callback – if you're building your own, use something like "http://localhost:8080/callback". Or grab one from your integrator/tool.
Static IP: Paste your primary IP here (mandatory). Add secondary if you have one.

Accept T&C, hit Create. You'll get an API Key and Secret right away.
Note: Orders will only work from that IP. If you're on a VPS, run your code there.

Test It:
From your whitelisted IP, try placing a test order via API.
If it fails with IP-related errors, double-check the whitelist or contact FlatTrade support (they're pretty responsive on their portal).

Gotchas:
For Client-Generated Algos (your own scripts), the IP must be yours, not shared.
If you're using tools like AlgoTest or Tradetron, they might have their own redirect URLs – copy those when creating the key.
No static IP? API creation still happens, but orders won't execute.


Alright, now for the sample program. I pulled this together from their GitHub Python SDK and docs (github.com/flattrade/pythonAPI). It's REST API stuff – place orders, get quotes, etc. I made it simple, like something I'd hack together on a weekend. Assumes you have Python 3, and you've installed their lib: pip install flatapi (wait, actually their wheel file from GitHub – download and pip install flattrade-0.1-py3-none-any.whl or whatever the latest is).
C
caaSuper Admin
Posted 1 day ago
Hey, so you're looking to hook up a static IP with FlatTrade's API for trading. From what I've seen, this is mostly about complying with SEBI rules in India – they want to track where orders are coming from for security reasons. FlatTrade (or Flattrade, same thing) makes it mandatory for algo trading setups. I'll break it down step by step, based on their docs and some common setups I've come across. Then I'll toss in a sample Python program using their REST API, since that's what "seo type" might mean? (Guessing it's a typo for "REST type" – their API is REST-based anyway). I'll keep it real and straightforward, like I'm just sharing notes from my own tinkering.
Why Static IP?

Dynamic IPs (the ones that change every time you reboot your router) aren't allowed for API orders. SEBI says all algo/API trades need to come from a fixed, registered IP.
FlatTrade requires you to whitelist a primary static IP when creating your API key. You can add a secondary one as backup (optional).
You can change it once a week max, unless something weird happens.
If you don't update it, your API orders won't go through after April 1, 2026 (per their support portal – yeah, future date, but it's in the rules now).

How to Get and Use a Static IP

Get a Static IP:
From your ISP: Call up your internet provider (like Airtel, Jio, BSNL in India). Ask for a static IP add-on. Costs around ₹500-2000/month depending on the plan. They'll assign one to your connection.
Cheaper/Easier Alternative: Use a VPS (Virtual Private Server). This is what most folks do for trading – it's reliable and you control it.
Sign up for Azure, AWS, or Google Cloud (free tier might work for testing).
Create a basic VM (e.g., Ubuntu on Azure, ₹300-500/month).
The public IP is static by default or you can reserve one.
Example: On Azure, go to Virtual Machines > Create > Basics tab > Set "Public IP" to "Static". Boom, you get an IP like 20.204.123.45.
Verify it: SSH into the VM and run curl ifconfig.me – that's your static IP.

Pro tip: Avoid VPNs for this; they might not be compliant, and dynamic ones defeat the purpose.
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Users Online Now
Guests Online 10
Members Online 0

Total Members: 21
Newest Member: brijamohanjha