This is sample code for learning only. It is not advice, and it is not a recommendation to trade.
This code can have bugs. Read the code and check it yourself. Test it first on Sandbox (UAT / Test — NOT live).
You are fully responsible for any live trade and for any loss. Markets are risky. You can lose money.
INFINN (HKKR Finserv Pvt Ltd) is not responsible for losses from using this code.
Questions: support@infinn.in
If you use a ready-made strategy on a live account, the exchange may need to approve it first. Do not go live until this is checked. See the SEBI retail algo rules and write to support@infinn.in.
The program is built in your browser from infinn_straddle_strangle.py. The choices you make are not saved on a server. The program has no keys or secrets. The toolkit reads them from environment variables (a place on your computer, not in the file).
5 easy steps
- Install Python. You need Python 3.9 or later. Get it from python.org. On Windows, tick the box that says “Add Python to PATH”.
- Install the INFINN toolkit. Download infinn-0.1.2-py3-none-any.whl, then run:
pip install ./infinn-0.1.2-py3-none-any.whl "websocket-client>=1.6"The short command pip install infinn is not on PyPI yet. Use the wheel file.
- Set your key. Put your API key and secret in environment variables. Do not type them into the program. On Windows Command Prompt:
set INFINN_API_KEY=your_app_key
set INFINN_API_SECRET=your_api_secret- Get your code. On this page, pick an index, pick Straddle or Strangle, then set your stop loss, target and lots. You can start from a ready plan below. Tick I have read this, then click Copy code or Download. You get one
.pyfile. - Run it on Sandbox (UAT / Test — NOT live). This starts as a dry run, so no orders are sent.
python infinn_nifty_straddle_sell.py --entry now
python infinn_nifty_straddle_sell.py # waits for your entry time
python infinn_nifty_straddle_sell.py --place-orders # real orders, still on Sandbox (UAT / Test — NOT live)On Windows, you can also download a .bat file and double-click it. Put it in the same folder as the .py file. The program opens the Sandbox login link. Type your User ID in CAPITALS, then your password and TOTP, then paste the full redirect URL. The login is reused for the day.
The trade rules are not made up for each person. Every program is the same tested file (infinn_straddle_strangle.py, engine sha256 4aeeb9647e3128b6…). Only the BUILDER_SETTINGS block changes.
Sandbox (UAT / Test — NOT live) currently sends no MCX prices, so a CRUDEOIL or CRUDEOILM test run may show no prices and stop before entry. Use NIFTY, BANKNIFTY or SENSEX to test the full flow. Sandbox prices and fills follow the test system, not the real market.
CRUDEOIL and CRUDEOILM trade on MCX, usually from 09:00 to 23:30 IST. When the US is on daylight time, the session can run until 23:55 IST. The program picks the nearest expiry for you (including on monthly crude options). On expiry day, once the session is nearly over, it moves to the next expiry. The reference price is the near-month MCX future, because crude has no spot index.
Build your program
Start from a ready plan, or fill the three steps. Open More options if you need extra settings. Copy and Download stay off until you tick I have read this. This page never turns --confirm-live on for you.
This is sample code for learning only. It is not advice, and it is not a recommendation to trade.
This code can have bugs. Read the code and check it yourself. Test it first on Sandbox (UAT / Test — NOT live).
You are fully responsible for any live trade and for any loss. Markets are risky. You can lose money.
INFINN (HKKR Finserv Pvt Ltd) is not responsible for losses from using this code.
Questions: support@infinn.in
You must tick this before you can copy or download the program.Settings block (this is the only part that changes):
Show the full program (0 lines)
What you can set
| Condition | Options | Program setting |
|---|---|---|
| Strategy | Straddle (ATM) or strangle | MODE |
| Strangle strikes | By points from ATM, by number of strikes, or by premium closest to a value | STRANGLE_BY, STRANGLE_OTM_POINTS, STRANGLE_OTM_STRIKES, STRANGLE_PREMIUM |
| Side | SELL (short) or BUY (long) | SIDE |
| Underlying | NIFTY, BANKNIFTY, SENSEX, CRUDEOIL, CRUDEOILM (MCX). No GOLD. | UNDERLYING |
| Expiry | Picked for you: the nearest date (current). Optional Next expiry is in More options. You never type a date. On expiry day it rolls to the next one after the session cutoff. | EXPIRY |
| Quantity | Lots per leg with a safety cap (max 10 in the builder); freeze quantity checked | LOTS, MAX_LOTS |
| Entry | Fixed time, X minutes after open, or now; optional last entry time | ENTRY_TIME, LAST_ENTRY_TIME |
| Entry filter | Combined CE + PE premium inside a range | ENTRY_MIN_PREMIUM, ENTRY_MAX_PREMIUM |
| Per-leg stoploss | % or points; exit that leg or both; move the other leg to cost | LEG_SL_PCT / LEG_SL_POINTS, LEG_SL_ACTION, MOVE_SL_TO_COST |
| Combined stoploss / target | In ₹, premium points, or % of combined entry premium | MTM_UNIT, COMBINED_SL, COMBINED_TARGET |
| Trailing stop | Start at profit X, exit if profit falls Y from its best | TRAIL_START, TRAIL_GAP |
| Lock profit | Once profit reaches X, exit if it falls back to Y | LOCK_TRIGGER, LOCK_MIN |
| Re-entry | After a stoploss: max 1–5 times, cooldown in minutes | REENTRY_ON_SL, MAX_REENTRIES, REENTRY_COOLDOWN_MINS |
| Time exit | Hard exit time | EXIT_TIME |
| Daily limits | Max loss and max profit for the whole account | MAX_LOSS_PER_DAY_RS, MAX_PROFIT_PER_DAY_RS |
| Orders | LIMIT with a buffer, or MARKET | ORDER_TYPE, LIMIT_BUFFER_PCT |
| Safety | Sandbox (UAT / Test — NOT live) by default, dry run by default | ENV, DRY_RUN |
The program checks exits in this order, every time the price updates: time exit, lost price feed, daily max loss, per-leg stop loss, combined stop loss, target, daily max profit, lock profit, trailing stop. A stop loss always wins over a target on the same update.
Safety
- Sandbox and dry run by default. Sandbox (UAT / Test — NOT live) is a test system. A dry run means the program only pretends to send orders. Live needs
ENV = "live",--confirm-liveand typingI UNDERSTAND. This page never sets--confirm-livefor you. - A stop loss is required. Lots are capped. Times and numbers are checked here, and checked again by the program before it does anything.
- Every exit closes open sides and tries again if needed. If a close cannot finish, the program prints MANUAL ACTION NEEDED and exits with code 4.
- No keys, passwords or tokens are ever written into the program.
- The disclaimer at the top of this page is also next to the Copy and Download buttons, at the top of every generated program, and printed once when the program starts. You must tick I have read this before you can copy or download.
Before any live use
- Run the dry run and Sandbox (UAT / Test — NOT live) orders on several days, including a stop-loss exit and a Ctrl+C exit.
- Confirm the SEBI retail algo rules (exchange approval) for your strategy with support@infinn.in.
- Register your static IP for API orders. Start with one lot and keep the daily max loss on.
Questions: support@infinn.in. INFINN does not give investment advice.