The official Java client for communicating with the Upstox API.
Upstox API is a set of rest APIs that provide data required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (using Websocket), and more, with the easy to understand API collection.
Automatically generated by the Swagger Codegen
Building the API client library requires:
Add this dependency to your project’s POM:
<dependency>
<groupId>com.upstox.api</groupId>
<artifactId>upstox-java-sdk</artifactId>
<version>1.10.0</version>
<scope>compile</scope>
</dependency>
Add this dependency to your project’s build file:
compile "com.upstox.api:upstox-java-sdk:1.10.0"
Sample Implementations can be found within /examples
folder.
All URIs are relative to https://api.upstox.com/v2
Class | Method | HTTP request | Description |
---|---|---|---|
ChargeApi | getBrokerage | GET /v2/charges/brokerage | Brokerage details |
ChargeApi | postMargin | POST /v2/charges/margin | Calculate Margin |
HistoryApi | getHistoricalCandleData | GET /v2/historical-candle/{instrumentKey}/{interval}/{to_date} | Historical candle data |
HistoryApi | getHistoricalCandleData1 | GET /v2/historical-candle/{instrumentKey}/{interval}/{to_date}/{from_date} | Historical candle data |
HistoryApi | getIntraDayCandleData | GET /v2/historical-candle/intraday/{instrumentKey}/{interval} | Intra day candle data |
LoginApi | authorize | GET /v2/login/authorization/dialog | Authorize API |
LoginApi | autoLogin | GET /v2/auth/auto-login | Auto Login |
LoginApi | logout | DELETE /v2/logout | Logout |
LoginApi | token | POST /v2/login/authorization/token | Get token API |
MarketHolidaysAndTimingsApi | getExchangeTimings | GET /v2/market/timings/{date} | Get Exchange Timings on particular date |
MarketHolidaysAndTimingsApi | getHoliday | GET /v2/market/holidays/{date} | Get Holiday on particular date |
MarketHolidaysAndTimingsApi | getHolidays | GET /v2/market/holidays | Get Holiday list of current year |
MarketHolidaysAndTimingsApi | getMarketStatus | GET /v2/market/status/{exchange} | Get Market status for particular exchange |
MarketQuoteApi | getFullMarketQuote | GET /v2/market-quote/quotes | Market quotes and instruments - Full market quotes |
MarketQuoteApi | getMarketQuoteOHLC | GET /v2/market-quote/ohlc | Market quotes and instruments - OHLC quotes |
MarketQuoteApi | ltp | GET /v2/market-quote/ltp | Market quotes and instruments - LTP quotes. |
OptionsApi | getOptionContracts | GET /v2/option/contract | Get option contracts |
OptionsApi | getPutCallOptionChain | GET /v2/option/chain | Get option chain |
OrderApi | cancelMultiOrder | DELETE /v2/order/multi/cancel | Cancel multi order |
OrderApi | cancelOrder | DELETE /v2/order/cancel | Cancel order |
OrderApi | exitPositions | POST /v2/order/positions/exit | Exit all positions |
OrderApi | getOrderBook | GET /v2/order/retrieve-all | Get order book |
OrderApi | getOrderDetails | GET /v2/order/history | Get order history |
OrderApi | getOrderStatus | GET /v2/order/details | Get order details |
OrderApi | getTradeHistory | GET /v2/order/trades/get-trades-for-day | Get trades |
OrderApi | getTradesByOrder | GET /v2/order/trades | Get trades for order |
OrderApi | modifyOrder | PUT /v2/order/modify | Modify order |
OrderApi | placeMultiOrder | POST /v2/order/multi/place | Place multi order |
OrderApi | placeOrder | POST /v2/order/place | Place order |
PortfolioApi | convertPositions | PUT /v2/portfolio/convert-position | Convert Positions |
PortfolioApi | getHoldings | GET /v2/portfolio/long-term-holdings | Get Holdings |
PortfolioApi | getPositions | GET /v2/portfolio/short-term-positions | Get Positions |
PostTradeApi | getTradesByDateRange | GET /v2/charges/historical-trades | Get historical trades |
TradeProfitAndLossApi | getProfitAndLossCharges | GET /v2/trade/profit-loss/charges | Get profit and loss on trades |
TradeProfitAndLossApi | getTradeWiseProfitAndLossData | GET /v2/trade/profit-loss/data | Get Trade-wise Profit and Loss Report Data |
TradeProfitAndLossApi | getTradeWiseProfitAndLossMetaData | GET /v2/trade/profit-loss/metadata | Get profit and loss meta data on trades |
UserApi | getProfile | GET /v2/user/profile | Get profile |
UserApi | getUserFundMargin | GET /v2/user/get-funds-and-margin | Get User Fund And Margin |
WebsocketApi | getMarketDataFeed | GET /v2/feed/market-data-feed | Market Data Feed |
WebsocketApi | getMarketDataFeedAuthorize | GET /v2/feed/market-data-feed/authorize | Market Data Feed Authorize |
WebsocketApi | getPortfolioStreamFeed | GET /v2/feed/portfolio-stream-feed | Portfolio Stream Feed |
WebsocketApi | getPortfolioStreamFeedAuthorize | GET /v2/feed/portfolio-stream-feed/authorize | Portfolio Stream Feed Authorize |
Connecting to the WebSocket for market and portfolio updates is streamlined through two primary Feeder functions:
Both functions are designed to simplify the process of subscribing to essential data streams, ensuring users have quick and easy access to the information they need.
The `MarketDataStreamerV3` interface is designed for effortless connection to the market WebSocket, enabling users to receive instantaneous updates on various instruments. The following example demonstrates how to quickly set up and start receiving market updates for selected instrument keys:
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
Set
The `MarketDataStreamer` interface is designed for effortless connection to the market WebSocket, enabling users to receive instantaneous updates on various instruments. The following example demonstrates how to quickly set up and start receiving market updates for selected instrument keys:
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
Set
1. Subscribing to Market Data on Connection Open with MarketDataStreamerV3
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
2. Subscribing to Instruments with Delays
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
3. Subscribing and Unsubscribing to Instruments
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
4. Subscribe, Change Mode and Unsubscribe
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
5. Disable Auto-Reconnect
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
6. Modify Auto-Reconnect parameters
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
</p>
</details>
V2
1. Subscribing to Market Data on Connection Open with MarketDataStreamer
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
2. Subscribing to Instruments with Delays
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
3. Subscribing and Unsubscribing to Instruments
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
4. Subscribe, Change Mode and Unsubscribe
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
5. Disable Auto-Reconnect
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
6. Modify Auto-Reconnect parameters
```java
public class MarketFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
</p>
</details>
### PortfolioDataStreamer
Connecting to the Portfolio WebSocket for real-time order updates is straightforward with the PortfolioDataStreamer class. Below is a concise guide to get you started on receiving updates:
```java
public class PortfolioFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken(
Position and holding updates can be enabled by setting the corresponding flag to `true` in the constructor of the `PortfolioDataStreamer` class.
```java
import com.upstox.feeder.HoldingUpdate;
import com.upstox.feeder.PositionUpdate;
public class PortfolioFeederTest {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth oAuth = (OAuth) defaultClient.getAuthentication("OAUTH2");
oAuth.setAccessToken( < ACCESS_TOKEN >);
final PortfolioDataStreamer portfolioDataStreamer = new PortfolioDataStreamer(defaultClient, true, true, true);
portfolioDataStreamer.setOnOrderUpdateListener(new OnOrderUpdateListener() {
@Override
public void onUpdate(OrderUpdate orderUpdate) {
System.out.println(orderUpdate);
}
});
portfolioDataStreamer.setOnHoldingUpdateListener(new OnHoldingUpdateListener() {
@Override
public void onUpdate(HoldingUpdate holdingUpdate) {
System.out.println(holdingUpdate);
}
});
portfolioDataStreamer.setOnPositionUpdateListener(new OnPositionUpdateListener() {
@Override
public void onUpdate(PositionUpdate positionUpdate) {
System.out.println(positionUpdate);
}
});
portfolioDataStreamer.connect();
}
}
```
This example demonstrates initializing the PortfolioDataStreamer, connecting it to the WebSocket, and setting up an event listener to receive and print order updates. Replace
## Documentation for Models
- [AnalyticsData](/upstox-java/docs/AnalyticsData.html)
- [ApiGatewayErrorResponse](/upstox-java/docs/ApiGatewayErrorResponse.html)
- [BatchExecutionSummary](/upstox-java/docs/BatchExecutionSummary.html)
- [BrokerageData](/upstox-java/docs/BrokerageData.html)
- [BrokerageTaxes](/upstox-java/docs/BrokerageTaxes.html)
- [BrokerageWrapperData](/upstox-java/docs/BrokerageWrapperData.html)
- [CancelOrExitMultiOrderData](/upstox-java/docs/CancelOrExitMultiOrderData.html)
- [CancelOrExitMultiOrderResponse](/upstox-java/docs/CancelOrExitMultiOrderResponse.html)
- [CancelOrExitOrderErrorData](/upstox-java/docs/CancelOrExitOrderErrorData.html)
- [CancelOrderData](/upstox-java/docs/CancelOrderData.html)
- [CancelOrderResponse](/upstox-java/docs/CancelOrderResponse.html)
- [ConvertPositionData](/upstox-java/docs/ConvertPositionData.html)
- [ConvertPositionRequest](/upstox-java/docs/ConvertPositionRequest.html)
- [ConvertPositionResponse](/upstox-java/docs/ConvertPositionResponse.html)
- [Depth](/upstox-java/docs/Depth.html)
- [DepthMap](/upstox-java/docs/DepthMap.html)
- [DpPlan](/upstox-java/docs/DpPlan.html)
- [ExchangeTimingData](/upstox-java/docs/ExchangeTimingData.html)
- [GetBrokerageResponse](/upstox-java/docs/GetBrokerageResponse.html)
- [GetExchangeTimingResponse](/upstox-java/docs/GetExchangeTimingResponse.html)
- [GetFullMarketQuoteResponse](/upstox-java/docs/GetFullMarketQuoteResponse.html)
- [GetHistoricalCandleResponse](/upstox-java/docs/GetHistoricalCandleResponse.html)
- [GetHoldingsResponse](/upstox-java/docs/GetHoldingsResponse.html)
- [GetHolidayResponse](/upstox-java/docs/GetHolidayResponse.html)
- [GetIntraDayCandleResponse](/upstox-java/docs/GetIntraDayCandleResponse.html)
- [GetMarketQuoteLastTradedPriceResponse](/upstox-java/docs/GetMarketQuoteLastTradedPriceResponse.html)
- [GetMarketQuoteOHLCResponse](/upstox-java/docs/GetMarketQuoteOHLCResponse.html)
- [GetMarketStatusResponse](/upstox-java/docs/GetMarketStatusResponse.html)
- [GetOptionChainResponse](/upstox-java/docs/GetOptionChainResponse.html)
- [GetOptionContractResponse](/upstox-java/docs/GetOptionContractResponse.html)
- [GetOrderBookResponse](/upstox-java/docs/GetOrderBookResponse.html)
- [GetOrderDetailsResponse](/upstox-java/docs/GetOrderDetailsResponse.html)
- [GetOrderResponse](/upstox-java/docs/GetOrderResponse.html)
- [GetPositionResponse](/upstox-java/docs/GetPositionResponse.html)
- [GetProfileResponse](/upstox-java/docs/GetProfileResponse.html)
- [GetProfitAndLossChargesResponse](/upstox-java/docs/GetProfitAndLossChargesResponse.html)
- [GetTradeResponse](/upstox-java/docs/GetTradeResponse.html)
- [GetTradeWiseProfitAndLossDataResponse](/upstox-java/docs/GetTradeWiseProfitAndLossDataResponse.html)
- [GetTradeWiseProfitAndLossMetaDataResponse](/upstox-java/docs/GetTradeWiseProfitAndLossMetaDataResponse.html)
- [GetUserFundMarginResponse](/upstox-java/docs/GetUserFundMarginResponse.html)
- [HistoricalCandleData](/upstox-java/docs/HistoricalCandleData.html)
- [HoldingsData](/upstox-java/docs/HoldingsData.html)
- [HolidayData](/upstox-java/docs/HolidayData.html)
- [Instrument](/upstox-java/docs/Instrument.html)
- [InstrumentData](/upstox-java/docs/InstrumentData.html)
- [IntraDayCandleData](/upstox-java/docs/IntraDayCandleData.html)
- [LogoutResponse](/upstox-java/docs/LogoutResponse.html)
- [Margin](/upstox-java/docs/Margin.html)
- [MarginData](/upstox-java/docs/MarginData.html)
- [MarginRequest](/upstox-java/docs/MarginRequest.html)
- [MarketData](/upstox-java/docs/MarketData.html)
- [MarketQuoteOHLC](/upstox-java/docs/MarketQuoteOHLC.html)
- [MarketQuoteSymbol](/upstox-java/docs/MarketQuoteSymbol.html)
- [MarketQuoteSymbolLtp](/upstox-java/docs/MarketQuoteSymbolLtp.html)
- [MarketStatusData](/upstox-java/docs/MarketStatusData.html)
- [ModifyOrderData](/upstox-java/docs/ModifyOrderData.html)
- [ModifyOrderRequest](/upstox-java/docs/ModifyOrderRequest.html)
- [ModifyOrderResponse](/upstox-java/docs/ModifyOrderResponse.html)
- [MultiOrderData](/upstox-java/docs/MultiOrderData.html)
- [MultiOrderError](/upstox-java/docs/MultiOrderError.html)
- [MultiOrderRequest](/upstox-java/docs/MultiOrderRequest.html)
- [MultiOrderResponse](/upstox-java/docs/MultiOrderResponse.html)
- [MultiOrderSummary](/upstox-java/docs/MultiOrderSummary.html)
- [OAuthClientException](/upstox-java/docs/OAuthClientException.html)
- [OAuthClientExceptionCause](/upstox-java/docs/OAuthClientExceptionCause.html)
- [OAuthClientExceptionCauseStackTrace](/upstox-java/docs/OAuthClientExceptionCauseStackTrace.html)
- [OAuthClientExceptionCauseSuppressed](/upstox-java/docs/OAuthClientExceptionCauseSuppressed.html)
- [Ohlc](/upstox-java/docs/Ohlc.html)
- [OptionStrikeData](/upstox-java/docs/OptionStrikeData.html)
- [OrderBookData](/upstox-java/docs/OrderBookData.html)
- [OrderData](/upstox-java/docs/OrderData.html)
- [OtherTaxes](/upstox-java/docs/OtherTaxes.html)
- [PlaceOrderData](/upstox-java/docs/PlaceOrderData.html)
- [PlaceOrderRequest](/upstox-java/docs/PlaceOrderRequest.html)
- [PlaceOrderResponse](/upstox-java/docs/PlaceOrderResponse.html)
- [PositionData](/upstox-java/docs/PositionData.html)
- [PostMarginResponse](/upstox-java/docs/PostMarginResponse.html)
- [Problem](/upstox-java/docs/Problem.html)
- [ProfileData](/upstox-java/docs/ProfileData.html)
- [ProfitAndLossChargesData](/upstox-java/docs/ProfitAndLossChargesData.html)
- [ProfitAndLossChargesTaxes](/upstox-java/docs/ProfitAndLossChargesTaxes.html)
- [ProfitAndLossChargesWrapperData](/upstox-java/docs/ProfitAndLossChargesWrapperData.html)
- [ProfitAndLossMetaData](/upstox-java/docs/ProfitAndLossMetaData.html)
- [ProfitAndLossMetaDataWrapper](/upstox-java/docs/ProfitAndLossMetaDataWrapper.html)
- [ProfitAndLossOtherChargesTaxes](/upstox-java/docs/ProfitAndLossOtherChargesTaxes.html)
- [PutCallOptionChainData](/upstox-java/docs/PutCallOptionChainData.html)
- [TokenRequest](/upstox-java/docs/TokenRequest.html)
- [TokenResponse](/upstox-java/docs/TokenResponse.html)
- [TradeData](/upstox-java/docs/TradeData.html)
- [TradeHistoryResponse](/upstox-java/docs/TradeHistoryResponse.html)
- [TradeHistoryResponseMetaData](/upstox-java/docs/TradeHistoryResponseMetaData.html)
- [TradeHistoryResponsePageData](/upstox-java/docs/TradeHistoryResponsePageData.html)
- [TradeHistoryResponseTradeData](/upstox-java/docs/TradeHistoryResponseTradeData.html)
- [TradeWiseMetaData](/upstox-java/docs/TradeWiseMetaData.html)
- [TradeWiseProfitAndLossData](/upstox-java/docs/TradeWiseProfitAndLossData.html)
- [UserFundMarginData](/upstox-java/docs/UserFundMarginData.html)
- [WebsocketAuthRedirectResponse](/upstox-java/docs/WebsocketAuthRedirectResponse.html)
- [WebsocketAuthRedirectResponseData](/upstox-java/docs/WebsocketAuthRedirectResponseData.html)
## Recommendation
It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.