Skip to content

Commit ff88409

Browse files
authored
Merge pull request #81 from upstox/multi-order-apis
Add new multi orders apis and SDK headers
2 parents cd141a7 + 7fc66c6 commit ff88409

39 files changed

+3010
-4
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The official Python client for communicating with the <a href="https://upstox.co
99
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.
1010

1111
- API version: v2
12-
- Package version: 2.7.0
12+
- Package version: 2.8.0
1313
- Build package: io.swagger.codegen.v3.generators.python.PythonClientCodegen
1414

1515
This Python package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project.
@@ -81,13 +81,16 @@ Class | Method | HTTP request | Description
8181
*MarketQuoteApi* | [**ltp**](docs/MarketQuoteApi.md#ltp) | **GET** /v2/market-quote/ltp | Market quotes and instruments - LTP quotes.
8282
*OptionsApi* | [**get_option_contracts**](docs/OptionsApi.md#get_option_contracts) | **GET** /v2/option/contract | Get option contracts
8383
*OptionsApi* | [**get_put_call_option_chain**](docs/OptionsApi.md#get_put_call_option_chain) | **GET** /v2/option/chain | Get option chain
84+
*OrderApi* | [**cancel_multi_order**](docs/OrderApi.md#cancel_multi_order) | **DELETE** /v2/order/multi/cancel | Cancel multi order
8485
*OrderApi* | [**cancel_order**](docs/OrderApi.md#cancel_order) | **DELETE** /v2/order/cancel | Cancel order
86+
*OrderApi* | [**exit_positions**](docs/OrderApi.md#exit_positions) | **POST** /v2/order/positions/exit | Exit all positions
8587
*OrderApi* | [**get_order_book**](docs/OrderApi.md#get_order_book) | **GET** /v2/order/retrieve-all | Get order book
8688
*OrderApi* | [**get_order_details**](docs/OrderApi.md#get_order_details) | **GET** /v2/order/history | Get order history
8789
*OrderApi* | [**get_order_status**](docs/OrderApi.md#get_order_status) | **GET** /v2/order/details | Get order details
8890
*OrderApi* | [**get_trade_history**](docs/OrderApi.md#get_trade_history) | **GET** /v2/order/trades/get-trades-for-day | Get trades
8991
*OrderApi* | [**get_trades_by_order**](docs/OrderApi.md#get_trades_by_order) | **GET** /v2/order/trades | Get trades for order
9092
*OrderApi* | [**modify_order**](docs/OrderApi.md#modify_order) | **PUT** /v2/order/modify | Modify order
93+
*OrderApi* | [**place_multi_order**](docs/OrderApi.md#place_multi_order) | **POST** /v2/order/multi/place | Place multi order
9194
*OrderApi* | [**place_order**](docs/OrderApi.md#place_order) | **POST** /v2/order/place | Place order
9295
*PortfolioApi* | [**convert_positions**](docs/PortfolioApi.md#convert_positions) | **PUT** /v2/portfolio/convert-position | Convert Positions
9396
*PortfolioApi* | [**get_holdings**](docs/PortfolioApi.md#get_holdings) | **GET** /v2/portfolio/long-term-holdings | Get Holdings
@@ -470,9 +473,13 @@ This example demonstrates initializing the PortfolioDataStreamer, connecting it
470473

471474
- [AnalyticsData](docs/AnalyticsData.md)
472475
- [ApiGatewayErrorResponse](docs/ApiGatewayErrorResponse.md)
476+
- [BatchExecutionSummary](docs/BatchExecutionSummary.md)
473477
- [BrokerageData](docs/BrokerageData.md)
474478
- [BrokerageTaxes](docs/BrokerageTaxes.md)
475479
- [BrokerageWrapperData](docs/BrokerageWrapperData.md)
480+
- [CancelOrExitMultiOrderData](docs/CancelOrExitMultiOrderData.md)
481+
- [CancelOrExitMultiOrderResponse](docs/CancelOrExitMultiOrderResponse.md)
482+
- [CancelOrExitOrderErrorData](docs/CancelOrExitOrderErrorData.md)
476483
- [CancelOrderData](docs/CancelOrderData.md)
477484
- [CancelOrderResponse](docs/CancelOrderResponse.md)
478485
- [ConvertPositionData](docs/ConvertPositionData.md)
@@ -522,6 +529,11 @@ This example demonstrates initializing the PortfolioDataStreamer, connecting it
522529
- [ModifyOrderData](docs/ModifyOrderData.md)
523530
- [ModifyOrderRequest](docs/ModifyOrderRequest.md)
524531
- [ModifyOrderResponse](docs/ModifyOrderResponse.md)
532+
- [MultiOrderData](docs/MultiOrderData.md)
533+
- [MultiOrderError](docs/MultiOrderError.md)
534+
- [MultiOrderRequest](docs/MultiOrderRequest.md)
535+
- [MultiOrderResponse](docs/MultiOrderResponse.md)
536+
- [MultiOrderSummary](docs/MultiOrderSummary.md)
525537
- [OAuthClientException](docs/OAuthClientException.md)
526538
- [OAuthClientExceptionCause](docs/OAuthClientExceptionCause.md)
527539
- [OAuthClientExceptionCauseStackTrace](docs/OAuthClientExceptionCauseStackTrace.md)

docs/BatchExecutionSummary.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# BatchExecutionSummary
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**total** | **int** | The total number of order lines present in the payload. | [optional]
7+
**success** | **int** | The number of order lines that were successfully placed without any errors. | [optional]
8+
**error** | **int** | The number of order lines that encountered errors during processing, despite their payloads being valid. | [optional]
9+
10+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
11+

docs/CancelOrExitMultiOrderData.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CancelOrExitMultiOrderData
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**order_ids** | **list[str]** | Reference order IDs | [optional]
7+
8+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
9+
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# CancelOrExitMultiOrderResponse
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**status** | **str** | | [optional]
7+
**data** | [**CancelOrExitMultiOrderData**](CancelOrExitMultiOrderData.md) | | [optional]
8+
**errors** | [**list[CancelOrExitOrderErrorData]**](CancelOrExitOrderErrorData.md) | Error data for cancel or exit order request | [optional]
9+
**summary** | [**BatchExecutionSummary**](BatchExecutionSummary.md) | | [optional]
10+
11+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
12+

docs/CancelOrExitOrderErrorData.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# CancelOrExitOrderErrorData
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**error_code** | **str** | Unique code for the error state | [optional]
7+
**message** | **str** | Verbose message for the error state | [optional]
8+
**property_path** | **str** | Path to property failing validation | [optional]
9+
**invalid_value** | **object** | Invalid value for the property failing validation | [optional]
10+
**error_code** | **str** | | [optional]
11+
**property_path** | **str** | | [optional]
12+
**invalid_value** | **object** | | [optional]
13+
**instrument_key** | **str** | Key of instrument | [optional]
14+
**order_id** | **str** | Reference order ID | [optional]
15+
16+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
17+

docs/MultiOrderData.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# MultiOrderData
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**correlation_id** | **str** | A unique identifier for tracking individual orders within the batch | [optional]
7+
**order_id** | **str** | An order ID for the order request placed | [optional]
8+
9+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
10+

docs/MultiOrderError.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# MultiOrderError
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**error_code** | **str** | Unique code for the error state | [optional]
7+
**message** | **str** | Verbose message for the error state | [optional]
8+
**property_path** | **str** | Path to property failing validation | [optional]
9+
**invalid_value** | **object** | Invalid value for the property failing validation | [optional]
10+
**error_code** | **str** | | [optional]
11+
**property_path** | **str** | | [optional]
12+
**invalid_value** | **object** | | [optional]
13+
**correlation_id** | **str** | A unique identifier for tracking individual orders within the batch | [optional]
14+
15+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
16+

docs/MultiOrderRequest.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MultiOrderRequest
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**quantity** | **int** | Quantity with which the order is to be placed |
7+
**product** | **str** | Signifies if the order was either Intraday, Delivery, CO or OCO |
8+
**validity** | **str** | It can be one of the following - DAY(default), IOC |
9+
**price** | **float** | Price at which the order will be placed |
10+
**tag** | **str** | | [optional]
11+
**slice** | **bool** | To divide the order line based on predefined exchange definitions |
12+
**instrument_token** | **str** | Key of the instrument |
13+
**order_type** | **str** | Type of order. It can be one of the following MARKET refers to market order LIMIT refers to Limit Order SL refers to Stop Loss Limit SL-M refers to Stop Loss Market |
14+
**transaction_type** | **str** | Indicates whether its a buy or sell order |
15+
**disclosed_quantity** | **int** | The quantity that should be disclosed in the market depth |
16+
**trigger_price** | **float** | If the order is a stop loss order then the trigger price to be set is mentioned here |
17+
**is_amo** | **bool** | Signifies if the order is an After Market Order |
18+
**correlation_id** | **str** | A unique identifier for tracking individual orders within the batch |
19+
20+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
21+

docs/MultiOrderResponse.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# MultiOrderResponse
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**status** | **str** | | [optional]
7+
**data** | [**list[MultiOrderData]**](MultiOrderData.md) | Response data for multi order request | [optional]
8+
**errors** | [**list[MultiOrderError]**](MultiOrderError.md) | Error details for multi order request | [optional]
9+
**summary** | [**MultiOrderSummary**](MultiOrderSummary.md) | | [optional]
10+
11+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
12+

docs/MultiOrderSummary.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# MultiOrderSummary
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**total** | **int** | The total number of order lines present in the payload. | [optional]
7+
**success** | **int** | The number of order lines that were successfully placed without any errors. | [optional]
8+
**error** | **int** | The number of order lines that encountered errors during processing, despite their payloads being valid. | [optional]
9+
**payload_error** | **int** | The number of order lines with payload errors, indicating formatting or data validity issues.&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Note&lt;/b&gt;: Orders are processed only if the entire batch is free of payload_error, ensuring error-free transactions. | [optional]
10+
11+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
12+

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
long_description = (this_directory / "README.md").read_text()
1919

2020
NAME = "upstox-python-sdk"
21-
VERSION = "2.7.0"
21+
VERSION = "2.8.0"
2222
# To install the library, run the following
2323
#
2424
# python setup.py install

test/sdk_tests/cancel_all.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import upstox_client
2+
import data_token
3+
from upstox_client.rest import ApiException
4+
5+
configuration = upstox_client.Configuration()
6+
configuration.access_token = data_token.access_token
7+
api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
8+
9+
param = {
10+
'tag': "kg_python_sdk1"
11+
}
12+
13+
try:
14+
api_response = api_instance.cancel_multi_order(**param)
15+
print(api_response)
16+
except ApiException as e:
17+
print("Exception when calling OrderApi->place_order: %s\n" % e.body)

test/sdk_tests/exit_all.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import upstox_client
2+
import data_token
3+
from upstox_client.rest import ApiException
4+
5+
configuration = upstox_client.Configuration()
6+
configuration.access_token = data_token.access_token
7+
api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
8+
9+
param = {
10+
'tag': "kg_python_sdk"
11+
}
12+
13+
14+
try:
15+
api_response = api_instance.exit_positions(**param)
16+
print(api_response)
17+
except ApiException as e:
18+
print("Exception when calling OrderApi->place_order: %s\n" % e.body)

test/sdk_tests/market_basic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
configuration = upstox_client.Configuration()
55
configuration.access_token = data_token.access_token
66
streamer = upstox_client.MarketDataStreamer(
7-
upstox_client.ApiClient(configuration), instrumentKeys=["MCX_FO|426302", "NSE_EQ|INE528G01035"], mode="full")
7+
upstox_client.ApiClient(configuration), instrumentKeys=["NSE_EQ|INE528G01035"], mode="full")
88

99
streamer.auto_reconnect(True, 5, 10)
1010

test/sdk_tests/place_multi_order.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import upstox_client
2+
import data_token
3+
from upstox_client.rest import ApiException
4+
5+
configuration = upstox_client.Configuration()
6+
configuration.access_token = data_token.access_token
7+
api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
8+
body = [
9+
upstox_client.MultiOrderRequest(1, "I", "DAY", 0, "kg_python_sdk", False, "NSE_EQ|INE669E01016", "MARKET", "BUY",
10+
0, 0, True, "1"),
11+
upstox_client.MultiOrderRequest(1, "D", "DAY", 8.9, "kg_python_sdk1", False, "NSE_EQ|INE669E01016", "LIMIT", "BUY",
12+
0, 0, True, "2")
13+
]
14+
15+
try:
16+
api_response = api_instance.place_multi_order(body)
17+
print(api_response)
18+
except ApiException as e:
19+
print("Exception when calling OrderApi->place_order: %s\n" % e.body)

test/sdk_tests/place_order.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
configuration = upstox_client.Configuration()
66
configuration.access_token = data_token.access_token
77
api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
8-
body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 0.0, "string", "NSE_EQ|INE669E01016", "MARKET", "BUY", 0, 0.0, False)
8+
body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 0.0, "string", "NSE_EQ|INE669E01016", "MARKET", "BUY", 0, 0.0, True)
99
api_version = '2.0'
1010
try:
1111
api_response = api_instance.place_order(body, api_version)

test/sdk_tests/sanity.py

+35
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,44 @@ def is_within_market_hours():
102102
#order details
103103
order_id = '240925010636040'
104104

105+
param = {
106+
'tag': "sdk_python_tag"
107+
}
108+
109+
try:
110+
api_response = api_instance.cancel_multi_order(**param)
111+
except ApiException as e:
112+
json_string = e.body.decode('utf-8')
113+
data_dict = json.loads(json_string)
114+
if data_dict.get('errors')[0].get('errorCode') != "UDAPI1109":
115+
print("cancel multi giving wrong response")
116+
117+
try:
118+
api_response = api_instance.exit_positions(**param)
119+
except ApiException as e:
120+
json_string = e.body.decode('utf-8')
121+
data_dict = json.loads(json_string)
122+
if data_dict.get('errors')[0].get('errorCode') != "UDAPI1111" and data_dict.get('errors')[0].get('errorCode') != "UDAPI1113":
123+
print("exit position giving wrong response")
124+
125+
body = [
126+
upstox_client.MultiOrderRequest(1, "I", "DAY", 0, "kg_python_sdk", False, "NSE_EQ|INE669E01016", "MARKET", "BUY",
127+
0, 0, True, "1"),
128+
upstox_client.MultiOrderRequest(1, "D", "DAY", 8.9, "kg_python_sdk1", False, "NSE_EQ|INE669E01016", "LIMIT", "BUY",
129+
0, 0, True, "2")
130+
]
131+
132+
try:
133+
api_response = api_instance.place_multi_order(body)
134+
print(api_response)
135+
except ApiException as e:
136+
print("Exception when calling OrderApi->place_order: %s\n" % e.body)
137+
138+
105139
try:
106140
api_response = api_instance.get_order_status(order_id=order_id)
107141
print(api_response)
142+
108143
except ApiException as e:
109144
json_string = e.body.decode('utf-8')
110145
data_dict = json.loads(json_string)

test/test_batch_execution_summary.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# coding: utf-8
2+
3+
"""
4+
OpenAPI definition
5+
6+
No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501
7+
8+
OpenAPI spec version: v0
9+
10+
Generated by: https://github.com/swagger-api/swagger-codegen.git
11+
"""
12+
13+
from __future__ import absolute_import
14+
15+
import unittest
16+
17+
import swagger_client
18+
from swagger_client.models.batch_execution_summary import BatchExecutionSummary # noqa: E501
19+
from swagger_client.rest import ApiException
20+
21+
22+
class TestBatchExecutionSummary(unittest.TestCase):
23+
"""BatchExecutionSummary unit test stubs"""
24+
25+
def setUp(self):
26+
pass
27+
28+
def tearDown(self):
29+
pass
30+
31+
def testBatchExecutionSummary(self):
32+
"""Test BatchExecutionSummary"""
33+
# FIXME: construct object with mandatory attributes with example values
34+
# model = swagger_client.models.batch_execution_summary.BatchExecutionSummary() # noqa: E501
35+
pass
36+
37+
38+
if __name__ == '__main__':
39+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# coding: utf-8
2+
3+
"""
4+
OpenAPI definition
5+
6+
No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501
7+
8+
OpenAPI spec version: v0
9+
10+
Generated by: https://github.com/swagger-api/swagger-codegen.git
11+
"""
12+
13+
from __future__ import absolute_import
14+
15+
import unittest
16+
17+
import swagger_client
18+
from swagger_client.models.cancel_or_exit_multi_order_data import CancelOrExitMultiOrderData # noqa: E501
19+
from swagger_client.rest import ApiException
20+
21+
22+
class TestCancelOrExitMultiOrderData(unittest.TestCase):
23+
"""CancelOrExitMultiOrderData unit test stubs"""
24+
25+
def setUp(self):
26+
pass
27+
28+
def tearDown(self):
29+
pass
30+
31+
def testCancelOrExitMultiOrderData(self):
32+
"""Test CancelOrExitMultiOrderData"""
33+
# FIXME: construct object with mandatory attributes with example values
34+
# model = swagger_client.models.cancel_or_exit_multi_order_data.CancelOrExitMultiOrderData() # noqa: E501
35+
pass
36+
37+
38+
if __name__ == '__main__':
39+
unittest.main()

0 commit comments

Comments
 (0)