Skip to content

Latest commit

 

History

History
397 lines (289 loc) · 12.1 KB

OrderApi.md

File metadata and controls

397 lines (289 loc) · 12.1 KB

OrderApi

All URIs are relative to https://api-v2.upstox.com

Method HTTP request Description
cancelOrder DELETE /order/cancel Cancel order
getOrderBook GET /order/retrieve-all Get order book
getOrderDetails GET /order/history Get order details
getTradeHistory GET /order/trades/get-trades-for-day Get trades
getTradesByOrder GET /order/trades Get trades for order
modifyOrder PUT /order/modify Modify order
placeOrder POST /order/place Place order

cancelOrder

CancelOrderResponse cancelOrder(orderId, apiVersion)

Cancel order

Cancel order API can be used for two purposes: Cancelling an open order which could be an AMO or a normal order It is also used to EXIT a CO or OCO(bracket order)

Example

// Import classes:
//import com.upstox.ApiClient;
//import com.upstox.ApiException;
//import com.upstox.Configuration;
//import com.upstox.auth.*;
//import io.swagger.client.api.OrderApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: OAUTH2
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("YOUR ACCESS TOKEN");

OrderApi apiInstance = new OrderApi();
String orderId = "orderId_example"; // String | The order ID for which the order must be cancelled
String apiVersion = "apiVersion_example"; // String | API Version Header
try {
    CancelOrderResponse result = apiInstance.cancelOrder(orderId, apiVersion);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling OrderApi#cancelOrder");
    e.printStackTrace();
}

Parameters

Name Type Description Notes
orderId String The order ID for which the order must be cancelled
apiVersion String API Version Header

Return type

CancelOrderResponse

Authorization

OAUTH2

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json, /

getOrderBook

GetOrderBookResponse getOrderBook(apiVersion)

Get order book

This API provides the list of orders placed by the user. The orders placed by the user is transient for a day and is cleared by the end of the trading session. This API returns all states of the orders, namely, open, pending, and filled ones.

Example

// Import classes:
//import com.upstox.ApiClient;
//import com.upstox.ApiException;
//import com.upstox.Configuration;
//import com.upstox.auth.*;
//import io.swagger.client.api.OrderApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: OAUTH2
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("YOUR ACCESS TOKEN");

OrderApi apiInstance = new OrderApi();
String apiVersion = "apiVersion_example"; // String | API Version Header
try {
    GetOrderBookResponse result = apiInstance.getOrderBook(apiVersion);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling OrderApi#getOrderBook");
    e.printStackTrace();
}

Parameters

Name Type Description Notes
apiVersion String API Version Header

Return type

GetOrderBookResponse

Authorization

OAUTH2

HTTP request headers

  • Content-Type: Not defined
  • Accept: /, application/json

getOrderDetails

GetOrderResponse getOrderDetails(apiVersion, orderId, tag)

Get order details

This API provides the details of the particular order the user has placed. The orders placed by the user is transient for a day and are cleared by the end of the trading session. This API returns all states of the orders, namely, open, pending, and filled ones. The order history can be requested either using order_id or tag. If both the options are passed, the history of the order which precisely matches both the order_id and tag will be returned in the response. If only the tag is passed, the history of all the associated orders which matches the tag will be shared in the response.

Example

// Import classes:
//import com.upstox.ApiClient;
//import com.upstox.ApiException;
//import com.upstox.Configuration;
//import com.upstox.auth.*;
//import io.swagger.client.api.OrderApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: OAUTH2
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("YOUR ACCESS TOKEN");

OrderApi apiInstance = new OrderApi();
String apiVersion = "apiVersion_example"; // String | API Version Header
String orderId = "orderId_example"; // String | The order reference ID for which the order history is required
String tag = "tag_example"; // String | The unique tag of the order for which the order history is being requested
try {
    GetOrderResponse result = apiInstance.getOrderDetails(apiVersion, orderId, tag);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling OrderApi#getOrderDetails");
    e.printStackTrace();
}

Parameters

Name Type Description Notes
apiVersion String API Version Header
orderId String The order reference ID for which the order history is required [optional]
tag String The unique tag of the order for which the order history is being requested [optional]

