public class KiteConnect extends Object implements AutoCloseable
| Modifier and Type | Field and Description |
|---|---|
static boolean |
ENABLE_LOGGING |
static SessionExpiryHook |
sessionExpiryHook |
| Constructor and Description |
|---|
KiteConnect(String apiKey)
Initializes KiteSDK with the api key provided for your app.
|
KiteConnect(String apiKey,
boolean enableDebugLog)
Initializes KiteSDK with the api key provided for your app.
|
KiteConnect(String apiKey,
Proxy userProxy,
boolean enableDebugLog)
Initializes KiteSDK with the api key provided for your app.
|
| Modifier and Type | Method and Description |
|---|---|
GTT |
cancelGTT(int gttId)
Cancel GTT.
|
boolean |
cancelMFOrder(String orderId)
If cancel is successful then api will respond as 200 and send back true else it will be sent back to user as KiteException.
|
boolean |
cancelMFSIP(String sipId)
Cancel a mutualfunds sip.
|
Order |
cancelOrder(String orderId,
String variety)
Cancels an order.
|
Order |
cancelOrder(String orderId,
String parentOrderId,
String variety)
Cancel/exit special orders like BO, CO
|
void |
close()
Releases any network resources associated with this client.
|
org.json.JSONObject |
convertPosition(String tradingSymbol,
String exchange,
String transactionType,
String positionType,
String oldProduct,
String newProduct,
int quantity)
Modifies an open position's product type.
|
User |
generateSession(String requestToken,
String apiSecret)
Do the token exchange with the `request_token` obtained after the login flow,
and retrieve the `access_token` required for all subsequent requests.
|
String |
getAccessToken()
Returns accessToken.
|
String |
getApiKey()
Returns apiKey of the App.
|
List<AuctionInstrument> |
getAuctionInstruments()
Fetches collection of auction instruments available for bidding.
|
CombinedMarginData |
getCombinedMarginCalculation(List<MarginCalculationParams> params,
boolean considerPositions,
boolean compactMode)
Get margins required data for multiple instruments before placing an order,
this can be used to check the margin required for taking hedged positions.
|
GTT |
getGTT(int gttId)
Fetch details of a GTT.
|
List<GTT> |
getGTTs()
Fetches list of gtt existing in an account.
|
HistoricalData |
getHistoricalData(Date from,
Date to,
String token,
String interval,
boolean continuous,
boolean oi)
Retrieves historical data for an instrument.
|
List<Holding> |
getHoldings()
Retrieves the list of holdings.
|
List<Instrument> |
getInstruments()
Retrieves list of market instruments available to trade.
|
List<Instrument> |
getInstruments(String exchange)
Retrieves list of market instruments available to trade for an exchange
Response is array for objects.
|
String |
getLoginURL()
Retrieves login url
|
Map<String,LTPQuote> |
getLTP(String[] instruments)
Retrieves last price.
|
List<MarginCalculationData> |
getMarginCalculation(List<MarginCalculationParams> params)
Get margins required data before placing an order.
|
Map<String,Margin> |
getMargins()
Gets account balance and cash margin details for a equity and commodity.
|
Margin |
getMargins(String segment)
Gets account balance and cash margin details for a particular segment.
|
List<MFHolding> |
getMFHoldings()
Retrieve all the mutualfunds holdings.
|
List<MFInstrument> |
getMFInstruments()
Retrieves mutualfunds instruments.
|
MFOrder |
getMFOrder(String orderId)
Retrieves individual mutualfunds order.
|
List<MFOrder> |
getMFOrders()
Retrieves all mutualfunds orders.
|
MFSIP |
getMFSIP(String sipId)
Retrieve an individual sip.
|
List<MFSIP> |
getMFSIPs()
Retrieve all mutualfunds sip.
|
Map<String,OHLCQuote> |
getOHLC(String[] instruments)
Retrieves OHLC and last price.
|
List<Order> |
getOrderHistory(String orderId)
Returns list of different stages an order has gone through.
|
List<Order> |
getOrders()
Fetches collection of orders from the orderbook.
|
List<Trade> |
getOrderTrades(String orderId)
Retrieves list of trades executed of an order.
|
Map<String,List<Position>> |
getPositions()
Retrieves the list of positions.
|
Profile |
getProfile()
Get the profile details of the use.
|
String |
getPublicToken()
Returns publicToken.
|
Map<String,Quote> |
getQuote(String[] instruments)
Retrieves quote and market depth for an instrument
|
List<Trade> |
getTrades()
Retrieves list of trades executed.
|
String |
getUserId()
Returns userId.
|
List<ContractNote> |
getVirtualContractNote(List<ContractNoteParams> params)
A virtual contract provides detailed charges order-wise for brokerage, STT, stamp duty, exchange transaction charges, SEBI turnover charge, and GST.
|
org.json.JSONObject |
invalidateAccessToken()
Kills the session by invalidating the access token.
|
org.json.JSONObject |
invalidateRefreshToken(String refreshToken)
Kills the refresh token.
|
org.json.JSONObject |
logout()
Logs out user by invalidating the access token.
|
GTT |
modifyGTT(int gttId,
GTTParams gttParams)
Modify a GTT.
|
boolean |
modifyMFSIP(String frequency,
int day,
int instalments,
double amount,
String status,
String sipId)
Modify a mutualfunds sip.
|
Order |
modifyOrder(String orderId,
OrderParams orderParams,
String variety)
Modifies an open order.
|
GTT |
placeGTT(GTTParams gttParams)
Place a GTT.
|
MFOrder |
placeMFOrder(String tradingsymbol,
String transactionType,
double amount,
double quantity,
String tag)
Place a mutualfunds order.
|
MFSIP |
placeMFSIP(String tradingsymbol,
String frequency,
int installmentDay,
int instalments,
int initialAmount,
double amount)
Place a mutualfunds sip.
|
OrderResponse |
placeOrder(OrderParams orderParams,
String variety)
Places an order for the given variety.
|
TokenSet |
renewAccessToken(String refreshToken,
String apiSecret)
Get a new access token using refresh token.
|
void |
setAccessToken(String accessToken)
Set the accessToken received after a successful authentication.
|
void |
setPublicToken(String publicToken)
Set publicToken.
|
void |
setSessionExpiryHook(SessionExpiryHook hook)
Registers callback for session error.
|
void |
setUserId(String id)
Set userId.
|
String |
sha256Hex(String str)
Hex encodes sha256 output for android support.
|
public static SessionExpiryHook sessionExpiryHook
public static boolean ENABLE_LOGGING
public KiteConnect(String apiKey)
apiKey - is the api key provided after creating new Kite Connect app on developers console.public KiteConnect(String apiKey, boolean enableDebugLog)
apiKey - is the api key provided after creating new Kite Connect app on developers console.enableDebugLog - is a boolean to enable debug logspublic KiteConnect(String apiKey, Proxy userProxy, boolean enableDebugLog)
apiKey - is the api key provided after creating new Kite Connect app on developers console.userProxy - is the user defined proxy. Can be used only if a user chose to use the proxy.public void setSessionExpiryHook(SessionExpiryHook hook)
hook - can be set to get callback when session is expired.public String getApiKey() throws NullPointerException
NullPointerException - if _apiKey is not found.public String getAccessToken() throws NullPointerException
NullPointerException - if accessToken is null.public String getUserId() throws NullPointerException
NullPointerException - if userId is null.public void setUserId(String id)
id - is user_id.public String getPublicToken() throws NullPointerException
NullPointerException - if publicToken is null.public void setAccessToken(String accessToken)
accessToken - is the access token received after sending request token and api secret.public void setPublicToken(String publicToken)
publicToken - is the public token received after sending request token and api secret.public void close()
close in interface AutoCloseablepublic String getLoginURL() throws NullPointerException
NullPointerExceptionpublic User generateSession(String requestToken, String apiSecret) throws KiteException, org.json.JSONException, IOException
requestToken - received from login process.apiSecret - which is unique for each aap.KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public TokenSet renewAccessToken(String refreshToken, String apiSecret) throws IOException, KiteException, org.json.JSONException
refreshToken - is the refresh token obtained after generateSession.apiSecret - is unique for each app.IOException - is thrown when there is connection error.KiteException - is thrown for all Kite trade related errors.org.json.JSONExceptionpublic String sha256Hex(String str)
str - is the String that has to be encrypted.public Profile getProfile() throws IOException, KiteException, org.json.JSONException
IOException - is thrown when there is connection error.KiteException - is thrown for all Kite trade related errors.org.json.JSONExceptionpublic Margin getMargins(String segment) throws KiteException, org.json.JSONException, IOException
segment - can be equity or commodity.KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public Map<String,Margin> getMargins() throws KiteException, org.json.JSONException, IOException
KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public List<MarginCalculationData> getMarginCalculation(List<MarginCalculationParams> params) throws IOException, KiteException, org.json.JSONException
KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public CombinedMarginData getCombinedMarginCalculation(List<MarginCalculationParams> params, boolean considerPositions, boolean compactMode) throws IOException, KiteException, org.json.JSONException
KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public List<ContractNote> getVirtualContractNote(List<ContractNoteParams> params) throws IOException, KiteException, org.json.JSONException
KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public OrderResponse placeOrder(OrderParams orderParams, String variety) throws KiteException, org.json.JSONException, IOException
orderParams - order input payload. Populate the fields required for the order being placed,
such as exchange, tradingsymbol, transactionType, quantity, product, orderType,
validity, price, triggerPrice, disclosedQuantity, tag, and marketProtection.
For Constants.VALIDITY_TTL, also set validityTTL. For
Constants.VARIETY_ICEBERG, also set icebergLegs and
icebergQuantity. For Constants.VARIETY_AUCTION, also set
auctionNumber. Set autoslice to true to allow the
order to be sliced automatically when applicable.variety - order variety to place. Supported values include regular, amo,
co, bo, iceberg, and auction, subject to API support.orderId and, when applicable,
sliced child order results.KiteException - if the Kite API returns a trading or request error.org.json.JSONException - if the response cannot be parsed as JSON.IOException - if a network or connection error occurs while placing the order.public Order modifyOrder(String orderId, OrderParams orderParams, String variety) throws KiteException, org.json.JSONException, IOException
orderParams - is Order params.variety - variety="regular". Order variety can be bo, co, amo, regular.orderId - order id of the order being modified.KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public Order cancelOrder(String orderId, String variety) throws KiteException, org.json.JSONException, IOException
orderId - order id of the order to be cancelled.variety - [variety="regular"]. Order variety can be bo, co, amo, regular.KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public Order cancelOrder(String orderId, String parentOrderId, String variety) throws KiteException, IOException, org.json.JSONException
parentOrderId - order id of first leg.orderId - order id of the order to be cancelled.variety - [variety="regular"]. Order variety can be bo, co, amo, regular.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection error.org.json.JSONExceptionpublic List<Order> getOrders() throws KiteException, org.json.JSONException, IOException
KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public List<AuctionInstrument> getAuctionInstruments() throws KiteException, org.json.JSONException, IOException
KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public List<GTT> getGTTs() throws KiteException, IOException, org.json.JSONException
KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection error.org.json.JSONExceptionpublic GTT getGTT(int gttId) throws IOException, KiteException, org.json.JSONException
gttId - is the id of the GTT that needs to be fetched.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection error.org.json.JSONException - is thrown when there is exception while parsing response.public GTT placeGTT(GTTParams gttParams) throws IOException, KiteException, org.json.JSONException
gttParams - is GTT param which container condition, type, order details. It can contain one or two orders.IOException - is thrown when there is connection error.KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.public GTT modifyGTT(int gttId, GTTParams gttParams) throws IOException, KiteException, org.json.JSONException
gttParams - is GTT param which container condition, type, order details. It can contain one or two orders.gttId - is the id of the GTT to be modified.IOException - is thrown when there is connection error.KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.public GTT cancelGTT(int gttId) throws IOException, KiteException, org.json.JSONException
gttId - order id of first leg.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection error.org.json.JSONException - is thrown when there is exception while parsing response.public List<Order> getOrderHistory(String orderId) throws KiteException, IOException, org.json.JSONException
orderId - is the order id which is obtained from orderbook.KiteException - is thrown for all Kite trade related errors.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection error.org.json.JSONExceptionpublic List<Trade> getTrades() throws KiteException, org.json.JSONException, IOException
KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public List<Trade> getOrderTrades(String orderId) throws KiteException, org.json.JSONException, IOException
orderId - order if of the order whose trades are fetched.KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public List<Holding> getHoldings() throws KiteException, org.json.JSONException, IOException
KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public Map<String,List<Position>> getPositions() throws KiteException, org.json.JSONException, IOException
KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public org.json.JSONObject convertPosition(String tradingSymbol, String exchange, String transactionType, String positionType, String oldProduct, String newProduct, int quantity) throws KiteException, org.json.JSONException, IOException
tradingSymbol - Tradingsymbol of the instrument (ex. RELIANCE, INFY).exchange - Exchange in which instrument is listed (NSE, BSE, NFO, BFO, CDS, MCX).transactionType - Transaction type (BUY or SELL).positionType - day or overnight positionoldProduct - Product code (NRML, MIS, CNC).newProduct - Product code (NRML, MIS, CNC).quantity - Order quantityKiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection error.public List<Instrument> getInstruments() throws KiteException, IOException, org.json.JSONException
KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related errors.org.json.JSONExceptionpublic List<Instrument> getInstruments(String exchange) throws KiteException, org.json.JSONException, IOException
exchange - Filter instruments based on exchange. exchange can be NSE, BSE, NFO, BFO, CDS, MCX.KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection related error.public Map<String,Quote> getQuote(String[] instruments) throws KiteException, org.json.JSONException, IOException
instruments - is the array of tradingsymbol and exchange or instrument token. For example {NSE:NIFTY 50, BSE:SENSEX} or {256265, 265}KiteException - is thrown for all Kite trade related errors.org.json.JSONException - is thrown when there is exception while parsing response.IOException - is thrown when there is connection related error.public Map<String,OHLCQuote> getOHLC(String[] instruments) throws KiteException, IOException, org.json.JSONException
instruments - is the array of tradingsymbol and exchange or instruments token.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic Map<String,LTPQuote> getLTP(String[] instruments) throws KiteException, IOException, org.json.JSONException
instruments - is the array of tradingsymbol and exchange or instruments token.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic HistoricalData getHistoricalData(Date from, Date to, String token, String interval, boolean continuous, boolean oi) throws KiteException, IOException, org.json.JSONException
from - "yyyy-mm-dd" for fetching candles between days and "yyyy-mm-dd hh:mm:ss" for fetching candles between timestamps.to - "yyyy-mm-dd" for fetching candles between days and "yyyy-mm-dd hh:mm:ss" for fetching candles between timestamps.continuous - set to true for fetching continuous data of expired instruments.interval - can be minute, day, 3minute, 5minute, 10minute, 15minute, 30minute, 60minute.token - is instruments token.oi - set to true for fetching open interest data. The default value is 0.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic List<MFInstrument> getMFInstruments() throws KiteException, IOException, org.json.JSONException
KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related errors.org.json.JSONExceptionpublic MFOrder placeMFOrder(String tradingsymbol, String transactionType, double amount, double quantity, String tag) throws KiteException, IOException, org.json.JSONException
tradingsymbol - Tradingsymbol (ISIN) of the fund.transactionType - BUY or SELL.amount - Amount worth of units to purchase. Not applicable on SELLs.quantity - Quantity to SELL. Not applicable on BUYs. If the holding is less than minimum_redemption_quantity, all the units have to be sold.tag - An optional tag to apply to an order to identify it (alphanumeric, max 8 chars).KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic boolean cancelMFOrder(String orderId) throws KiteException, IOException, org.json.JSONException
orderId - is the order id of the mutualfunds order.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there connection related error.org.json.JSONExceptionpublic List<MFOrder> getMFOrders() throws KiteException, IOException, org.json.JSONException
KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic MFOrder getMFOrder(String orderId) throws KiteException, IOException, org.json.JSONException
orderId - is the order id of a mutualfunds scrip.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic MFSIP placeMFSIP(String tradingsymbol, String frequency, int installmentDay, int instalments, int initialAmount, double amount) throws KiteException, IOException, org.json.JSONException
tradingsymbol - Tradingsymbol (ISIN) of the fund.frequency - weekly, monthly, or quarterly.amount - Amount worth of units to purchase. It should be equal to or greated than minimum_additional_purchase_amount and in multiple of purchase_amount_multiplier in the instrument master.installmentDay - If Frequency is monthly, the day of the month (1, 5, 10, 15, 20, 25) to trigger the order on.instalments - Number of instalments to trigger. If set to -1, instalments are triggered at fixed intervals until the SIP is cancelled.initialAmount - Amount worth of units to purchase before the SIP starts. Should be equal to or greater than minimum_purchase_amount and in multiple of purchase_amount_multiplier. This is only considered if there have been no prior investments in the target fund.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic boolean modifyMFSIP(String frequency, int day, int instalments, double amount, String status, String sipId) throws KiteException, IOException, org.json.JSONException
frequency - weekly, monthly, or quarterly.status - Pause or unpause an SIP (active or paused).amount - Amount worth of units to purchase. It should be equal to or greated than minimum_additional_purchase_amount and in multiple of purchase_amount_multiplier in the instrument master.day - If Frequency is monthly, the day of the month (1, 5, 10, 15, 20, 25) to trigger the order on.instalments - Number of instalments to trigger. If set to -1, instalments are triggered at fixed intervals until the SIP is cancelled.sipId - is the id of the sip.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic boolean cancelMFSIP(String sipId) throws KiteException, IOException, org.json.JSONException
sipId - is the id of mutualfunds sip.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic List<MFSIP> getMFSIPs() throws KiteException, IOException, org.json.JSONException
KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic MFSIP getMFSIP(String sipId) throws KiteException, IOException, org.json.JSONException
sipId - is the id of a particular sip.KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic List<MFHolding> getMFHoldings() throws KiteException, IOException, org.json.JSONException
KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic org.json.JSONObject logout()
throws KiteException,
IOException,
org.json.JSONException
KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic org.json.JSONObject invalidateAccessToken()
throws IOException,
KiteException,
org.json.JSONException
KiteException - is thrown for all Kite trade related errors.IOException - is thrown when there is connection related error.org.json.JSONExceptionpublic org.json.JSONObject invalidateRefreshToken(String refreshToken) throws IOException, KiteException, org.json.JSONException
refreshToken - is the token received after successful log in.IOException - is thrown for connection related errors.KiteException - is thrown for Kite trade related errors.org.json.JSONExceptionCopyright © 2026. All rights reserved.