upstox-java

Upstox Java SDK Examples

This directory contains Java SDK code examples for the Upstox API, organized by category.

Prerequisites

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>com.upstox.api</groupId>
    <artifactId>upstox-java-api</artifactId>
    <version>LATEST</version>
    <scope>compile</scope>
</dependency>

Folder Structure

Category Description
login Authentication — get access token and logout
user User profile, fund/margin details, IP management, kill switch
orders Place, modify, cancel orders and fetch order details
portfolio Positions, holdings, MTF positions, and position conversion
market-quote LTP, OHLC, full market quotes, and option greeks
historical-data Historical and intra-day candle data
option-chain Option contracts and put/call option chain
expired-instruments Expired instrument data and historical candles
market-information Exchange status, market timings, holidays, OI, change in OI, PCR, max pain, FII, and DII
fundamentals Company profile, balance sheet, cash flow, income statement, key ratios, share holdings, corporate actions, and competitors
gtt-orders Good Till Triggered (GTT) order management
margins Order margin calculations
charges Brokerage charge calculations
trade-profit-and-loss Trade-wise profit and loss reports
strategies/ Ready-to-run options strategy examples for Nifty 50 (bullish, bearish, neutral, others).

Options Strategies

Each strategy file searches for the required Nifty 50 option legs using the Instruments API and places market orders via the v3 Order API.

Bullish

File Strategy Legs
BuyCall.java Buy Call BUY ATM CE
SellPut.java Sell Put SELL ATM PE
BullCallSpread.java Bull Call Spread BUY ATM CE + SELL ATM+1 CE
BullPutSpread.java Bull Put Spread SELL ATM PE + BUY ATM-1 PE
BullButterfly.java Bull Butterfly BUY ATM CE + SELL 2× ATM+1 CE + BUY ATM+2 CE
BullCondor.java Bull Condor BUY ATM CE + SELL ATM+1 CE + SELL ATM+2 CE + BUY ATM+3 CE
LongCalendarCall.java Long Calendar with Calls SELL current-week ATM CE + BUY next-week ATM CE
LongSyntheticFuture.java Long Synthetic Future BUY ATM CE + SELL ATM PE
CallRatioBackSpread.java Call Ratio Back Spread SELL 1× ATM CE + BUY 2× ATM+1 CE
RangeForward.java Range Forward SELL ATM-1 PE + BUY ATM+1 CE

Bearish

File Strategy Legs
BuyPut.java Buy Put BUY ATM PE
SellCall.java Sell Call SELL ATM CE
BearCallSpread.java Bear Call Spread SELL ATM CE + BUY ATM+1 CE
BearPutSpread.java Bear Put Spread BUY ATM PE + SELL ATM-1 PE
BearButterfly.java Bear Butterfly BUY ATM PE + SELL 2× ATM-1 PE + BUY ATM-2 PE
BearCondor.java Bear Condor BUY ATM PE + SELL ATM-1 PE + SELL ATM-2 PE + BUY ATM-3 PE
LongCalendarPut.java Long Calendar with Puts SELL current-week ATM PE + BUY next-week ATM PE
ShortSyntheticFuture.java Short Synthetic Future SELL ATM CE + BUY ATM PE
PutRatioBackSpread.java Put Ratio Back Spread SELL 1× ATM PE + BUY 2× ATM-1 PE
RiskReversal.java Risk Reversal SELL ATM+1 CE + BUY ATM-1 PE

Neutral

File Strategy Legs
ShortStraddle.java Short Straddle SELL ATM CE + SELL ATM PE
ShortStrangle.java Short Strangle SELL ATM+1 CE + SELL ATM-1 PE
IronButterfly.java Iron Butterfly SELL ATM CE + SELL ATM PE + BUY ATM+2 CE + BUY ATM-2 PE
Batman.java Batman BUY ATM CE + SELL 2× ATM+1 CE + BUY ATM+2 CE + BUY ATM PE + SELL 2× ATM-1 PE + BUY ATM-2 PE
ShortIronCondor.java Short Iron Condor SELL ATM+1 CE + BUY ATM+2 CE + SELL ATM-1 PE + BUY ATM-2 PE

Others

File Strategy Legs
LongStraddle.java Long Straddle BUY ATM CE + BUY ATM PE
LongStrangle.java Long Strangle BUY ATM+1 CE + BUY ATM-1 PE
CallRatioSpread.java Call Ratio Spread BUY 1× ATM CE + SELL 2× ATM+1 CE
PutRatioSpread.java Put Ratio Spread BUY 1× ATM PE + SELL 2× ATM-1 PE
LongIronButterfly.java Long Iron Butterfly BUY ATM CE + BUY ATM PE + SELL ATM+2 CE + SELL ATM-2 PE
LongIronCondor.java Long Iron Condor BUY ATM+1 CE + SELL ATM+2 CE + BUY ATM-1 PE + SELL ATM-2 PE
Strip.java Strip BUY 1× ATM CE + BUY 2× ATM PE
Strap.java Strap BUY 2× ATM CE + BUY 1× ATM PE