Return type

GetOrderResponse

Authorization

OAUTH2

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json, /

getTradeHistory

GetTradeResponse getTradeHistory(apiVersion)

Get trades

Retrieve the trades executed for the day

Example

// Import classes:
//import com.upstox.ApiClient;
//import com.upstox.ApiException;
//import com.upstox.Configuration;
//import com.upstox.auth.*;
//import io.swagger.client.api.OrderApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: OAUTH2
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("YOUR ACCESS TOKEN");

OrderApi apiInstance = new OrderApi();
String apiVersion = "apiVersion_example"; // String | API Version Header
try {
    GetTradeResponse result = apiInstance.getTradeHistory(apiVersion);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling OrderApi#getTradeHistory");
    e.printStackTrace();
}

Parameters

Name Type Description Notes
apiVersion String API Version Header

Return type

GetTradeResponse

Authorization

OAUTH2

HTTP request headers

  • Content-Type: Not defined
  • Accept: /, application/json

getTradesByOrder

GetTradeResponse getTradesByOrder(orderId, apiVersion)

Get trades for order

Retrieve the trades executed for an order

Example

// Import classes:
//import com.upstox.ApiClient;
//import com.upstox.ApiException;
//import com.upstox.Configuration;
//import com.upstox.auth.*;
//import io.swagger.client.api.OrderApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: OAUTH2
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("YOUR ACCESS TOKEN");

OrderApi apiInstance = new OrderApi();
String orderId = "orderId_example"; // String | The order ID for which the order to get order trades
String apiVersion = "apiVersion_example"; // String | API Version Header
try {
    GetTradeResponse result = apiInstance.getTradesByOrder(orderId, apiVersion);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling OrderApi#getTradesByOrder");
    e.printStackTrace();
}

Parameters

Name Type Description Notes
orderId String The order ID for which the order to get order trades
apiVersion String API Version Header

Return type

GetTradeResponse

Authorization

OAUTH2

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json, /

modifyOrder

ModifyOrderResponse modifyOrder(body, apiVersion)

Modify order

This API allows you to modify an order. For modification orderId is mandatory. With orderId you need to send the optional parameter which needs to be modified. In case the optional parameters aren't sent, the default will be considered from the original order

Example

// Import classes:
//import com.upstox.ApiClient;
//import com.upstox.ApiException;
//import com.upstox.Configuration;
//import com.upstox.auth.*;
//import io.swagger.client.api.OrderApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: OAUTH2
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("YOUR ACCESS TOKEN");

OrderApi apiInstance = new OrderApi();
ModifyOrderRequest body = new ModifyOrderRequest(); // ModifyOrderRequest | 
String apiVersion = "apiVersion_example"; // String | API Version Header
try {
    ModifyOrderResponse result = apiInstance.modifyOrder(body, apiVersion);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling OrderApi#modifyOrder");
    e.printStackTrace();
}

Parameters

Name Type Description Notes
body ModifyOrderRequest
apiVersion String API Version Header

Return type

ModifyOrderResponse

Authorization

OAUTH2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json, /

placeOrder

PlaceOrderResponse placeOrder(body, apiVersion)

Place order

This API allows you to place an order to the exchange via Upstox.

Example

// Import classes:
//import com.upstox.ApiClient;
//import com.upstox.ApiException;
//import com.upstox.Configuration;
//import com.upstox.auth.*;
//import io.swagger.client.api.OrderApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: OAUTH2
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("YOUR ACCESS TOKEN");

OrderApi apiInstance = new OrderApi();
PlaceOrderRequest body = new PlaceOrderRequest(); // PlaceOrderRequest | 
String apiVersion = "apiVersion_example"; // String | API Version Header
try {
    PlaceOrderResponse result = apiInstance.placeOrder(body, apiVersion);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling OrderApi#placeOrder");
    e.printStackTrace();
}

Parameters

Name Type Description Notes
body PlaceOrderRequest
apiVersion String API Version Header

Return type

PlaceOrderResponse

Authorization

OAUTH2

HTTP request headers

  • Content-Type: application/json
  • Accept: /, application/json