From f72d11136a902a20f8631cb142798c0f81ed2036 Mon Sep 17 00:00:00 2001 From: KETAN GUPTA Date: Tue, 21 Jan 2025 14:59:37 +0530 Subject: [PATCH 1/7] init commit for v3 url --- README.md | 15 +- docs/CancelOrderV3Response.md | 11 + docs/IndieUserInitTokenData.md | 10 + docs/IndieUserInitTokenResponse.md | 10 + docs/IndieUserTokenRequest.md | 9 + docs/ModifyOrderV3Response.md | 11 + docs/MultiOrderV3Data.md | 9 + docs/OrderControllerV3Api.md | 151 ++++++ docs/OrderMetadata.md | 9 + docs/PlaceOrderV3Request.md | 20 + docs/PlaceOrderV3Response.md | 11 + setup.py | 2 +- test/sdk_tests/cancel_order_v3.py | 16 + test/sdk_tests/data_token.py | 3 +- test/sdk_tests/init_token_request.py | 13 + test/sdk_tests/modify_v3.py | 16 + test/sdk_tests/place_order_v3.py | 16 + test/sdk_tests/sandbox_sanity.py | 126 +++++ test/test_cancel_order_v3_response.py | 39 ++ test/test_indie_user_init_token_data.py | 39 ++ test/test_indie_user_init_token_response.py | 39 ++ test/test_indie_user_token_request.py | 39 ++ test/test_modify_order_v3_response.py | 39 ++ test/test_multi_order_v3_data.py | 39 ++ test/test_order_controller_v_3_api.py | 51 ++ test/test_order_metadata.py | 39 ++ test/test_place_order_v3_request.py | 39 ++ test/test_place_order_v3_response.py | 39 ++ upstox_client/__init__.py | 10 + upstox_client/api/__init__.py | 1 + upstox_client/api/login_api.py | 107 +++++ upstox_client/api/order_controller_v_3_api.py | 332 +++++++++++++ upstox_client/api_client.py | 2 +- upstox_client/configuration.py | 18 +- upstox_client/models/__init__.py | 9 + .../models/cancel_order_v3_response.py | 168 +++++++ .../models/indie_user_init_token_data.py | 140 ++++++ .../models/indie_user_init_token_response.py | 142 ++++++ .../models/indie_user_token_request.py | 112 +++++ .../models/modify_order_v3_response.py | 168 +++++++ upstox_client/models/multi_order_v3_data.py | 110 +++++ upstox_client/models/order_metadata.py | 110 +++++ .../models/place_order_v3_request.py | 450 ++++++++++++++++++ .../models/place_order_v3_response.py | 168 +++++++ 44 files changed, 2895 insertions(+), 12 deletions(-) create mode 100644 docs/CancelOrderV3Response.md create mode 100644 docs/IndieUserInitTokenData.md create mode 100644 docs/IndieUserInitTokenResponse.md create mode 100644 docs/IndieUserTokenRequest.md create mode 100644 docs/ModifyOrderV3Response.md create mode 100644 docs/MultiOrderV3Data.md create mode 100644 docs/OrderControllerV3Api.md create mode 100644 docs/OrderMetadata.md create mode 100644 docs/PlaceOrderV3Request.md create mode 100644 docs/PlaceOrderV3Response.md create mode 100644 test/sdk_tests/cancel_order_v3.py create mode 100644 test/sdk_tests/init_token_request.py create mode 100644 test/sdk_tests/modify_v3.py create mode 100644 test/sdk_tests/place_order_v3.py create mode 100644 test/sdk_tests/sandbox_sanity.py create mode 100644 test/test_cancel_order_v3_response.py create mode 100644 test/test_indie_user_init_token_data.py create mode 100644 test/test_indie_user_init_token_response.py create mode 100644 test/test_indie_user_token_request.py create mode 100644 test/test_modify_order_v3_response.py create mode 100644 test/test_multi_order_v3_data.py create mode 100644 test/test_order_controller_v_3_api.py create mode 100644 test/test_order_metadata.py create mode 100644 test/test_place_order_v3_request.py create mode 100644 test/test_place_order_v3_response.py create mode 100644 upstox_client/api/order_controller_v_3_api.py create mode 100644 upstox_client/models/cancel_order_v3_response.py create mode 100644 upstox_client/models/indie_user_init_token_data.py create mode 100644 upstox_client/models/indie_user_init_token_response.py create mode 100644 upstox_client/models/indie_user_token_request.py create mode 100644 upstox_client/models/modify_order_v3_response.py create mode 100644 upstox_client/models/multi_order_v3_data.py create mode 100644 upstox_client/models/order_metadata.py create mode 100644 upstox_client/models/place_order_v3_request.py create mode 100644 upstox_client/models/place_order_v3_response.py diff --git a/README.md b/README.md index 675a605..903703c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The official Python client for communicating with the CancelOrderV3Response cancel_order(order_id, origin=origin) + + + +### Example +```python +from __future__ import print_function +import time +import upstox_client +from upstox_client.rest import ApiException +from pprint import pprint + +# create an instance of the API class +api_instance = upstox_client.OrderApiV3() +order_id = 'order_id_example' # str | +origin = 'origin_example' # str | (optional) + +try: + api_response = api_instance.cancel_order(order_id, origin=origin) + pprint(api_response) +except ApiException as e: + print("Exception when calling OrderApiV3->cancel_order: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **order_id** | **str**| | + **origin** | **str**| | [optional] + +### Return type + +[**CancelOrderV3Response**](CancelOrderV3Response.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: */* + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **modify_order** +> ModifyOrderV3Response modify_order(body, origin=origin) + + + +### Example +```python +from __future__ import print_function +import time +import upstox_client +from upstox_client.rest import ApiException +from pprint import pprint + +# create an instance of the API class +api_instance = upstox_client.OrderApiV3() +body = upstox_client.ModifyOrderRequest() # ModifyOrderRequest | +origin = 'origin_example' # str | (optional) + +try: + api_response = api_instance.modify_order(body, origin=origin) + pprint(api_response) +except ApiException as e: + print("Exception when calling OrderApiV3->modify_order: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**ModifyOrderRequest**](ModifyOrderRequest.md)| | + **origin** | **str**| | [optional] + +### Return type + +[**ModifyOrderV3Response**](ModifyOrderV3Response.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: */* + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **place_order** +> PlaceOrderV3Response place_order(body, origin=origin) + + + +### Example +```python +from __future__ import print_function +import time +import upstox_client +from upstox_client.rest import ApiException +from pprint import pprint + +# create an instance of the API class +api_instance = upstox_client.OrderApiV3() +body = upstox_client.PlaceOrderV3Request() # PlaceOrderV3Request | +origin = 'origin_example' # str | (optional) + +try: + api_response = api_instance.place_order(body, origin=origin) + pprint(api_response) +except ApiException as e: + print("Exception when calling OrderApiV3->place_order: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**PlaceOrderV3Request**](PlaceOrderV3Request.md)| | + **origin** | **str**| | [optional] + +### Return type + +[**PlaceOrderV3Response**](PlaceOrderV3Response.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: */* + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/docs/OrderMetadata.md b/docs/OrderMetadata.md new file mode 100644 index 0000000..5ebc03a --- /dev/null +++ b/docs/OrderMetadata.md @@ -0,0 +1,9 @@ +# OrderMetadata + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**latency** | **int** | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/docs/PlaceOrderV3Request.md b/docs/PlaceOrderV3Request.md new file mode 100644 index 0000000..d7d3548 --- /dev/null +++ b/docs/PlaceOrderV3Request.md @@ -0,0 +1,20 @@ +# PlaceOrderV3Request + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**quantity** | **int** | Quantity with which the order is to be placed | +**product** | **str** | Signifies if the order was either Intraday, Delivery, CO or OCO | +**validity** | **str** | It can be one of the following - DAY(default), IOC | +**price** | **float** | Price at which the order will be placed | +**tag** | **str** | | [optional] +**slice** | **bool** | | [optional] +**instrument_token** | **str** | Key of the instrument | +**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 | +**transaction_type** | **str** | Indicates whether its a buy or sell order | +**disclosed_quantity** | **int** | The quantity that should be disclosed in the market depth | +**trigger_price** | **float** | If the order is a stop loss order then the trigger price to be set is mentioned here | +**is_amo** | **bool** | Signifies if the order is an After Market Order | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/docs/PlaceOrderV3Response.md b/docs/PlaceOrderV3Response.md new file mode 100644 index 0000000..5f68cda --- /dev/null +++ b/docs/PlaceOrderV3Response.md @@ -0,0 +1,11 @@ +# PlaceOrderV3Response + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**status** | **str** | | [optional] +**data** | [**MultiOrderV3Data**](MultiOrderV3Data.md) | | [optional] +**metadata** | [**OrderMetadata**](OrderMetadata.md) | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/setup.py b/setup.py index 5710ba9..b2a9476 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ long_description = (this_directory / "README.md").read_text() NAME = "upstox-python-sdk" -VERSION = "2.10.0" +VERSION = "2.11.0" # To install the library, run the following # # python setup.py install diff --git a/test/sdk_tests/cancel_order_v3.py b/test/sdk_tests/cancel_order_v3.py new file mode 100644 index 0000000..ad75929 --- /dev/null +++ b/test/sdk_tests/cancel_order_v3.py @@ -0,0 +1,16 @@ +import upstox_client +import data_token + + +from upstox_client.rest import ApiException + +configuration = upstox_client.Configuration() +configuration.access_token = data_token.access_token + +api_instance = upstox_client.OrderApiV3(upstox_client.ApiClient(configuration)) + +try: + api_response = api_instance.cancel_order("250121010502101") + print(api_response) +except ApiException as e: + print("Exception when calling v3 cancel: %s\n" % e) \ No newline at end of file diff --git a/test/sdk_tests/data_token.py b/test/sdk_tests/data_token.py index c8954a3..4e3e510 100644 --- a/test/sdk_tests/data_token.py +++ b/test/sdk_tests/data_token.py @@ -1,5 +1,6 @@ -access_token = "" +access_token = "" +sandbox_access_token = "" sample_instrument_key = [ "NSE_EQ|INE528G01035", "NSE_EQ|INE399C01030", "BSE_EQ|INE055E01034", "NCD_FO|14245", "NSE_EQ|INE169A01031", diff --git a/test/sdk_tests/init_token_request.py b/test/sdk_tests/init_token_request.py new file mode 100644 index 0000000..2edb4de --- /dev/null +++ b/test/sdk_tests/init_token_request.py @@ -0,0 +1,13 @@ +import upstox_client + +from upstox_client.rest import ApiException + +configuration = upstox_client.Configuration() + +api_instance = upstox_client.LoginApi(upstox_client.ApiClient(configuration)) +body = upstox_client.IndieUserTokenRequest(client_secret="9rmbdmvjsb") +try: + api_response = api_instance.init_token_request_for_indie_user(body,client_id="fd330501-ac87-4ecb-b4e1-4ec994c70c32") + print(api_response) +except ApiException as e: + print("Exception when calling indie token request: %s\n" % e) \ No newline at end of file diff --git a/test/sdk_tests/modify_v3.py b/test/sdk_tests/modify_v3.py new file mode 100644 index 0000000..ed719c0 --- /dev/null +++ b/test/sdk_tests/modify_v3.py @@ -0,0 +1,16 @@ +import upstox_client +import data_token + +from upstox_client.rest import ApiException + +configuration = upstox_client.Configuration() +configuration.access_token = data_token.access_token +api_instance = upstox_client.OrderApiV3(upstox_client.ApiClient(configuration)) + +body = upstox_client.ModifyOrderRequest(1, "DAY", 9.12, "250121010502101", "LIMIT", 0, 0) + +try: + api_response = api_instance.modify_order(body) + print(api_response) +except ApiException as e: + print("Exception when calling v3 modify: %s\n" % e) \ No newline at end of file diff --git a/test/sdk_tests/place_order_v3.py b/test/sdk_tests/place_order_v3.py new file mode 100644 index 0000000..fbb79da --- /dev/null +++ b/test/sdk_tests/place_order_v3.py @@ -0,0 +1,16 @@ +import upstox_client +import data_token + +from upstox_client.rest import ApiException + +configuration = upstox_client.Configuration() +configuration.access_token = data_token.access_token +api_instance = upstox_client.OrderApiV3(upstox_client.ApiClient(configuration)) + +body = upstox_client.PlaceOrderV3Request(quantity=1, product="D",validity="DAY", price=9.12, tag="string", instrument_token="NSE_EQ|INE669E01016", order_type="LIMIT",transaction_type="BUY", disclosed_quantity=0, trigger_price=0.0, is_amo=False, slice=True) + +try: + api_response = api_instance.place_order(body) + print(api_response) +except ApiException as e: + print("Exception when calling OrderApi->place_order: %s\n" % e) \ No newline at end of file diff --git a/test/sdk_tests/sandbox_sanity.py b/test/sdk_tests/sandbox_sanity.py new file mode 100644 index 0000000..28101d1 --- /dev/null +++ b/test/sdk_tests/sandbox_sanity.py @@ -0,0 +1,126 @@ +import upstox_client +import data_token +from upstox_client.rest import ApiException +import json + + +configuration = upstox_client.Configuration(sandbox=True) +configuration.access_token = data_token.sandbox_access_token +api_version = '2.0' + + + +instruments = [ + upstox_client.Instrument(instrument_key="NSE_EQ|INE528G01035", quantity=12, product="D", transaction_type="BUY"), + upstox_client.Instrument(instrument_key="NSE_EQ|INE002A01018", quantity=1, product="D", transaction_type="BUY") +] + +api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) +body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 12.0, "string", "NSE_EQ|INE528G01035", "LIMIT", "BUY", 0, 0.0, + False) +try: + api_response = api_instance.place_order(body, api_version) + print(api_response) +except ApiException as e: + print("exception in place order: ", e) + +api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) +body = upstox_client.ModifyOrderRequest(2, "DAY", 0, "250121112512866", "MARKET", 0, 0) +api_version = '2.0' # str | API Version Header + +try: + # Modify order + api_response = api_instance.modify_order(body, api_version) +except ApiException as e: + json_string = e.body.decode('utf-8') + data_dict = json.loads(json_string) + if data_dict.get('errors')[0].get('errorCode') != "UDAPI100010": + print("modify order giving wrong response") + +# order details +order_id = '240925010636040' + +body = [ + upstox_client.MultiOrderRequest(1, "I", "DAY", 0, "kg_python_sdk", False, "NSE_EQ|INE669E01016", "MARKET", "BUY", + 0, 0, True, "1"), + upstox_client.MultiOrderRequest(1, "D", "DAY", 8.9, "kg_python_sdk1", False, "NSE_EQ|INE669E01016", "LIMIT", "BUY", + 0, 0, True, "2") +] + +try: + api_response = api_instance.place_multi_order(body) + print(api_response) +except ApiException as e: + print("Exception when calling OrderApi->place_order: %s\n" % e.body) + +try: + api_response = api_instance.get_order_status(order_id="250121112521183") +except ApiException as e: + json_string = e.body.decode('utf-8') + data_dict = json.loads(json_string) + if data_dict.get('errors')[0].get('errorCode') != "UDAPI100010": + print("order details giving wrong response") + +api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) +order_id = '2501211126016789' +api_version = '2.0' + +try: + # Cancel order + api_response = api_instance.cancel_order(order_id, api_version) +except ApiException as e: + json_string = e.body.decode('utf-8') + data_dict = json.loads(json_string) + if data_dict.get('errors')[0].get('errorCode') != "UDAPI100010": + print("cancel order giving wrong response") + +api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) +api_version = '2.0' +try: + # Get order book + api_response = api_instance.get_order_book(api_version) + if api_response.status != "success": + print("get order book giving invalid data") +except ApiException as e: + print("Exception when calling OrderApi->get_order_book: %s\n" % e) + +api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) +api_version = '2.0' +order_id = '25012112309073' + +try: + api_response = api_instance.get_order_details(api_version, order_id=order_id) +except ApiException as e: + json_string = e.body.decode('utf-8') + data_dict = json.loads(json_string) + if data_dict.get('errors')[0].get('errorCode') != "UDAPI100010": + print("get order details giving wrong response") + +api_instance = upstox_client.OrderApiV3(upstox_client.ApiClient(configuration)) +body = upstox_client.PlaceOrderV3Request(quantity=1, product="D",validity="DAY", price=9.12, tag="string", instrument_token="NSE_EQ|INE669E01016", order_type="LIMIT",transaction_type="BUY", disclosed_quantity=0, trigger_price=0.0, is_amo=True, slice=True) + +try: + api_response = api_instance.place_order(body) + print(api_response) +except ApiException as e: + print("Exception when calling OrderApi->place_order: %s\n" % e) + +body = upstox_client.ModifyOrderRequest(3, "DAY", 9.12, "250120010373947", "LIMIT", 0, 0) + +try: + api_response = api_instance.modify_order(body) +except ApiException as e: + json_string = e.body.decode('utf-8') + data_dict = json.loads(json_string) + if data_dict.get('errors')[0].get('errorCode') != "UDAPI100010": + print("modify order giving wrong response") + + +try: + # Cancel order + api_response = api_instance.cancel_order(order_id) +except ApiException as e: + json_string = e.body.decode('utf-8') + data_dict = json.loads(json_string) + if data_dict.get('errors')[0].get('errorCode') != "UDAPI100010": + print("cancel order giving wrong response") \ No newline at end of file diff --git a/test/test_cancel_order_v3_response.py b/test/test_cancel_order_v3_response.py new file mode 100644 index 0000000..cc86a23 --- /dev/null +++ b/test/test_cancel_order_v3_response.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import unittest + +import upstox_client +from upstox_client.models.cancel_order_v3_response import CancelOrderV3Response # noqa: E501 +from upstox_client.rest import ApiException + + +class TestCancelOrderV3Response(unittest.TestCase): + """CancelOrderV3Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testCancelOrderV3Response(self): + """Test CancelOrderV3Response""" + # FIXME: construct object with mandatory attributes with example values + # model = upstox_client.models.cancel_order_v3_response.CancelOrderV3Response() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_indie_user_init_token_data.py b/test/test_indie_user_init_token_data.py new file mode 100644 index 0000000..092665f --- /dev/null +++ b/test/test_indie_user_init_token_data.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import unittest + +import upstox_client +from upstox_client.models.indie_user_init_token_data import IndieUserInitTokenData # noqa: E501 +from upstox_client.rest import ApiException + + +class TestIndieUserInitTokenData(unittest.TestCase): + """IndieUserInitTokenData unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testIndieUserInitTokenData(self): + """Test IndieUserInitTokenData""" + # FIXME: construct object with mandatory attributes with example values + # model = upstox_client.models.indie_user_init_token_data.IndieUserInitTokenData() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_indie_user_init_token_response.py b/test/test_indie_user_init_token_response.py new file mode 100644 index 0000000..e0b244c --- /dev/null +++ b/test/test_indie_user_init_token_response.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import unittest + +import upstox_client +from upstox_client.models.indie_user_init_token_response import IndieUserInitTokenResponse # noqa: E501 +from upstox_client.rest import ApiException + + +class TestIndieUserInitTokenResponse(unittest.TestCase): + """IndieUserInitTokenResponse unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testIndieUserInitTokenResponse(self): + """Test IndieUserInitTokenResponse""" + # FIXME: construct object with mandatory attributes with example values + # model = upstox_client.models.indie_user_init_token_response.IndieUserInitTokenResponse() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_indie_user_token_request.py b/test/test_indie_user_token_request.py new file mode 100644 index 0000000..3df6e0b --- /dev/null +++ b/test/test_indie_user_token_request.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import unittest + +import upstox_client +from upstox_client.models.indie_user_token_request import IndieUserTokenRequest # noqa: E501 +from upstox_client.rest import ApiException + + +class TestIndieUserTokenRequest(unittest.TestCase): + """IndieUserTokenRequest unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testIndieUserTokenRequest(self): + """Test IndieUserTokenRequest""" + # FIXME: construct object with mandatory attributes with example values + # model = upstox_client.models.indie_user_token_request.IndieUserTokenRequest() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_modify_order_v3_response.py b/test/test_modify_order_v3_response.py new file mode 100644 index 0000000..d53ea29 --- /dev/null +++ b/test/test_modify_order_v3_response.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import unittest + +import upstox_client +from upstox_client.models.modify_order_v3_response import ModifyOrderV3Response # noqa: E501 +from upstox_client.rest import ApiException + + +class TestModifyOrderV3Response(unittest.TestCase): + """ModifyOrderV3Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testModifyOrderV3Response(self): + """Test ModifyOrderV3Response""" + # FIXME: construct object with mandatory attributes with example values + # model = upstox_client.models.modify_order_v3_response.ModifyOrderV3Response() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_multi_order_v3_data.py b/test/test_multi_order_v3_data.py new file mode 100644 index 0000000..c11bfd7 --- /dev/null +++ b/test/test_multi_order_v3_data.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import unittest + +import upstox_client +from upstox_client.models.multi_order_v3_data import MultiOrderV3Data # noqa: E501 +from upstox_client.rest import ApiException + + +class TestMultiOrderV3Data(unittest.TestCase): + """MultiOrderV3Data unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testMultiOrderV3Data(self): + """Test MultiOrderV3Data""" + # FIXME: construct object with mandatory attributes with example values + # model = upstox_client.models.multi_order_v3_data.MultiOrderV3Data() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_order_controller_v_3_api.py b/test/test_order_controller_v_3_api.py new file mode 100644 index 0000000..07e1fe1 --- /dev/null +++ b/test/test_order_controller_v_3_api.py @@ -0,0 +1,51 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import unittest + +import upstox_client +from upstox_client.api.order_controller_v_3_api import OrderApiV3 # noqa: E501 +from upstox_client.rest import ApiException + + +class TestOrderApiV3(unittest.TestCase): + """OrderApiV3 unit test stubs""" + + def setUp(self): + self.api = OrderApiV3() # noqa: E501 + + def tearDown(self): + pass + + def test_cancel_order(self): + """Test case for cancel_order + + """ + pass + + def test_modify_order(self): + """Test case for modify_order + + """ + pass + + def test_place_order(self): + """Test case for place_order + + """ + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_order_metadata.py b/test/test_order_metadata.py new file mode 100644 index 0000000..5e3f423 --- /dev/null +++ b/test/test_order_metadata.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import unittest + +import upstox_client +from upstox_client.models.order_metadata import OrderMetadata # noqa: E501 +from upstox_client.rest import ApiException + + +class TestOrderMetadata(unittest.TestCase): + """OrderMetadata unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testOrderMetadata(self): + """Test OrderMetadata""" + # FIXME: construct object with mandatory attributes with example values + # model = upstox_client.models.order_metadata.OrderMetadata() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_place_order_v3_request.py b/test/test_place_order_v3_request.py new file mode 100644 index 0000000..3b17a6b --- /dev/null +++ b/test/test_place_order_v3_request.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import unittest + +import upstox_client +from upstox_client.models.place_order_v3_request import PlaceOrderV3Request # noqa: E501 +from upstox_client.rest import ApiException + + +class TestPlaceOrderV3Request(unittest.TestCase): + """PlaceOrderV3Request unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testPlaceOrderV3Request(self): + """Test PlaceOrderV3Request""" + # FIXME: construct object with mandatory attributes with example values + # model = upstox_client.models.place_order_v3_request.PlaceOrderV3Request() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_place_order_v3_response.py b/test/test_place_order_v3_response.py new file mode 100644 index 0000000..16a4eab --- /dev/null +++ b/test/test_place_order_v3_response.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import unittest + +import upstox_client +from upstox_client.models.place_order_v3_response import PlaceOrderV3Response # noqa: E501 +from upstox_client.rest import ApiException + + +class TestPlaceOrderV3Response(unittest.TestCase): + """PlaceOrderV3Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testPlaceOrderV3Response(self): + """Test PlaceOrderV3Response""" + # FIXME: construct object with mandatory attributes with example values + # model = upstox_client.models.place_order_v3_response.PlaceOrderV3Response() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/upstox_client/__init__.py b/upstox_client/__init__.py index 590b8d2..3bf60cc 100644 --- a/upstox_client/__init__.py +++ b/upstox_client/__init__.py @@ -27,6 +27,7 @@ from upstox_client.api.trade_profit_and_loss_api import TradeProfitAndLossApi from upstox_client.api.user_api import UserApi from upstox_client.api.websocket_api import WebsocketApi +from upstox_client.api.order_controller_v_3_api import OrderApiV3 # import websocket interfaces into sdk package from upstox_client.feeder.market_data_streamer import MarketDataStreamer from upstox_client.feeder.market_data_streamer_v3 import MarketDataStreamerV3 @@ -46,6 +47,7 @@ from upstox_client.models.cancel_or_exit_order_error_data import CancelOrExitOrderErrorData from upstox_client.models.cancel_order_data import CancelOrderData from upstox_client.models.cancel_order_response import CancelOrderResponse +from upstox_client.models.cancel_order_v3_response import CancelOrderV3Response from upstox_client.models.convert_position_data import ConvertPositionData from upstox_client.models.convert_position_request import ConvertPositionRequest from upstox_client.models.convert_position_response import ConvertPositionResponse @@ -78,6 +80,9 @@ from upstox_client.models.historical_candle_data import HistoricalCandleData from upstox_client.models.holdings_data import HoldingsData from upstox_client.models.holiday_data import HolidayData +from upstox_client.models.indie_user_init_token_data import IndieUserInitTokenData +from upstox_client.models.indie_user_init_token_response import IndieUserInitTokenResponse +from upstox_client.models.indie_user_token_request import IndieUserTokenRequest from upstox_client.models.instrument import Instrument from upstox_client.models.instrument_data import InstrumentData from upstox_client.models.intra_day_candle_data import IntraDayCandleData @@ -93,11 +98,13 @@ from upstox_client.models.modify_order_data import ModifyOrderData from upstox_client.models.modify_order_request import ModifyOrderRequest from upstox_client.models.modify_order_response import ModifyOrderResponse +from upstox_client.models.modify_order_v3_response import ModifyOrderV3Response from upstox_client.models.multi_order_data import MultiOrderData from upstox_client.models.multi_order_error import MultiOrderError from upstox_client.models.multi_order_request import MultiOrderRequest from upstox_client.models.multi_order_response import MultiOrderResponse from upstox_client.models.multi_order_summary import MultiOrderSummary +from upstox_client.models.multi_order_v3_data import MultiOrderV3Data from upstox_client.models.o_auth_client_exception import OAuthClientException from upstox_client.models.o_auth_client_exception_cause import OAuthClientExceptionCause from upstox_client.models.o_auth_client_exception_cause_stack_trace import OAuthClientExceptionCauseStackTrace @@ -106,10 +113,13 @@ from upstox_client.models.option_strike_data import OptionStrikeData from upstox_client.models.order_book_data import OrderBookData from upstox_client.models.order_data import OrderData +from upstox_client.models.order_metadata import OrderMetadata from upstox_client.models.other_taxes import OtherTaxes from upstox_client.models.place_order_data import PlaceOrderData from upstox_client.models.place_order_request import PlaceOrderRequest from upstox_client.models.place_order_response import PlaceOrderResponse +from upstox_client.models.place_order_v3_request import PlaceOrderV3Request +from upstox_client.models.place_order_v3_response import PlaceOrderV3Response from upstox_client.models.position_data import PositionData from upstox_client.models.post_margin_response import PostMarginResponse from upstox_client.models.problem import Problem diff --git a/upstox_client/api/__init__.py b/upstox_client/api/__init__.py index ebb7cfc..43c19f5 100644 --- a/upstox_client/api/__init__.py +++ b/upstox_client/api/__init__.py @@ -12,3 +12,4 @@ from upstox_client.api.trade_profit_and_loss_api import TradeProfitAndLossApi from upstox_client.api.user_api import UserApi from upstox_client.api.websocket_api import WebsocketApi +from upstox_client.api.order_controller_v_3_api import OrderApiV3 diff --git a/upstox_client/api/login_api.py b/upstox_client/api/login_api.py index 31a01c8..41e42c4 100644 --- a/upstox_client/api/login_api.py +++ b/upstox_client/api/login_api.py @@ -151,6 +151,113 @@ def authorize_with_http_info(self, client_id, redirect_uri, api_version, **kwarg _request_timeout=params.get('_request_timeout'), collection_formats=collection_formats) + def init_token_request_for_indie_user(self, body, client_id, **kwargs): # noqa: E501 + """Init token API # noqa: E501 + + This API provides the initialize the generate token and it's expiry for an indie user # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.init_token_request_for_indie_user(body, client_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param IndieUserTokenRequest body: (required) + :param str client_id: (required) + :return: IndieUserInitTokenResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.init_token_request_for_indie_user_with_http_info(body, client_id, **kwargs) # noqa: E501 + else: + (data) = self.init_token_request_for_indie_user_with_http_info(body, client_id, **kwargs) # noqa: E501 + return data + + def init_token_request_for_indie_user_with_http_info(self, body, client_id, **kwargs): # noqa: E501 + """Init token API # noqa: E501 + + This API provides the initialize the generate token and it's expiry for an indie user # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.init_token_request_for_indie_user_with_http_info(body, client_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param IndieUserTokenRequest body: (required) + :param str client_id: (required) + :return: IndieUserInitTokenResponse + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['body', 'client_id'] # noqa: E501 + all_params.append('async_req') + all_params.append('_return_http_data_only') + all_params.append('_preload_content') + all_params.append('_request_timeout') + + params = locals() + for key, val in six.iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method init_token_request_for_indie_user" % key + ) + params[key] = val + del params['kwargs'] + # verify the required parameter 'body' is set + if ('body' not in params or + params['body'] is None): + raise ValueError("Missing the required parameter `body` when calling `init_token_request_for_indie_user`") # noqa: E501 + # verify the required parameter 'client_id' is set + if ('client_id' not in params or + params['client_id'] is None): + raise ValueError("Missing the required parameter `client_id` when calling `init_token_request_for_indie_user`") # noqa: E501 + + collection_formats = {} + + path_params = {} + if 'client_id' in params: + path_params['client_id'] = params['client_id'] # noqa: E501 + + query_params = [] + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + if 'body' in params: + body_params = params['body'] + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json', '*/*']) # noqa: E501 + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 + ['application/json']) # noqa: E501 + + # Authentication setting + auth_settings = [] # noqa: E501 + + return self.api_client.call_api( + '/v3/login/auth/token/request/{client_id}', 'POST', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='IndieUserInitTokenResponse', # noqa: E501 + auth_settings=auth_settings, + async_req=params.get('async_req'), + _return_http_data_only=params.get('_return_http_data_only'), + _preload_content=params.get('_preload_content', True), + _request_timeout=params.get('_request_timeout'), + collection_formats=collection_formats) + def logout(self, api_version, **kwargs): # noqa: E501 """Logout # noqa: E501 diff --git a/upstox_client/api/order_controller_v_3_api.py b/upstox_client/api/order_controller_v_3_api.py new file mode 100644 index 0000000..c5175c5 --- /dev/null +++ b/upstox_client/api/order_controller_v_3_api.py @@ -0,0 +1,332 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import re # noqa: F401 + +# python 2 and python 3 compatibility library +import six + +from upstox_client.api_client import ApiClient + + +class OrderApiV3(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + Ref: https://github.com/swagger-api/swagger-codegen + """ + + def __init__(self, api_client=None): + if api_client is None: + api_client = ApiClient() + self.api_client = api_client + + def cancel_order(self, order_id, **kwargs): # noqa: E501 + """cancel_order # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.cancel_order(order_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str order_id: (required) + :param str origin: + :return: CancelOrderV3Response + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.cancel_order_with_http_info(order_id, **kwargs) # noqa: E501 + else: + (data) = self.cancel_order_with_http_info(order_id, **kwargs) # noqa: E501 + return data + + def cancel_order_with_http_info(self, order_id, **kwargs): # noqa: E501 + """cancel_order # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.cancel_order_with_http_info(order_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str order_id: (required) + :param str origin: + :return: CancelOrderV3Response + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['order_id', 'origin'] # noqa: E501 + all_params.append('async_req') + all_params.append('_return_http_data_only') + all_params.append('_preload_content') + all_params.append('_request_timeout') + + params = locals() + for key, val in six.iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method cancel_order" % key + ) + params[key] = val + del params['kwargs'] + # verify the required parameter 'order_id' is set + if ('order_id' not in params or + params['order_id'] is None): + raise ValueError("Missing the required parameter `order_id` when calling `cancel_order`") # noqa: E501 + + collection_formats = {} + + path_params = {} + + query_params = [] + if 'order_id' in params: + query_params.append(('order_id', params['order_id'])) # noqa: E501 + + header_params = {} + if 'origin' in params: + header_params['Origin'] = params['origin'] # noqa: E501 + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['*/*']) # noqa: E501 + + # Authentication setting + auth_settings = ['OAUTH2'] # noqa: E501 + + return self.api_client.call_api( + '/v3/order/cancel', 'DELETE', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='CancelOrderV3Response', # noqa: E501 + auth_settings=auth_settings, + async_req=params.get('async_req'), + _return_http_data_only=params.get('_return_http_data_only'), + _preload_content=params.get('_preload_content', True), + _request_timeout=params.get('_request_timeout'), + collection_formats=collection_formats) + + def modify_order(self, body, **kwargs): # noqa: E501 + """modify_order # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.modify_order(body, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param ModifyOrderRequest body: (required) + :param str origin: + :return: ModifyOrderV3Response + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.modify_order_with_http_info(body, **kwargs) # noqa: E501 + else: + (data) = self.modify_order_with_http_info(body, **kwargs) # noqa: E501 + return data + + def modify_order_with_http_info(self, body, **kwargs): # noqa: E501 + """modify_order # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.modify_order_with_http_info(body, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param ModifyOrderRequest body: (required) + :param str origin: + :return: ModifyOrderV3Response + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['body', 'origin'] # noqa: E501 + all_params.append('async_req') + all_params.append('_return_http_data_only') + all_params.append('_preload_content') + all_params.append('_request_timeout') + + params = locals() + for key, val in six.iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method modify_order" % key + ) + params[key] = val + del params['kwargs'] + # verify the required parameter 'body' is set + if ('body' not in params or + params['body'] is None): + raise ValueError("Missing the required parameter `body` when calling `modify_order`") # noqa: E501 + + collection_formats = {} + + path_params = {} + + query_params = [] + + header_params = {} + if 'origin' in params: + header_params['Origin'] = params['origin'] # noqa: E501 + + form_params = [] + local_var_files = {} + + body_params = None + if 'body' in params: + body_params = params['body'] + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['*/*']) # noqa: E501 + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 + ['application/json']) # noqa: E501 + + # Authentication setting + auth_settings = ['OAUTH2'] # noqa: E501 + + return self.api_client.call_api( + '/v3/order/modify', 'PUT', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='ModifyOrderV3Response', # noqa: E501 + auth_settings=auth_settings, + async_req=params.get('async_req'), + _return_http_data_only=params.get('_return_http_data_only'), + _preload_content=params.get('_preload_content', True), + _request_timeout=params.get('_request_timeout'), + collection_formats=collection_formats) + + def place_order(self, body, **kwargs): # noqa: E501 + """place_order # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.place_order(body, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param PlaceOrderV3Request body: (required) + :param str origin: + :return: PlaceOrderV3Response + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.place_order_with_http_info(body, **kwargs) # noqa: E501 + else: + (data) = self.place_order_with_http_info(body, **kwargs) # noqa: E501 + return data + + def place_order_with_http_info(self, body, **kwargs): # noqa: E501 + """place_order # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.place_order_with_http_info(body, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param PlaceOrderV3Request body: (required) + :param str origin: + :return: PlaceOrderV3Response + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['body', 'origin'] # noqa: E501 + all_params.append('async_req') + all_params.append('_return_http_data_only') + all_params.append('_preload_content') + all_params.append('_request_timeout') + + params = locals() + for key, val in six.iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method place_order" % key + ) + params[key] = val + del params['kwargs'] + # verify the required parameter 'body' is set + if ('body' not in params or + params['body'] is None): + raise ValueError("Missing the required parameter `body` when calling `place_order`") # noqa: E501 + + collection_formats = {} + + path_params = {} + + query_params = [] + + header_params = {} + if 'origin' in params: + header_params['Origin'] = params['origin'] # noqa: E501 + + form_params = [] + local_var_files = {} + + body_params = None + if 'body' in params: + body_params = params['body'] + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['*/*']) # noqa: E501 + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 + ['application/json']) # noqa: E501 + + # Authentication setting + auth_settings = ['OAUTH2'] # noqa: E501 + + return self.api_client.call_api( + '/v3/order/place', 'POST', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='PlaceOrderV3Response', # noqa: E501 + auth_settings=auth_settings, + async_req=params.get('async_req'), + _return_http_data_only=params.get('_return_http_data_only'), + _preload_content=params.get('_preload_content', True), + _request_timeout=params.get('_request_timeout'), + collection_formats=collection_formats) diff --git a/upstox_client/api_client.py b/upstox_client/api_client.py index 1eb8b92..e7f5fc5 100644 --- a/upstox_client/api_client.py +++ b/upstox_client/api_client.py @@ -74,7 +74,7 @@ def __init__(self, configuration=None, header_name=None, header_value=None, # Set default User-Agent. self.user_agent = 'Swagger-Codegen/1.0.0/python' self.default_headers["X-Upstox-SDK-Language"] = "python" - self.default_headers["X-Upstox-SDK-Version"] = "2.10.0" + self.default_headers["X-Upstox-SDK-Version"] = "2.11.0" def __del__(self): try: diff --git a/upstox_client/configuration.py b/upstox_client/configuration.py index 325403d..80c53d4 100644 --- a/upstox_client/configuration.py +++ b/upstox_client/configuration.py @@ -27,15 +27,14 @@ def __init__(cls, name, bases, dct): super(TypeWithDefault, cls).__init__(name, bases, dct) cls._default = None - def __call__(cls): - if cls._default is None: - cls._default = type.__call__(cls) - return copy.copy(cls._default) + def __call__(cls, *args, **kwargs): + return type.__call__(cls, *args, **kwargs) def set_default(cls, default): cls._default = copy.copy(default) + class Configuration(six.with_metaclass(TypeWithDefault, object)): """NOTE: This class is auto generated by the swagger code generator program. @@ -43,13 +42,16 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): Do not edit the class manually. """ - def __init__(self): + def __init__(self, sandbox=False): """Constructor""" # Default Base url - self.host = "https://api.upstox.com" + if sandbox: + self.host = "https://api-sandbox.upstox.com" + self.order_host = "https://api-sandbox.upstox.com" + else: + self.host = "https://api.upstox.com" + self.order_host = "https://api-hft.upstox.com" - # Low latency order host - self.order_host = "https://api-hft.upstox.com" # Temp file folder for downloading files self.temp_folder_path = None diff --git a/upstox_client/models/__init__.py b/upstox_client/models/__init__.py index 850900d..3f8934d 100644 --- a/upstox_client/models/__init__.py +++ b/upstox_client/models/__init__.py @@ -25,6 +25,7 @@ from upstox_client.models.cancel_or_exit_order_error_data import CancelOrExitOrderErrorData from upstox_client.models.cancel_order_data import CancelOrderData from upstox_client.models.cancel_order_response import CancelOrderResponse +from upstox_client.models.cancel_order_v3_response import CancelOrderV3Response from upstox_client.models.convert_position_data import ConvertPositionData from upstox_client.models.convert_position_request import ConvertPositionRequest from upstox_client.models.convert_position_response import ConvertPositionResponse @@ -57,6 +58,9 @@ from upstox_client.models.historical_candle_data import HistoricalCandleData from upstox_client.models.holdings_data import HoldingsData from upstox_client.models.holiday_data import HolidayData +from upstox_client.models.indie_user_init_token_data import IndieUserInitTokenData +from upstox_client.models.indie_user_init_token_response import IndieUserInitTokenResponse +from upstox_client.models.indie_user_token_request import IndieUserTokenRequest from upstox_client.models.instrument import Instrument from upstox_client.models.instrument_data import InstrumentData from upstox_client.models.intra_day_candle_data import IntraDayCandleData @@ -72,11 +76,13 @@ from upstox_client.models.modify_order_data import ModifyOrderData from upstox_client.models.modify_order_request import ModifyOrderRequest from upstox_client.models.modify_order_response import ModifyOrderResponse +from upstox_client.models.modify_order_v3_response import ModifyOrderV3Response from upstox_client.models.multi_order_data import MultiOrderData from upstox_client.models.multi_order_error import MultiOrderError from upstox_client.models.multi_order_request import MultiOrderRequest from upstox_client.models.multi_order_response import MultiOrderResponse from upstox_client.models.multi_order_summary import MultiOrderSummary +from upstox_client.models.multi_order_v3_data import MultiOrderV3Data from upstox_client.models.o_auth_client_exception import OAuthClientException from upstox_client.models.o_auth_client_exception_cause import OAuthClientExceptionCause from upstox_client.models.o_auth_client_exception_cause_stack_trace import OAuthClientExceptionCauseStackTrace @@ -85,10 +91,13 @@ from upstox_client.models.option_strike_data import OptionStrikeData from upstox_client.models.order_book_data import OrderBookData from upstox_client.models.order_data import OrderData +from upstox_client.models.order_metadata import OrderMetadata from upstox_client.models.other_taxes import OtherTaxes from upstox_client.models.place_order_data import PlaceOrderData from upstox_client.models.place_order_request import PlaceOrderRequest from upstox_client.models.place_order_response import PlaceOrderResponse +from upstox_client.models.place_order_v3_request import PlaceOrderV3Request +from upstox_client.models.place_order_v3_response import PlaceOrderV3Response from upstox_client.models.position_data import PositionData from upstox_client.models.post_margin_response import PostMarginResponse from upstox_client.models.problem import Problem diff --git a/upstox_client/models/cancel_order_v3_response.py b/upstox_client/models/cancel_order_v3_response.py new file mode 100644 index 0000000..4119a82 --- /dev/null +++ b/upstox_client/models/cancel_order_v3_response.py @@ -0,0 +1,168 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +import pprint +import re # noqa: F401 + +import six + +class CancelOrderV3Response(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'status': 'str', + 'data': 'CancelOrderData', + 'metadata': 'OrderMetadata' + } + + attribute_map = { + 'status': 'status', + 'data': 'data', + 'metadata': 'metadata' + } + + def __init__(self, status=None, data=None, metadata=None): # noqa: E501 + """CancelOrderV3Response - a model defined in Swagger""" # noqa: E501 + self._status = None + self._data = None + self._metadata = None + self.discriminator = None + if status is not None: + self.status = status + if data is not None: + self.data = data + if metadata is not None: + self.metadata = metadata + + @property + def status(self): + """Gets the status of this CancelOrderV3Response. # noqa: E501 + + + :return: The status of this CancelOrderV3Response. # noqa: E501 + :rtype: str + """ + return self._status + + @status.setter + def status(self, status): + """Sets the status of this CancelOrderV3Response. + + + :param status: The status of this CancelOrderV3Response. # noqa: E501 + :type: str + """ + allowed_values = ["success", "error", "partial_success"] # noqa: E501 + if status not in allowed_values: + raise ValueError( + "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 + .format(status, allowed_values) + ) + + self._status = status + + @property + def data(self): + """Gets the data of this CancelOrderV3Response. # noqa: E501 + + + :return: The data of this CancelOrderV3Response. # noqa: E501 + :rtype: CancelOrderData + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this CancelOrderV3Response. + + + :param data: The data of this CancelOrderV3Response. # noqa: E501 + :type: CancelOrderData + """ + + self._data = data + + @property + def metadata(self): + """Gets the metadata of this CancelOrderV3Response. # noqa: E501 + + + :return: The metadata of this CancelOrderV3Response. # noqa: E501 + :rtype: OrderMetadata + """ + return self._metadata + + @metadata.setter + def metadata(self, metadata): + """Sets the metadata of this CancelOrderV3Response. + + + :param metadata: The metadata of this CancelOrderV3Response. # noqa: E501 + :type: OrderMetadata + """ + + self._metadata = metadata + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + if issubclass(CancelOrderV3Response, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, CancelOrderV3Response): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/upstox_client/models/indie_user_init_token_data.py b/upstox_client/models/indie_user_init_token_data.py new file mode 100644 index 0000000..7288f58 --- /dev/null +++ b/upstox_client/models/indie_user_init_token_data.py @@ -0,0 +1,140 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +import pprint +import re # noqa: F401 + +import six + +class IndieUserInitTokenData(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'authorization_expiry': 'str', + 'notifier_url': 'str' + } + + attribute_map = { + 'authorization_expiry': 'authorization_expiry', + 'notifier_url': 'notifier_url' + } + + def __init__(self, authorization_expiry=None, notifier_url=None): # noqa: E501 + """IndieUserInitTokenData - a model defined in Swagger""" # noqa: E501 + self._authorization_expiry = None + self._notifier_url = None + self.discriminator = None + if authorization_expiry is not None: + self.authorization_expiry = authorization_expiry + if notifier_url is not None: + self.notifier_url = notifier_url + + @property + def authorization_expiry(self): + """Gets the authorization_expiry of this IndieUserInitTokenData. # noqa: E501 + + authorize token expiry # noqa: E501 + + :return: The authorization_expiry of this IndieUserInitTokenData. # noqa: E501 + :rtype: str + """ + return self._authorization_expiry + + @authorization_expiry.setter + def authorization_expiry(self, authorization_expiry): + """Sets the authorization_expiry of this IndieUserInitTokenData. + + authorize token expiry # noqa: E501 + + :param authorization_expiry: The authorization_expiry of this IndieUserInitTokenData. # noqa: E501 + :type: str + """ + + self._authorization_expiry = authorization_expiry + + @property + def notifier_url(self): + """Gets the notifier_url of this IndieUserInitTokenData. # noqa: E501 + + notifier webhook url # noqa: E501 + + :return: The notifier_url of this IndieUserInitTokenData. # noqa: E501 + :rtype: str + """ + return self._notifier_url + + @notifier_url.setter + def notifier_url(self, notifier_url): + """Sets the notifier_url of this IndieUserInitTokenData. + + notifier webhook url # noqa: E501 + + :param notifier_url: The notifier_url of this IndieUserInitTokenData. # noqa: E501 + :type: str + """ + + self._notifier_url = notifier_url + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + if issubclass(IndieUserInitTokenData, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, IndieUserInitTokenData): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/upstox_client/models/indie_user_init_token_response.py b/upstox_client/models/indie_user_init_token_response.py new file mode 100644 index 0000000..3827bdd --- /dev/null +++ b/upstox_client/models/indie_user_init_token_response.py @@ -0,0 +1,142 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +import pprint +import re # noqa: F401 + +import six + +class IndieUserInitTokenResponse(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'status': 'str', + 'data': 'IndieUserInitTokenData' + } + + attribute_map = { + 'status': 'status', + 'data': 'data' + } + + def __init__(self, status=None, data=None): # noqa: E501 + """IndieUserInitTokenResponse - a model defined in Swagger""" # noqa: E501 + self._status = None + self._data = None + self.discriminator = None + if status is not None: + self.status = status + if data is not None: + self.data = data + + @property + def status(self): + """Gets the status of this IndieUserInitTokenResponse. # noqa: E501 + + + :return: The status of this IndieUserInitTokenResponse. # noqa: E501 + :rtype: str + """ + return self._status + + @status.setter + def status(self, status): + """Sets the status of this IndieUserInitTokenResponse. + + + :param status: The status of this IndieUserInitTokenResponse. # noqa: E501 + :type: str + """ + allowed_values = ["success", "error", "partial_success"] # noqa: E501 + if status not in allowed_values: + raise ValueError( + "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 + .format(status, allowed_values) + ) + + self._status = status + + @property + def data(self): + """Gets the data of this IndieUserInitTokenResponse. # noqa: E501 + + + :return: The data of this IndieUserInitTokenResponse. # noqa: E501 + :rtype: IndieUserInitTokenData + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this IndieUserInitTokenResponse. + + + :param data: The data of this IndieUserInitTokenResponse. # noqa: E501 + :type: IndieUserInitTokenData + """ + + self._data = data + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + if issubclass(IndieUserInitTokenResponse, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, IndieUserInitTokenResponse): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/upstox_client/models/indie_user_token_request.py b/upstox_client/models/indie_user_token_request.py new file mode 100644 index 0000000..c8aedd9 --- /dev/null +++ b/upstox_client/models/indie_user_token_request.py @@ -0,0 +1,112 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +import pprint +import re # noqa: F401 + +import six + +class IndieUserTokenRequest(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'client_secret': 'str' + } + + attribute_map = { + 'client_secret': 'client_secret' + } + + def __init__(self, client_secret=None): # noqa: E501 + """IndieUserTokenRequest - a model defined in Swagger""" # noqa: E501 + self._client_secret = None + self.discriminator = None + if client_secret is not None: + self.client_secret = client_secret + + @property + def client_secret(self): + """Gets the client_secret of this IndieUserTokenRequest. # noqa: E501 + + OAuth client secret that is a private secret known only to app and authorization server # noqa: E501 + + :return: The client_secret of this IndieUserTokenRequest. # noqa: E501 + :rtype: str + """ + return self._client_secret + + @client_secret.setter + def client_secret(self, client_secret): + """Sets the client_secret of this IndieUserTokenRequest. + + OAuth client secret that is a private secret known only to app and authorization server # noqa: E501 + + :param client_secret: The client_secret of this IndieUserTokenRequest. # noqa: E501 + :type: str + """ + + self._client_secret = client_secret + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + if issubclass(IndieUserTokenRequest, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, IndieUserTokenRequest): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/upstox_client/models/modify_order_v3_response.py b/upstox_client/models/modify_order_v3_response.py new file mode 100644 index 0000000..6bd7a5d --- /dev/null +++ b/upstox_client/models/modify_order_v3_response.py @@ -0,0 +1,168 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +import pprint +import re # noqa: F401 + +import six + +class ModifyOrderV3Response(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'status': 'str', + 'data': 'ModifyOrderData', + 'metadata': 'OrderMetadata' + } + + attribute_map = { + 'status': 'status', + 'data': 'data', + 'metadata': 'metadata' + } + + def __init__(self, status=None, data=None, metadata=None): # noqa: E501 + """ModifyOrderV3Response - a model defined in Swagger""" # noqa: E501 + self._status = None + self._data = None + self._metadata = None + self.discriminator = None + if status is not None: + self.status = status + if data is not None: + self.data = data + if metadata is not None: + self.metadata = metadata + + @property + def status(self): + """Gets the status of this ModifyOrderV3Response. # noqa: E501 + + + :return: The status of this ModifyOrderV3Response. # noqa: E501 + :rtype: str + """ + return self._status + + @status.setter + def status(self, status): + """Sets the status of this ModifyOrderV3Response. + + + :param status: The status of this ModifyOrderV3Response. # noqa: E501 + :type: str + """ + allowed_values = ["success", "error", "partial_success"] # noqa: E501 + if status not in allowed_values: + raise ValueError( + "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 + .format(status, allowed_values) + ) + + self._status = status + + @property + def data(self): + """Gets the data of this ModifyOrderV3Response. # noqa: E501 + + + :return: The data of this ModifyOrderV3Response. # noqa: E501 + :rtype: ModifyOrderData + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this ModifyOrderV3Response. + + + :param data: The data of this ModifyOrderV3Response. # noqa: E501 + :type: ModifyOrderData + """ + + self._data = data + + @property + def metadata(self): + """Gets the metadata of this ModifyOrderV3Response. # noqa: E501 + + + :return: The metadata of this ModifyOrderV3Response. # noqa: E501 + :rtype: OrderMetadata + """ + return self._metadata + + @metadata.setter + def metadata(self, metadata): + """Sets the metadata of this ModifyOrderV3Response. + + + :param metadata: The metadata of this ModifyOrderV3Response. # noqa: E501 + :type: OrderMetadata + """ + + self._metadata = metadata + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + if issubclass(ModifyOrderV3Response, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, ModifyOrderV3Response): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/upstox_client/models/multi_order_v3_data.py b/upstox_client/models/multi_order_v3_data.py new file mode 100644 index 0000000..a69693e --- /dev/null +++ b/upstox_client/models/multi_order_v3_data.py @@ -0,0 +1,110 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +import pprint +import re # noqa: F401 + +import six + +class MultiOrderV3Data(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'order_ids': 'list[str]' + } + + attribute_map = { + 'order_ids': 'order_ids' + } + + def __init__(self, order_ids=None): # noqa: E501 + """MultiOrderV3Data - a model defined in Swagger""" # noqa: E501 + self._order_ids = None + self.discriminator = None + if order_ids is not None: + self.order_ids = order_ids + + @property + def order_ids(self): + """Gets the order_ids of this MultiOrderV3Data. # noqa: E501 + + + :return: The order_ids of this MultiOrderV3Data. # noqa: E501 + :rtype: list[str] + """ + return self._order_ids + + @order_ids.setter + def order_ids(self, order_ids): + """Sets the order_ids of this MultiOrderV3Data. + + + :param order_ids: The order_ids of this MultiOrderV3Data. # noqa: E501 + :type: list[str] + """ + + self._order_ids = order_ids + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + if issubclass(MultiOrderV3Data, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, MultiOrderV3Data): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/upstox_client/models/order_metadata.py b/upstox_client/models/order_metadata.py new file mode 100644 index 0000000..e7d4f62 --- /dev/null +++ b/upstox_client/models/order_metadata.py @@ -0,0 +1,110 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +import pprint +import re # noqa: F401 + +import six + +class OrderMetadata(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'latency': 'int' + } + + attribute_map = { + 'latency': 'latency' + } + + def __init__(self, latency=None): # noqa: E501 + """OrderMetadata - a model defined in Swagger""" # noqa: E501 + self._latency = None + self.discriminator = None + if latency is not None: + self.latency = latency + + @property + def latency(self): + """Gets the latency of this OrderMetadata. # noqa: E501 + + + :return: The latency of this OrderMetadata. # noqa: E501 + :rtype: int + """ + return self._latency + + @latency.setter + def latency(self, latency): + """Sets the latency of this OrderMetadata. + + + :param latency: The latency of this OrderMetadata. # noqa: E501 + :type: int + """ + + self._latency = latency + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + if issubclass(OrderMetadata, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, OrderMetadata): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/upstox_client/models/place_order_v3_request.py b/upstox_client/models/place_order_v3_request.py new file mode 100644 index 0000000..3062b10 --- /dev/null +++ b/upstox_client/models/place_order_v3_request.py @@ -0,0 +1,450 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +import pprint +import re # noqa: F401 + +import six + +class PlaceOrderV3Request(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'quantity': 'int', + 'product': 'str', + 'validity': 'str', + 'price': 'float', + 'tag': 'str', + 'slice': 'bool', + 'instrument_token': 'str', + 'order_type': 'str', + 'transaction_type': 'str', + 'disclosed_quantity': 'int', + 'trigger_price': 'float', + 'is_amo': 'bool' + } + + attribute_map = { + 'quantity': 'quantity', + 'product': 'product', + 'validity': 'validity', + 'price': 'price', + 'tag': 'tag', + 'slice': 'slice', + 'instrument_token': 'instrument_token', + 'order_type': 'order_type', + 'transaction_type': 'transaction_type', + 'disclosed_quantity': 'disclosed_quantity', + 'trigger_price': 'trigger_price', + 'is_amo': 'is_amo' + } + + def __init__(self, quantity=None, product=None, validity=None, price=None, tag=None, slice=None, instrument_token=None, order_type=None, transaction_type=None, disclosed_quantity=None, trigger_price=None, is_amo=None): # noqa: E501 + """PlaceOrderV3Request - a model defined in Swagger""" # noqa: E501 + self._quantity = None + self._product = None + self._validity = None + self._price = None + self._tag = None + self._slice = None + self._instrument_token = None + self._order_type = None + self._transaction_type = None + self._disclosed_quantity = None + self._trigger_price = None + self._is_amo = None + self.discriminator = None + self.quantity = quantity + self.product = product + self.validity = validity + self.price = price + if tag is not None: + self.tag = tag + if slice is not None: + self.slice = slice + self.instrument_token = instrument_token + self.order_type = order_type + self.transaction_type = transaction_type + self.disclosed_quantity = disclosed_quantity + self.trigger_price = trigger_price + self.is_amo = is_amo + + @property + def quantity(self): + """Gets the quantity of this PlaceOrderV3Request. # noqa: E501 + + Quantity with which the order is to be placed # noqa: E501 + + :return: The quantity of this PlaceOrderV3Request. # noqa: E501 + :rtype: int + """ + return self._quantity + + @quantity.setter + def quantity(self, quantity): + """Sets the quantity of this PlaceOrderV3Request. + + Quantity with which the order is to be placed # noqa: E501 + + :param quantity: The quantity of this PlaceOrderV3Request. # noqa: E501 + :type: int + """ + if quantity is None: + raise ValueError("Invalid value for `quantity`, must not be `None`") # noqa: E501 + + self._quantity = quantity + + @property + def product(self): + """Gets the product of this PlaceOrderV3Request. # noqa: E501 + + Signifies if the order was either Intraday, Delivery, CO or OCO # noqa: E501 + + :return: The product of this PlaceOrderV3Request. # noqa: E501 + :rtype: str + """ + return self._product + + @product.setter + def product(self, product): + """Sets the product of this PlaceOrderV3Request. + + Signifies if the order was either Intraday, Delivery, CO or OCO # noqa: E501 + + :param product: The product of this PlaceOrderV3Request. # noqa: E501 + :type: str + """ + if product is None: + raise ValueError("Invalid value for `product`, must not be `None`") # noqa: E501 + allowed_values = ["I", "D"] # noqa: E501 + if product not in allowed_values: + raise ValueError( + "Invalid value for `product` ({0}), must be one of {1}" # noqa: E501 + .format(product, allowed_values) + ) + + self._product = product + + @property + def validity(self): + """Gets the validity of this PlaceOrderV3Request. # noqa: E501 + + It can be one of the following - DAY(default), IOC # noqa: E501 + + :return: The validity of this PlaceOrderV3Request. # noqa: E501 + :rtype: str + """ + return self._validity + + @validity.setter + def validity(self, validity): + """Sets the validity of this PlaceOrderV3Request. + + It can be one of the following - DAY(default), IOC # noqa: E501 + + :param validity: The validity of this PlaceOrderV3Request. # noqa: E501 + :type: str + """ + if validity is None: + raise ValueError("Invalid value for `validity`, must not be `None`") # noqa: E501 + allowed_values = ["DAY", "IOC"] # noqa: E501 + if validity not in allowed_values: + raise ValueError( + "Invalid value for `validity` ({0}), must be one of {1}" # noqa: E501 + .format(validity, allowed_values) + ) + + self._validity = validity + + @property + def price(self): + """Gets the price of this PlaceOrderV3Request. # noqa: E501 + + Price at which the order will be placed # noqa: E501 + + :return: The price of this PlaceOrderV3Request. # noqa: E501 + :rtype: float + """ + return self._price + + @price.setter + def price(self, price): + """Sets the price of this PlaceOrderV3Request. + + Price at which the order will be placed # noqa: E501 + + :param price: The price of this PlaceOrderV3Request. # noqa: E501 + :type: float + """ + if price is None: + raise ValueError("Invalid value for `price`, must not be `None`") # noqa: E501 + + self._price = price + + @property + def tag(self): + """Gets the tag of this PlaceOrderV3Request. # noqa: E501 + + + :return: The tag of this PlaceOrderV3Request. # noqa: E501 + :rtype: str + """ + return self._tag + + @tag.setter + def tag(self, tag): + """Sets the tag of this PlaceOrderV3Request. + + + :param tag: The tag of this PlaceOrderV3Request. # noqa: E501 + :type: str + """ + + self._tag = tag + + @property + def slice(self): + """Gets the slice of this PlaceOrderV3Request. # noqa: E501 + + + :return: The slice of this PlaceOrderV3Request. # noqa: E501 + :rtype: bool + """ + return self._slice + + @slice.setter + def slice(self, slice): + """Sets the slice of this PlaceOrderV3Request. + + + :param slice: The slice of this PlaceOrderV3Request. # noqa: E501 + :type: bool + """ + + self._slice = slice + + @property + def instrument_token(self): + """Gets the instrument_token of this PlaceOrderV3Request. # noqa: E501 + + Key of the instrument # noqa: E501 + + :return: The instrument_token of this PlaceOrderV3Request. # noqa: E501 + :rtype: str + """ + return self._instrument_token + + @instrument_token.setter + def instrument_token(self, instrument_token): + """Sets the instrument_token of this PlaceOrderV3Request. + + Key of the instrument # noqa: E501 + + :param instrument_token: The instrument_token of this PlaceOrderV3Request. # noqa: E501 + :type: str + """ + if instrument_token is None: + raise ValueError("Invalid value for `instrument_token`, must not be `None`") # noqa: E501 + + self._instrument_token = instrument_token + + @property + def order_type(self): + """Gets the order_type of this PlaceOrderV3Request. # noqa: E501 + + 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 # noqa: E501 + + :return: The order_type of this PlaceOrderV3Request. # noqa: E501 + :rtype: str + """ + return self._order_type + + @order_type.setter + def order_type(self, order_type): + """Sets the order_type of this PlaceOrderV3Request. + + 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 # noqa: E501 + + :param order_type: The order_type of this PlaceOrderV3Request. # noqa: E501 + :type: str + """ + if order_type is None: + raise ValueError("Invalid value for `order_type`, must not be `None`") # noqa: E501 + allowed_values = ["MARKET", "LIMIT", "SL", "SL-M"] # noqa: E501 + if order_type not in allowed_values: + raise ValueError( + "Invalid value for `order_type` ({0}), must be one of {1}" # noqa: E501 + .format(order_type, allowed_values) + ) + + self._order_type = order_type + + @property + def transaction_type(self): + """Gets the transaction_type of this PlaceOrderV3Request. # noqa: E501 + + Indicates whether its a buy or sell order # noqa: E501 + + :return: The transaction_type of this PlaceOrderV3Request. # noqa: E501 + :rtype: str + """ + return self._transaction_type + + @transaction_type.setter + def transaction_type(self, transaction_type): + """Sets the transaction_type of this PlaceOrderV3Request. + + Indicates whether its a buy or sell order # noqa: E501 + + :param transaction_type: The transaction_type of this PlaceOrderV3Request. # noqa: E501 + :type: str + """ + if transaction_type is None: + raise ValueError("Invalid value for `transaction_type`, must not be `None`") # noqa: E501 + allowed_values = ["BUY", "SELL"] # noqa: E501 + if transaction_type not in allowed_values: + raise ValueError( + "Invalid value for `transaction_type` ({0}), must be one of {1}" # noqa: E501 + .format(transaction_type, allowed_values) + ) + + self._transaction_type = transaction_type + + @property + def disclosed_quantity(self): + """Gets the disclosed_quantity of this PlaceOrderV3Request. # noqa: E501 + + The quantity that should be disclosed in the market depth # noqa: E501 + + :return: The disclosed_quantity of this PlaceOrderV3Request. # noqa: E501 + :rtype: int + """ + return self._disclosed_quantity + + @disclosed_quantity.setter + def disclosed_quantity(self, disclosed_quantity): + """Sets the disclosed_quantity of this PlaceOrderV3Request. + + The quantity that should be disclosed in the market depth # noqa: E501 + + :param disclosed_quantity: The disclosed_quantity of this PlaceOrderV3Request. # noqa: E501 + :type: int + """ + if disclosed_quantity is None: + raise ValueError("Invalid value for `disclosed_quantity`, must not be `None`") # noqa: E501 + + self._disclosed_quantity = disclosed_quantity + + @property + def trigger_price(self): + """Gets the trigger_price of this PlaceOrderV3Request. # noqa: E501 + + If the order is a stop loss order then the trigger price to be set is mentioned here # noqa: E501 + + :return: The trigger_price of this PlaceOrderV3Request. # noqa: E501 + :rtype: float + """ + return self._trigger_price + + @trigger_price.setter + def trigger_price(self, trigger_price): + """Sets the trigger_price of this PlaceOrderV3Request. + + If the order is a stop loss order then the trigger price to be set is mentioned here # noqa: E501 + + :param trigger_price: The trigger_price of this PlaceOrderV3Request. # noqa: E501 + :type: float + """ + if trigger_price is None: + raise ValueError("Invalid value for `trigger_price`, must not be `None`") # noqa: E501 + + self._trigger_price = trigger_price + + @property + def is_amo(self): + """Gets the is_amo of this PlaceOrderV3Request. # noqa: E501 + + Signifies if the order is an After Market Order # noqa: E501 + + :return: The is_amo of this PlaceOrderV3Request. # noqa: E501 + :rtype: bool + """ + return self._is_amo + + @is_amo.setter + def is_amo(self, is_amo): + """Sets the is_amo of this PlaceOrderV3Request. + + Signifies if the order is an After Market Order # noqa: E501 + + :param is_amo: The is_amo of this PlaceOrderV3Request. # noqa: E501 + :type: bool + """ + if is_amo is None: + raise ValueError("Invalid value for `is_amo`, must not be `None`") # noqa: E501 + + self._is_amo = is_amo + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + if issubclass(PlaceOrderV3Request, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, PlaceOrderV3Request): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/upstox_client/models/place_order_v3_response.py b/upstox_client/models/place_order_v3_response.py new file mode 100644 index 0000000..26f60e4 --- /dev/null +++ b/upstox_client/models/place_order_v3_response.py @@ -0,0 +1,168 @@ +# coding: utf-8 + +""" + OpenAPI definition + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: v0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +import pprint +import re # noqa: F401 + +import six + +class PlaceOrderV3Response(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'status': 'str', + 'data': 'MultiOrderV3Data', + 'metadata': 'OrderMetadata' + } + + attribute_map = { + 'status': 'status', + 'data': 'data', + 'metadata': 'metadata' + } + + def __init__(self, status=None, data=None, metadata=None): # noqa: E501 + """PlaceOrderV3Response - a model defined in Swagger""" # noqa: E501 + self._status = None + self._data = None + self._metadata = None + self.discriminator = None + if status is not None: + self.status = status + if data is not None: + self.data = data + if metadata is not None: + self.metadata = metadata + + @property + def status(self): + """Gets the status of this PlaceOrderV3Response. # noqa: E501 + + + :return: The status of this PlaceOrderV3Response. # noqa: E501 + :rtype: str + """ + return self._status + + @status.setter + def status(self, status): + """Sets the status of this PlaceOrderV3Response. + + + :param status: The status of this PlaceOrderV3Response. # noqa: E501 + :type: str + """ + allowed_values = ["success", "error", "partial_success"] # noqa: E501 + if status not in allowed_values: + raise ValueError( + "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 + .format(status, allowed_values) + ) + + self._status = status + + @property + def data(self): + """Gets the data of this PlaceOrderV3Response. # noqa: E501 + + + :return: The data of this PlaceOrderV3Response. # noqa: E501 + :rtype: MultiOrderV3Data + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this PlaceOrderV3Response. + + + :param data: The data of this PlaceOrderV3Response. # noqa: E501 + :type: MultiOrderV3Data + """ + + self._data = data + + @property + def metadata(self): + """Gets the metadata of this PlaceOrderV3Response. # noqa: E501 + + + :return: The metadata of this PlaceOrderV3Response. # noqa: E501 + :rtype: OrderMetadata + """ + return self._metadata + + @metadata.setter + def metadata(self, metadata): + """Sets the metadata of this PlaceOrderV3Response. + + + :param metadata: The metadata of this PlaceOrderV3Response. # noqa: E501 + :type: OrderMetadata + """ + + self._metadata = metadata + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + if issubclass(PlaceOrderV3Response, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, PlaceOrderV3Response): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other From 24f1421d7868a4664e6db52e93a9c71bbb3c6b5d Mon Sep 17 00:00:00 2001 From: KETAN GUPTA Date: Thu, 23 Jan 2025 18:02:20 +0530 Subject: [PATCH 2/7] updated TypeWithDefault --- upstox_client/configuration.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/upstox_client/configuration.py b/upstox_client/configuration.py index 80c53d4..41b4aa1 100644 --- a/upstox_client/configuration.py +++ b/upstox_client/configuration.py @@ -28,7 +28,9 @@ def __init__(cls, name, bases, dct): cls._default = None def __call__(cls, *args, **kwargs): - return type.__call__(cls, *args, **kwargs) + if cls._default is None: + cls._default = type.__call__(cls, *args, **kwargs) + return copy.copy(cls._default) def set_default(cls, default): cls._default = copy.copy(default) From 0068617a1b81d035eb2487ee2cda4388bdba31fe Mon Sep 17 00:00:00 2001 From: KETAN GUPTA Date: Sun, 26 Jan 2025 14:30:23 +0530 Subject: [PATCH 3/7] added v3 example and blocked not valid sandbox endpoints --- docs/ChargeApi.md | 52 ++++ docs/LoginApi.md | 50 ++++ docs/OrderApi.md | 238 +++++++++++++++++- ...{OrderControllerV3Api.md => OrderApiV3.md} | 24 +- .../market_data/v3/MarketDataFeedV3.proto | 119 +++++++++ .../market_data/v3/MarketDataFeedV3_pb2.py | 74 ++++++ examples/websocket/market_data/v3/README.md | 103 ++++++++ .../market_data/v3/websocket_client.py | 74 ++++++ test/sdk_tests/market_basic.py | 2 +- test/sdk_tests/sandbox_sanity.py | 46 ++-- upstox_client/api_client.py | 4 + upstox_client/configuration.py | 13 + 12 files changed, 749 insertions(+), 50 deletions(-) rename docs/{OrderControllerV3Api.md => OrderApiV3.md} (82%) create mode 100644 examples/websocket/market_data/v3/MarketDataFeedV3.proto create mode 100644 examples/websocket/market_data/v3/MarketDataFeedV3_pb2.py create mode 100644 examples/websocket/market_data/v3/README.md create mode 100644 examples/websocket/market_data/v3/websocket_client.py diff --git a/docs/ChargeApi.md b/docs/ChargeApi.md index fc32adf..3f50f4b 100644 --- a/docs/ChargeApi.md +++ b/docs/ChargeApi.md @@ -68,3 +68,55 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **post_margin** +> PostMarginResponse post_margin(body) + +Calculate Margin + +Compute Margin + +### Example +```python +from __future__ import print_function +import time +import upstox_client +from upstox_client.rest import ApiException +from pprint import pprint + +# Configure OAuth2 access token for authorization: OAUTH2 +configuration = upstox_client.Configuration() +configuration.access_token = 'YOUR_ACCESS_TOKEN' + +# create an instance of the API class +api_instance = upstox_client.ChargeApi(upstox_client.ApiClient(configuration)) +body = upstox_client.MarginRequest() # MarginRequest | + +try: + # Calculate Margin + api_response = api_instance.post_margin(body) + pprint(api_response) +except ApiException as e: + print("Exception when calling ChargeApi->post_margin: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**MarginRequest**](MarginRequest.md)| | + +### Return type + +[**PostMarginResponse**](PostMarginResponse.md) + +### Authorization + +[OAUTH2](../README.md#OAUTH2) + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json, */* + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/docs/LoginApi.md b/docs/LoginApi.md index 299555f..b8b1724 100644 --- a/docs/LoginApi.md +++ b/docs/LoginApi.md @@ -63,6 +63,56 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **init_token_request_for_indie_user** +> IndieUserInitTokenResponse init_token_request_for_indie_user(body, client_id) + +Init token API + +This API provides the initialize the generate token and it's expiry for an indie user + +### Example +```python +from __future__ import print_function +import time +import upstox_client +from upstox_client.rest import ApiException +from pprint import pprint + +# create an instance of the API class +api_instance = upstox_client.LoginApi() +body = upstox_client.IndieUserTokenRequest() # IndieUserTokenRequest | +client_id = 'client_id_example' # str | + +try: + # Init token API + api_response = api_instance.init_token_request_for_indie_user(body, client_id) + pprint(api_response) +except ApiException as e: + print("Exception when calling LoginApi->init_token_request_for_indie_user: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**IndieUserTokenRequest**](IndieUserTokenRequest.md)| | + **client_id** | **str**| | + +### Return type + +[**IndieUserInitTokenResponse**](IndieUserInitTokenResponse.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json, */* + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **logout** > LogoutResponse logout(api_version) diff --git a/docs/OrderApi.md b/docs/OrderApi.md index cda3bf6..be26029 100644 --- a/docs/OrderApi.md +++ b/docs/OrderApi.md @@ -4,16 +4,74 @@ All URIs are relative to *https://api-v2.upstox.com* Method | HTTP request | Description ------------- | ------------- | ------------- -[**cancel_order**](OrderApi.md#cancel_order) | **DELETE** /order/cancel | Cancel order -[**get_order_book**](OrderApi.md#get_order_book) | **GET** /order/retrieve-all | Get order book -[**get_order_details**](OrderApi.md#get_order_details) | **GET** /order/history | Get order details -[**get_trade_history**](OrderApi.md#get_trade_history) | **GET** /order/trades/get-trades-for-day | Get trades -[**get_trades_by_order**](OrderApi.md#get_trades_by_order) | **GET** /order/trades | Get trades for order -[**modify_order**](OrderApi.md#modify_order) | **PUT** /order/modify | Modify order -[**place_order**](OrderApi.md#place_order) | **POST** /order/place | Place order +[**cancel_multi_order**](OrderApi.md#cancel_multi_order) | **DELETE** /v2/order/multi/cancel | Cancel multi order +[**cancel_order1**](OrderApi.md#cancel_order1) | **DELETE** /v2/order/cancel | Cancel order +[**exit_positions**](OrderApi.md#exit_positions) | **POST** /v2/order/positions/exit | Exit all positions +[**get_order_book**](OrderApi.md#get_order_book) | **GET** /v2/order/retrieve-all | Get order book +[**get_order_details**](OrderApi.md#get_order_details) | **GET** /v2/order/history | Get order history +[**get_order_status**](OrderApi.md#get_order_status) | **GET** /v2/order/details | Get order details +[**get_trade_history**](OrderApi.md#get_trade_history) | **GET** /v2/order/trades/get-trades-for-day | Get trades +[**get_trades_by_order**](OrderApi.md#get_trades_by_order) | **GET** /v2/order/trades | Get trades for order +[**modify_order1**](OrderApi.md#modify_order1) | **PUT** /v2/order/modify | Modify order +[**place_multi_order**](OrderApi.md#place_multi_order) | **POST** /v2/order/multi/place | Place multi order +[**place_order1**](OrderApi.md#place_order1) | **POST** /v2/order/place | Place order -# **cancel_order** -> CancelOrderResponse cancel_order(order_id, api_version) +# **cancel_multi_order** +> CancelOrExitMultiOrderResponse cancel_multi_order(tag=tag, segment=segment) + +Cancel multi order + +API to cancel all the open or pending orders which can be applied to both AMO and regular orders. + +### Example +```python +from __future__ import print_function +import time +import upstox_client +from upstox_client.rest import ApiException +from pprint import pprint + +# Configure OAuth2 access token for authorization: OAUTH2 +configuration = upstox_client.Configuration() +configuration.access_token = 'YOUR_ACCESS_TOKEN' + +# create an instance of the API class +api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) +tag = 'tag_example' # str | The tag associated with the orders for which the orders must be cancelled (optional) +segment = 'segment_example' # str | The segment for which the orders must be cancelled (optional) + +try: + # Cancel multi order + api_response = api_instance.cancel_multi_order(tag=tag, segment=segment) + pprint(api_response) +except ApiException as e: + print("Exception when calling OrderApi->cancel_multi_order: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **tag** | **str**| The tag associated with the orders for which the orders must be cancelled | [optional] + **segment** | **str**| The segment for which the orders must be cancelled | [optional] + +### Return type + +[**CancelOrExitMultiOrderResponse**](CancelOrExitMultiOrderResponse.md) + +### Authorization + +[OAUTH2](../README.md#OAUTH2) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json, */* + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **cancel_order1** +> CancelOrderResponse cancel_order1(order_id) Cancel order @@ -66,6 +124,60 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **exit_positions** +> CancelOrExitMultiOrderResponse exit_positions(tag=tag, segment=segment) + +Exit all positions + +This API provides the functionality to exit all the positions + +### Example +```python +from __future__ import print_function +import time +import upstox_client +from upstox_client.rest import ApiException +from pprint import pprint + +# Configure OAuth2 access token for authorization: OAUTH2 +configuration = upstox_client.Configuration() +configuration.access_token = 'YOUR_ACCESS_TOKEN' + +# create an instance of the API class +api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) +tag = 'tag_example' # str | The tag associated with the positions for which the positions must be exit (optional) +segment = 'segment_example' # str | The segment for which the positions must be exit (optional) + +try: + # Exit all positions + api_response = api_instance.exit_positions(tag=tag, segment=segment) + pprint(api_response) +except ApiException as e: + print("Exception when calling OrderApi->exit_positions: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **tag** | **str**| The tag associated with the positions for which the positions must be exit | [optional] + **segment** | **str**| The segment for which the positions must be exit | [optional] + +### Return type + +[**CancelOrExitMultiOrderResponse**](CancelOrExitMultiOrderResponse.md) + +### Authorization + +[OAUTH2](../README.md#OAUTH2) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json, */* + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **get_order_book** > GetOrderBookResponse get_order_book(api_version) @@ -174,6 +286,58 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **get_order_status** +> GetOrderDetailsResponse get_order_status(order_id=order_id) + +Get order details + +This API provides the recent detail 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.\\n\\nThe order details can be requested using order_id. + +### Example +```python +from __future__ import print_function +import time +import upstox_client +from upstox_client.rest import ApiException +from pprint import pprint + +# Configure OAuth2 access token for authorization: OAUTH2 +configuration = upstox_client.Configuration() +configuration.access_token = 'YOUR_ACCESS_TOKEN' + +# create an instance of the API class +api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) +order_id = 'order_id_example' # str | The order reference ID for which the order details is required (optional) + +try: + # Get order details + api_response = api_instance.get_order_status(order_id=order_id) + pprint(api_response) +except ApiException as e: + print("Exception when calling OrderApi->get_order_status: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **order_id** | **str**| The order reference ID for which the order details is required | [optional] + +### Return type + +[**GetOrderDetailsResponse**](GetOrderDetailsResponse.md) + +### Authorization + +[OAUTH2](../README.md#OAUTH2) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json, */* + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **get_trade_history** > GetTradeResponse get_trade_history(api_version) @@ -334,8 +498,60 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -# **place_order** -> PlaceOrderResponse place_order(body, api_version) +# **place_multi_order** +> MultiOrderResponse place_multi_order(body) + +Place multi order + +This API allows you to place multiple orders to the exchange via Upstox. + +### Example +```python +from __future__ import print_function +import time +import upstox_client +from upstox_client.rest import ApiException +from pprint import pprint + +# Configure OAuth2 access token for authorization: OAUTH2 +configuration = upstox_client.Configuration() +configuration.access_token = 'YOUR_ACCESS_TOKEN' + +# create an instance of the API class +api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) +body = [upstox_client.MultiOrderRequest()] # list[MultiOrderRequest] | + +try: + # Place multi order + api_response = api_instance.place_multi_order(body) + pprint(api_response) +except ApiException as e: + print("Exception when calling OrderApi->place_multi_order: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**list[MultiOrderRequest]**](MultiOrderRequest.md)| | + +### Return type + +[**MultiOrderResponse**](MultiOrderResponse.md) + +### Authorization + +[OAUTH2](../README.md#OAUTH2) + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: */*, application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **place_order1** +> PlaceOrderResponse place_order1(body) Place order diff --git a/docs/OrderControllerV3Api.md b/docs/OrderApiV3.md similarity index 82% rename from docs/OrderControllerV3Api.md rename to docs/OrderApiV3.md index 2a2fae7..21d3188 100644 --- a/docs/OrderControllerV3Api.md +++ b/docs/OrderApiV3.md @@ -9,7 +9,7 @@ Method | HTTP request | Description [**place_order**](OrderApiV3.md#place_order) | **POST** /v3/order/place | # **cancel_order** -> CancelOrderV3Response cancel_order(order_id, origin=origin) +> CancelOrderV3Response cancel_order(order_id) @@ -24,10 +24,9 @@ from pprint import pprint # create an instance of the API class api_instance = upstox_client.OrderApiV3() order_id = 'order_id_example' # str | -origin = 'origin_example' # str | (optional) try: - api_response = api_instance.cancel_order(order_id, origin=origin) + api_response = api_instance.cancel_order(order_id) pprint(api_response) except ApiException as e: print("Exception when calling OrderApiV3->cancel_order: %s\n" % e) @@ -37,8 +36,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **order_id** | **str**| | - **origin** | **str**| | [optional] + **order_id** | **str**| | ### Return type @@ -56,7 +54,7 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **modify_order** -> ModifyOrderV3Response modify_order(body, origin=origin) +> ModifyOrderV3Response modify_order(body) @@ -71,10 +69,9 @@ from pprint import pprint # create an instance of the API class api_instance = upstox_client.OrderApiV3() body = upstox_client.ModifyOrderRequest() # ModifyOrderRequest | -origin = 'origin_example' # str | (optional) try: - api_response = api_instance.modify_order(body, origin=origin) + api_response = api_instance.modify_order(body) pprint(api_response) except ApiException as e: print("Exception when calling OrderApiV3->modify_order: %s\n" % e) @@ -84,8 +81,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**ModifyOrderRequest**](ModifyOrderRequest.md)| | - **origin** | **str**| | [optional] + **body** | [**ModifyOrderRequest**](ModifyOrderRequest.md)| | ### Return type @@ -103,7 +99,7 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **place_order** -> PlaceOrderV3Response place_order(body, origin=origin) +> PlaceOrderV3Response place_order(body) @@ -118,10 +114,9 @@ from pprint import pprint # create an instance of the API class api_instance = upstox_client.OrderApiV3() body = upstox_client.PlaceOrderV3Request() # PlaceOrderV3Request | -origin = 'origin_example' # str | (optional) try: - api_response = api_instance.place_order(body, origin=origin) + api_response = api_instance.place_order(body) pprint(api_response) except ApiException as e: print("Exception when calling OrderApiV3->place_order: %s\n" % e) @@ -131,8 +126,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**PlaceOrderV3Request**](PlaceOrderV3Request.md)| | - **origin** | **str**| | [optional] + **body** | [**PlaceOrderV3Request**](PlaceOrderV3Request.md)| | ### Return type diff --git a/examples/websocket/market_data/v3/MarketDataFeedV3.proto b/examples/websocket/market_data/v3/MarketDataFeedV3.proto new file mode 100644 index 0000000..1621bf5 --- /dev/null +++ b/examples/websocket/market_data/v3/MarketDataFeedV3.proto @@ -0,0 +1,119 @@ +syntax = "proto3"; +package com.upstox.marketdatafeederv3udapi.rpc.proto; + +message LTPC { + double ltp = 1; + int64 ltt = 2; + double cp = 3; //close price +} + +message MarketLevel { + repeated Quote bidAskQuote = 1; +} + +message MarketOHLC { + repeated OHLC ohlc = 1; +} + +message Quote { + int64 bidQ = 1; + double bidP = 2; + int64 askQ = 3; + double askP = 4; +} + +message OptionGreeks { + double delta = 1; + double theta = 2; + double gamma = 3; + double vega = 4; + double rho = 5; +} + +message OHLC { + string interval = 1; + double open = 2; + double high = 3; + double low = 4; + double close = 5; + int64 vol = 6; + int64 ts = 7; +} + +enum Type{ + initial_feed = 0; + live_feed = 1; + market_info = 2; +} + +message MarketFullFeed{ + LTPC ltpc = 1; + MarketLevel marketLevel = 2; + OptionGreeks optionGreeks = 3; + MarketOHLC marketOHLC = 4; + double atp = 5; //avg traded price + int64 vtt = 6; //volume traded today + double oi = 7; //open interest + double iv = 8; //implied volatility + double tbq =9; //total buy quantity + double tsq = 10; //total sell quantity +} + +message IndexFullFeed{ + LTPC ltpc = 1; + MarketOHLC marketOHLC = 2; +} + + +message FullFeed { + oneof FullFeedUnion { + MarketFullFeed marketFF = 1; + IndexFullFeed indexFF = 2; + } +} + +message FirstLevelWithGreeks{ + LTPC ltpc = 1; + Quote firstDepth = 2; + OptionGreeks optionGreeks = 3; + int64 vtt = 4; //volume traded today + double oi = 5; //open interest + double iv = 6; //implied volatility +} + +message Feed { + oneof FeedUnion { + LTPC ltpc = 1; + FullFeed fullFeed = 2; + FirstLevelWithGreeks firstLevelWithGreeks = 3; + } + RequestMode requestMode = 4; +} + +enum RequestMode { + ltpc = 0; + full_d5 = 1; + option_greeks = 2; + full_d30 = 3; +} + +enum MarketStatus { + PRE_OPEN_START = 0; + PRE_OPEN_END = 1; + NORMAL_OPEN = 2; + NORMAL_CLOSE = 3; + CLOSING_START = 4; + CLOSING_END = 5; +} + + +message MarketInfo { + map segmentStatus = 1; +} + +message FeedResponse{ + Type type = 1; + map feeds = 2; + int64 currentTs = 3; + MarketInfo marketInfo = 4; +} \ No newline at end of file diff --git a/examples/websocket/market_data/v3/MarketDataFeedV3_pb2.py b/examples/websocket/market_data/v3/MarketDataFeedV3_pb2.py new file mode 100644 index 0000000..73b647f --- /dev/null +++ b/examples/websocket/market_data/v3/MarketDataFeedV3_pb2.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: MarketDataFeedV3.proto +# Protobuf Python Version: 5.28.3 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 5, + 28, + 3, + '', + 'MarketDataFeedV3.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x16MarketDataFeedV3.proto\x12,com.upstox.marketdatafeederv3udapi.rpc.proto\",\n\x04LTPC\x12\x0b\n\x03ltp\x18\x01 \x01(\x01\x12\x0b\n\x03ltt\x18\x02 \x01(\x03\x12\n\n\x02\x63p\x18\x03 \x01(\x01\"W\n\x0bMarketLevel\x12H\n\x0b\x62idAskQuote\x18\x01 \x03(\x0b\x32\x33.com.upstox.marketdatafeederv3udapi.rpc.proto.Quote\"N\n\nMarketOHLC\x12@\n\x04ohlc\x18\x01 \x03(\x0b\x32\x32.com.upstox.marketdatafeederv3udapi.rpc.proto.OHLC\"?\n\x05Quote\x12\x0c\n\x04\x62idQ\x18\x01 \x01(\x03\x12\x0c\n\x04\x62idP\x18\x02 \x01(\x01\x12\x0c\n\x04\x61skQ\x18\x03 \x01(\x03\x12\x0c\n\x04\x61skP\x18\x04 \x01(\x01\"V\n\x0cOptionGreeks\x12\r\n\x05\x64\x65lta\x18\x01 \x01(\x01\x12\r\n\x05theta\x18\x02 \x01(\x01\x12\r\n\x05gamma\x18\x03 \x01(\x01\x12\x0c\n\x04vega\x18\x04 \x01(\x01\x12\x0b\n\x03rho\x18\x05 \x01(\x01\"i\n\x04OHLC\x12\x10\n\x08interval\x18\x01 \x01(\t\x12\x0c\n\x04open\x18\x02 \x01(\x01\x12\x0c\n\x04high\x18\x03 \x01(\x01\x12\x0b\n\x03low\x18\x04 \x01(\x01\x12\r\n\x05\x63lose\x18\x05 \x01(\x01\x12\x0b\n\x03vol\x18\x06 \x01(\x03\x12\n\n\x02ts\x18\x07 \x01(\x03\"\x8e\x03\n\x0eMarketFullFeed\x12@\n\x04ltpc\x18\x01 \x01(\x0b\x32\x32.com.upstox.marketdatafeederv3udapi.rpc.proto.LTPC\x12N\n\x0bmarketLevel\x18\x02 \x01(\x0b\x32\x39.com.upstox.marketdatafeederv3udapi.rpc.proto.MarketLevel\x12P\n\x0coptionGreeks\x18\x03 \x01(\x0b\x32:.com.upstox.marketdatafeederv3udapi.rpc.proto.OptionGreeks\x12L\n\nmarketOHLC\x18\x04 \x01(\x0b\x32\x38.com.upstox.marketdatafeederv3udapi.rpc.proto.MarketOHLC\x12\x0b\n\x03\x61tp\x18\x05 \x01(\x01\x12\x0b\n\x03vtt\x18\x06 \x01(\x03\x12\n\n\x02oi\x18\x07 \x01(\x01\x12\n\n\x02iv\x18\x08 \x01(\x01\x12\x0b\n\x03tbq\x18\t \x01(\x01\x12\x0b\n\x03tsq\x18\n \x01(\x01\"\x9f\x01\n\rIndexFullFeed\x12@\n\x04ltpc\x18\x01 \x01(\x0b\x32\x32.com.upstox.marketdatafeederv3udapi.rpc.proto.LTPC\x12L\n\nmarketOHLC\x18\x02 \x01(\x0b\x32\x38.com.upstox.marketdatafeederv3udapi.rpc.proto.MarketOHLC\"\xbd\x01\n\x08\x46ullFeed\x12P\n\x08marketFF\x18\x01 \x01(\x0b\x32<.com.upstox.marketdatafeederv3udapi.rpc.proto.MarketFullFeedH\x00\x12N\n\x07indexFF\x18\x02 \x01(\x0b\x32;.com.upstox.marketdatafeederv3udapi.rpc.proto.IndexFullFeedH\x00\x42\x0f\n\rFullFeedUnion\"\x98\x02\n\x14\x46irstLevelWithGreeks\x12@\n\x04ltpc\x18\x01 \x01(\x0b\x32\x32.com.upstox.marketdatafeederv3udapi.rpc.proto.LTPC\x12G\n\nfirstDepth\x18\x02 \x01(\x0b\x32\x33.com.upstox.marketdatafeederv3udapi.rpc.proto.Quote\x12P\n\x0coptionGreeks\x18\x03 \x01(\x0b\x32:.com.upstox.marketdatafeederv3udapi.rpc.proto.OptionGreeks\x12\x0b\n\x03vtt\x18\x04 \x01(\x03\x12\n\n\x02oi\x18\x05 \x01(\x01\x12\n\n\x02iv\x18\x06 \x01(\x01\"\xd7\x02\n\x04\x46\x65\x65\x64\x12\x42\n\x04ltpc\x18\x01 \x01(\x0b\x32\x32.com.upstox.marketdatafeederv3udapi.rpc.proto.LTPCH\x00\x12J\n\x08\x66ullFeed\x18\x02 \x01(\x0b\x32\x36.com.upstox.marketdatafeederv3udapi.rpc.proto.FullFeedH\x00\x12\x62\n\x14\x66irstLevelWithGreeks\x18\x03 \x01(\x0b\x32\x42.com.upstox.marketdatafeederv3udapi.rpc.proto.FirstLevelWithGreeksH\x00\x12N\n\x0brequestMode\x18\x04 \x01(\x0e\x32\x39.com.upstox.marketdatafeederv3udapi.rpc.proto.RequestModeB\x0b\n\tFeedUnion\"\xe2\x01\n\nMarketInfo\x12\x62\n\rsegmentStatus\x18\x01 \x03(\x0b\x32K.com.upstox.marketdatafeederv3udapi.rpc.proto.MarketInfo.SegmentStatusEntry\x1ap\n\x12SegmentStatusEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12I\n\x05value\x18\x02 \x01(\x0e\x32:.com.upstox.marketdatafeederv3udapi.rpc.proto.MarketStatus:\x02\x38\x01\"\xe9\x02\n\x0c\x46\x65\x65\x64Response\x12@\n\x04type\x18\x01 \x01(\x0e\x32\x32.com.upstox.marketdatafeederv3udapi.rpc.proto.Type\x12T\n\x05\x66\x65\x65\x64s\x18\x02 \x03(\x0b\x32\x45.com.upstox.marketdatafeederv3udapi.rpc.proto.FeedResponse.FeedsEntry\x12\x11\n\tcurrentTs\x18\x03 \x01(\x03\x12L\n\nmarketInfo\x18\x04 \x01(\x0b\x32\x38.com.upstox.marketdatafeederv3udapi.rpc.proto.MarketInfo\x1a`\n\nFeedsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x41\n\x05value\x18\x02 \x01(\x0b\x32\x32.com.upstox.marketdatafeederv3udapi.rpc.proto.Feed:\x02\x38\x01*8\n\x04Type\x12\x10\n\x0cinitial_feed\x10\x00\x12\r\n\tlive_feed\x10\x01\x12\x0f\n\x0bmarket_info\x10\x02*E\n\x0bRequestMode\x12\x08\n\x04ltpc\x10\x00\x12\x0b\n\x07\x66ull_d5\x10\x01\x12\x11\n\roption_greeks\x10\x02\x12\x0c\n\x08\x66ull_d30\x10\x03*{\n\x0cMarketStatus\x12\x12\n\x0ePRE_OPEN_START\x10\x00\x12\x10\n\x0cPRE_OPEN_END\x10\x01\x12\x0f\n\x0bNORMAL_OPEN\x10\x02\x12\x10\n\x0cNORMAL_CLOSE\x10\x03\x12\x11\n\rCLOSING_START\x10\x04\x12\x0f\n\x0b\x43LOSING_END\x10\x05\x62\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'MarketDataFeedV3_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + DESCRIPTOR._loaded_options = None + _globals['_MARKETINFO_SEGMENTSTATUSENTRY']._loaded_options = None + _globals['_MARKETINFO_SEGMENTSTATUSENTRY']._serialized_options = b'8\001' + _globals['_FEEDRESPONSE_FEEDSENTRY']._loaded_options = None + _globals['_FEEDRESPONSE_FEEDSENTRY']._serialized_options = b'8\001' + _globals['_TYPE']._serialized_start=2524 + _globals['_TYPE']._serialized_end=2580 + _globals['_REQUESTMODE']._serialized_start=2582 + _globals['_REQUESTMODE']._serialized_end=2651 + _globals['_MARKETSTATUS']._serialized_start=2653 + _globals['_MARKETSTATUS']._serialized_end=2776 + _globals['_LTPC']._serialized_start=72 + _globals['_LTPC']._serialized_end=116 + _globals['_MARKETLEVEL']._serialized_start=118 + _globals['_MARKETLEVEL']._serialized_end=205 + _globals['_MARKETOHLC']._serialized_start=207 + _globals['_MARKETOHLC']._serialized_end=285 + _globals['_QUOTE']._serialized_start=287 + _globals['_QUOTE']._serialized_end=350 + _globals['_OPTIONGREEKS']._serialized_start=352 + _globals['_OPTIONGREEKS']._serialized_end=438 + _globals['_OHLC']._serialized_start=440 + _globals['_OHLC']._serialized_end=545 + _globals['_MARKETFULLFEED']._serialized_start=548 + _globals['_MARKETFULLFEED']._serialized_end=946 + _globals['_INDEXFULLFEED']._serialized_start=949 + _globals['_INDEXFULLFEED']._serialized_end=1108 + _globals['_FULLFEED']._serialized_start=1111 + _globals['_FULLFEED']._serialized_end=1300 + _globals['_FIRSTLEVELWITHGREEKS']._serialized_start=1303 + _globals['_FIRSTLEVELWITHGREEKS']._serialized_end=1583 + _globals['_FEED']._serialized_start=1586 + _globals['_FEED']._serialized_end=1929 + _globals['_MARKETINFO']._serialized_start=1932 + _globals['_MARKETINFO']._serialized_end=2158 + _globals['_MARKETINFO_SEGMENTSTATUSENTRY']._serialized_start=2046 + _globals['_MARKETINFO_SEGMENTSTATUSENTRY']._serialized_end=2158 + _globals['_FEEDRESPONSE']._serialized_start=2161 + _globals['_FEEDRESPONSE']._serialized_end=2522 + _globals['_FEEDRESPONSE_FEEDSENTRY']._serialized_start=2426 + _globals['_FEEDRESPONSE_FEEDSENTRY']._serialized_end=2522 +# @@protoc_insertion_point(module_scope) diff --git a/examples/websocket/market_data/v3/README.md b/examples/websocket/market_data/v3/README.md new file mode 100644 index 0000000..5e83e3f --- /dev/null +++ b/examples/websocket/market_data/v3/README.md @@ -0,0 +1,103 @@ +# Market Stream feed websocket client + +This Python project demonstrates how to connect to the Upstox Websocket API for streaming live market data. It fetches market data for a list of instrument keys and decodes the incoming protobuf data to a JSON format. + +## Getting Started + +These instructions will help you run the sample websocket client. + +### Prerequisites + +Before you can run this script, you need to have Python 3.8 or later installed on your system. If you haven't installed Python yet, you can download it from the official website: + +[Download Python](https://www.python.org/downloads/) + +You will also need to install several Python packages: + +- `websockets` +- `asyncio` +- `protobuf` +- `requests` + + +You can install these packages using pip, a package manager for Python. Open a terminal and enter the following command: + +```sh +pip install websockets asyncio protobuf requests +``` + +### Protocol Buffers (Protobuf) Classes Generation + +Generate the Protobuf classes in Python from `.proto` file. + +Before you can generate the Protobuf classes, you need to download the [proto file](https://assets.upstox.com/feed/market-data-feed/v3/MarketDataFeed.proto) and install the Protocol Buffers compiler (protoc). + +To download the Protocol Buffers compiler, go to the [Google Protocol Buffers GitHub repository](https://github.com/protocolbuffers/protobuf/releases) and download the appropriate `protoc--.zip` file for your operating system. Extract the ZIP file and add the `bin` directory to your system PATH. + +For example, on a Unix-like system, you can add the directory to your PATH like this: + +```bash +export PATH=$PATH:/path/to/protoc/bin +``` + +You can confirm that the compiler is correctly installed by opening a new terminal window and running the following command: + +``` +protoc --version +``` + +This should print the protoc version. + +#### Generate Protobuf classes + +Navigate to the directory containing your .proto files and run the following command: + +``` +protoc --python_out=. *.proto +``` + +This will generate .py files for each .proto file in the directory. + +In your Python code, you can now import the generated classes like any other Python module. For example, if you have a file MarketDataFeedV3.proto and you've generated MarketDataFeedV3_pb2.py, you can import it like this: + +``` +import MarketDataFeedV3_pb2 as pb +``` + +Sample class (MarketDataFeedV3_pb2.py) included as part of this repo. + +### Configuration + +The script requires an Upstox API access token for authorization. You will need to specify your Upstox API access token in the Python script. Look for the line below and replace 'ACCESS_TOKEN' with your actual access token. + +``` +access_token = 'ACCESS_TOKEN' +``` + +### Running the Script + +After installing the prerequisites and setting up your access token, you can run the script. Navigate to the directory containing the script and run the following command: + +``` +python3 websocket_client.py +``` + +Replace websocket_client.py with the name of your Python script. + +## Understanding the Code + +The script first sets up an SSL context. It then fetches the authorized redirect URI from the Upstox server using a valid access token and utilizes this URI to establish a connection with the WebSocket server. + +The script sends a subscription request for "NSE_INDEX|Nifty Bank" and "NSE_INDEX|Nifty 50". When it receives data from the server, it decodes the protobuf data into a FeedResponse object, converts this object into a dictionary, and then prints the dictionary. + +## Support + +If you encounter any problems or have any questions about this project, feel free to post it on our [Developer Community](https://community.upstox.com/c/developer-api/15). + +## Disclaimer + +This is a sample script meant for educational purposes. It may require modifications to work with your specific requirements. + +Please replace `'ACCESS_TOKEN'` with your actual access token and `websocket_client.py` with the name of your Python script. Modify any other details as needed to fit your project. + + diff --git a/examples/websocket/market_data/v3/websocket_client.py b/examples/websocket/market_data/v3/websocket_client.py new file mode 100644 index 0000000..aec5a67 --- /dev/null +++ b/examples/websocket/market_data/v3/websocket_client.py @@ -0,0 +1,74 @@ +# Import necessary modules +import asyncio +import json +import ssl +import websockets +import requests +from google.protobuf.json_format import MessageToDict + +import MarketDataFeedV3_pb2 as pb + + +def get_market_data_feed_authorize_v3(): + """Get authorization for market data feed.""" + access_token = 'ACCESS_TOKEN' + headers = { + 'Accept': 'application/json', + 'Authorization': f'Bearer {access_token}' + } + url = 'https://api.upstox.com/v3/feed/market-data-feed/authorize' + api_response = requests.get(url=url, headers=headers) + return api_response.json() + + +def decode_protobuf(buffer): + """Decode protobuf message.""" + feed_response = pb.FeedResponse() + feed_response.ParseFromString(buffer) + return feed_response + + +async def fetch_market_data(): + """Fetch market data using WebSocket and print it.""" + + # Create default SSL context + ssl_context = ssl.create_default_context() + ssl_context.check_hostname = False + ssl_context.verify_mode = ssl.CERT_NONE + + # Get market data feed authorization + response = get_market_data_feed_authorize_v3() + # Connect to the WebSocket with SSL context + async with websockets.connect(response["data"]["authorized_redirect_uri"], ssl=ssl_context) as websocket: + print('Connection established') + + await asyncio.sleep(1) # Wait for 1 second + + # Data to be sent over the WebSocket + data = { + "guid": "someguid", + "method": "sub", + "data": { + "mode": "full", + "instrumentKeys": ["NSE_INDEX|Nifty Bank", "NSE_INDEX|Nifty 50"] + } + } + + # Convert data to binary and send over WebSocket + binary_data = json.dumps(data).encode('utf-8') + await websocket.send(binary_data) + + # Continuously receive and decode data from WebSocket + while True: + message = await websocket.recv() + decoded_data = decode_protobuf(message) + + # Convert the decoded data to a dictionary + data_dict = MessageToDict(decoded_data) + + # Print the dictionary representation + print(json.dumps(data_dict)) + + +# Execute the function to fetch market data +asyncio.run(fetch_market_data()) diff --git a/test/sdk_tests/market_basic.py b/test/sdk_tests/market_basic.py index fffe8e7..fa63fdb 100644 --- a/test/sdk_tests/market_basic.py +++ b/test/sdk_tests/market_basic.py @@ -4,7 +4,7 @@ configuration = upstox_client.Configuration() configuration.access_token = data_token.access_token streamer = upstox_client.MarketDataStreamer( - upstox_client.ApiClient(configuration), instrumentKeys=["NSE_EQ|INE528G01035"], mode="full") + upstox_client.ApiClient(configuration), instrumentKeys=["MCX_FO|442169"], mode="full") streamer.auto_reconnect(True, 5, 10) diff --git a/test/sdk_tests/sandbox_sanity.py b/test/sdk_tests/sandbox_sanity.py index 28101d1..7388a5a 100644 --- a/test/sdk_tests/sandbox_sanity.py +++ b/test/sdk_tests/sandbox_sanity.py @@ -53,13 +53,13 @@ except ApiException as e: print("Exception when calling OrderApi->place_order: %s\n" % e.body) -try: - api_response = api_instance.get_order_status(order_id="250121112521183") -except ApiException as e: - json_string = e.body.decode('utf-8') - data_dict = json.loads(json_string) - if data_dict.get('errors')[0].get('errorCode') != "UDAPI100010": - print("order details giving wrong response") +# try: +# api_response = api_instance.get_order_status(order_id="250121112521183") +# except ApiException as e: +# json_string = e.body.decode('utf-8') +# data_dict = json.loads(json_string) +# if data_dict.get('errors')[0].get('errorCode') != "UDAPI100010": +# print("order details giving wrong response") api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) order_id = '2501211126016789' @@ -76,25 +76,25 @@ api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) api_version = '2.0' -try: - # Get order book - api_response = api_instance.get_order_book(api_version) - if api_response.status != "success": - print("get order book giving invalid data") -except ApiException as e: - print("Exception when calling OrderApi->get_order_book: %s\n" % e) +# try: +# # Get order book +# api_response = api_instance.get_order_book(api_version) +# if api_response.status != "success": +# print("get order book giving invalid data") +# except ApiException as e: +# print("Exception when calling OrderApi->get_order_book: %s\n" % e) +# except ValueError as e: +# print(e) -api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration)) -api_version = '2.0' order_id = '25012112309073' -try: - api_response = api_instance.get_order_details(api_version, order_id=order_id) -except ApiException as e: - json_string = e.body.decode('utf-8') - data_dict = json.loads(json_string) - if data_dict.get('errors')[0].get('errorCode') != "UDAPI100010": - print("get order details giving wrong response") +# try: +# api_response = api_instance.get_order_details(api_version, order_id=order_id) +# except ApiException as e: +# json_string = e.body.decode('utf-8') +# data_dict = json.loads(json_string) +# if data_dict.get('errors')[0].get('errorCode') != "UDAPI100010": +# print("get order details giving wrong response") api_instance = upstox_client.OrderApiV3(upstox_client.ApiClient(configuration)) body = upstox_client.PlaceOrderV3Request(quantity=1, product="D",validity="DAY", price=9.12, tag="string", instrument_token="NSE_EQ|INE669E01016", order_type="LIMIT",transaction_type="BUY", disclosed_quantity=0, trigger_price=0.0, is_amo=True, slice=True) diff --git a/upstox_client/api_client.py b/upstox_client/api_client.py index e7f5fc5..6ca1a9b 100644 --- a/upstox_client/api_client.py +++ b/upstox_client/api_client.py @@ -319,6 +319,10 @@ def call_api(self, resource_path, method, If parameter async_req is False or missing, then the method will return the response directly. """ + + if self.configuration.sandbox and (not self.configuration.sandbox_urls.__contains__(resource_path)): + raise ValueError(f'URL {resource_path} is not allowed for sandbox.') + if not async_req: return self.__call_api(resource_path, method, path_params, query_params, header_params, diff --git a/upstox_client/configuration.py b/upstox_client/configuration.py index 41b4aa1..37f768f 100644 --- a/upstox_client/configuration.py +++ b/upstox_client/configuration.py @@ -46,6 +46,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): def __init__(self, sandbox=False): """Constructor""" + + self.sandbox = sandbox # Default Base url if sandbox: self.host = "https://api-sandbox.upstox.com" @@ -111,6 +113,17 @@ def __init__(self, sandbox=False): # Safe chars for path_param self.safe_chars_for_path_param = '' + # valid sandbox endpoints + self.sandbox_urls = { + "/v2/order/place", + "/v2/order/modify", + "/v2/order/cancel", + "/v2/order/multi/place", + "/v3/order/place", + "/v3/order/modify", + "/v3/order/cancel", + } + @property def logger_file(self): """The logger file. From c92f787fcc5fc9c2c181913618db28b7ba8839ad Mon Sep 17 00:00:00 2001 From: KETAN GUPTA Date: Mon, 27 Jan 2025 13:40:39 +0530 Subject: [PATCH 4/7] added v3 url for websocket APIs --- upstox_client/api/websocket_api.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/upstox_client/api/websocket_api.py b/upstox_client/api/websocket_api.py index 9b6bc73..5447471 100644 --- a/upstox_client/api/websocket_api.py +++ b/upstox_client/api/websocket_api.py @@ -99,9 +99,13 @@ def get_market_data_feed_with_http_info(self, api_version, **kwargs): # noqa: E query_params = [] + resource_path = '/v3/feed/market-data-feed' header_params = {} if 'api_version' in params: - header_params['Api-Version'] = params['api_version'] # noqa: E501 + header_params['Api-Version'] = params['api_version'] # noqa: E501 + if params['api_version'] == "2.0": + resource_path = '/v2/feed/market-data-feed' + form_params = [] local_var_files = {} @@ -115,7 +119,7 @@ def get_market_data_feed_with_http_info(self, api_version, **kwargs): # noqa: E auth_settings = ['OAUTH2'] # noqa: E501 return self.api_client.call_api( - '/v2/feed/market-data-feed', 'GET', + resource_path, 'GET', path_params, query_params, header_params, @@ -194,9 +198,12 @@ def get_market_data_feed_authorize_with_http_info(self, api_version, **kwargs): query_params = [] + resource_path = '/v3/feed/market-data-feed/authorize' header_params = {} if 'api_version' in params: - header_params['Api-Version'] = params['api_version'] # noqa: E501 + header_params['Api-Version'] = params['api_version'] # noqa: E501 + if params['api_version'] == "2.0": + resource_path = '/v2/feed/market-data-feed/authorize' form_params = [] local_var_files = {} @@ -209,8 +216,7 @@ def get_market_data_feed_authorize_with_http_info(self, api_version, **kwargs): # Authentication setting auth_settings = ['OAUTH2'] # noqa: E501 - return self.api_client.call_api( - '/v2/feed/market-data-feed/authorize', 'GET', + return self.api_client.call_api(resource_path, 'GET', path_params, query_params, header_params, From 6da13439f1cd9ae66e34ec3ffc16d8162870c9b8 Mon Sep 17 00:00:00 2001 From: KETAN GUPTA Date: Mon, 27 Jan 2025 16:36:43 +0530 Subject: [PATCH 5/7] added v3 function for websocket --- upstox_client/api/websocket_api.py | 184 +++++++++++++++++++++++++++-- 1 file changed, 173 insertions(+), 11 deletions(-) diff --git a/upstox_client/api/websocket_api.py b/upstox_client/api/websocket_api.py index 5447471..5988c14 100644 --- a/upstox_client/api/websocket_api.py +++ b/upstox_client/api/websocket_api.py @@ -99,13 +99,9 @@ def get_market_data_feed_with_http_info(self, api_version, **kwargs): # noqa: E query_params = [] - resource_path = '/v3/feed/market-data-feed' header_params = {} if 'api_version' in params: - header_params['Api-Version'] = params['api_version'] # noqa: E501 - if params['api_version'] == "2.0": - resource_path = '/v2/feed/market-data-feed' - + header_params['Api-Version'] = params['api_version'] # noqa: E501 form_params = [] local_var_files = {} @@ -119,7 +115,7 @@ def get_market_data_feed_with_http_info(self, api_version, **kwargs): # noqa: E auth_settings = ['OAUTH2'] # noqa: E501 return self.api_client.call_api( - resource_path, 'GET', + '/v2/feed/market-data-feed', 'GET', path_params, query_params, header_params, @@ -198,12 +194,9 @@ def get_market_data_feed_authorize_with_http_info(self, api_version, **kwargs): query_params = [] - resource_path = '/v3/feed/market-data-feed/authorize' header_params = {} if 'api_version' in params: - header_params['Api-Version'] = params['api_version'] # noqa: E501 - if params['api_version'] == "2.0": - resource_path = '/v2/feed/market-data-feed/authorize' + header_params['Api-Version'] = params['api_version'] # noqa: E501 form_params = [] local_var_files = {} @@ -216,7 +209,8 @@ def get_market_data_feed_authorize_with_http_info(self, api_version, **kwargs): # Authentication setting auth_settings = ['OAUTH2'] # noqa: E501 - return self.api_client.call_api(resource_path, 'GET', + return self.api_client.call_api( + '/v2/feed/market-data-feed/authorize', 'GET', path_params, query_params, header_params, @@ -231,6 +225,174 @@ def get_market_data_feed_authorize_with_http_info(self, api_version, **kwargs): _request_timeout=params.get('_request_timeout'), collection_formats=collection_formats) + def get_market_data_feed_v3(self, **kwargs): # noqa: E501 + """Market Data Feed # noqa: E501 + + This API redirects the client to the respective socket endpoint to receive Market updates. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.get_market_data_feed_v3(async_req=True) + >>> result = thread.get() + + :param async_req bool + :return: None + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.get_market_data_feed_with_http_info_v3(**kwargs) # noqa: E501 + else: + (data) = self.get_market_data_feed_with_http_info_v3(**kwargs) # noqa: E501 + return data + + def get_market_data_feed_with_http_info_v3(self, **kwargs): # noqa: E501 + """Market Data Feed # noqa: E501 + + This API redirects the client to the respective socket endpoint to receive Market updates. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.get_market_data_feed_with_http_info_v3(async_req=True) + >>> result = thread.get() + + :param async_req bool + :return: None + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['async_req', '_return_http_data_only', '_preload_content', '_request_timeout'] # noqa: E501 + + params = locals() + for key, val in six.iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method get_market_data_feed" % key + ) + params[key] = val + del params['kwargs'] + + collection_formats = {} + + path_params = {} + + query_params = [] + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['*/*']) # noqa: E501 + + # Authentication setting + auth_settings = ['OAUTH2'] # noqa: E501 + + return self.api_client.call_api( + '/v3/feed/market-data-feed', 'GET', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type=None, # noqa: E501 + auth_settings=auth_settings, + async_req=params.get('async_req'), + _return_http_data_only=params.get('_return_http_data_only'), + _preload_content=params.get('_preload_content', True), + _request_timeout=params.get('_request_timeout'), + collection_formats=collection_formats) + + def get_market_data_feed_authorize_v3(self, **kwargs): # noqa: E501 + """Market Data Feed Authorize # noqa: E501 + + This API provides the functionality to retrieve the socket endpoint URI for Market updates. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.get_market_data_feed_authorize_v3(async_req=True) + >>> result = thread.get() + + :param async_req bool + :return: WebsocketAuthRedirectResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.get_market_data_feed_authorize_with_http_info_v3(**kwargs) # noqa: E501 + else: + (data) = self.get_market_data_feed_authorize_with_http_info_v3(**kwargs) # noqa: E501 + return data + + def get_market_data_feed_authorize_with_http_info_v3(self, **kwargs): # noqa: E501 + """Market Data Feed Authorize # noqa: E501 + + This API provides the functionality to retrieve the socket endpoint URI for Market updates. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.get_market_data_feed_authorize_with_http_info_v3(async_req=True) + >>> result = thread.get() + + :param async_req bool + :return: WebsocketAuthRedirectResponse + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['async_req', '_return_http_data_only', '_preload_content', + '_request_timeout'] # noqa: E501 + + params = locals() + for key, val in six.iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method get_market_data_feed_authorize" % key + ) + params[key] = val + del params['kwargs'] + + collection_formats = {} + + path_params = {} + + query_params = [] + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['*/*', 'application/json']) # noqa: E501 + + # Authentication setting + auth_settings = ['OAUTH2'] # noqa: E501 + + return self.api_client.call_api( + '/v3/feed/market-data-feed/authorize', 'GET', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='WebsocketAuthRedirectResponse', # noqa: E501 + auth_settings=auth_settings, + async_req=params.get('async_req'), + _return_http_data_only=params.get('_return_http_data_only'), + _preload_content=params.get('_preload_content', True), + _request_timeout=params.get('_request_timeout'), + collection_formats=collection_formats) + + def get_portfolio_stream_feed(self, api_version, **kwargs): # noqa: E501 """Portfolio Stream Feed # noqa: E501 From 041ce657d8fc38f3b378dc6dda3ace13ba678da7 Mon Sep 17 00:00:00 2001 From: KETAN GUPTA Date: Mon, 27 Jan 2025 17:15:21 +0530 Subject: [PATCH 6/7] added sandbox example in readme --- README.md | 24 +++++++++++++++++++++ examples/websocket/market_data/README.md | 3 ++- examples/websocket/market_data/v3/README.md | 2 +- test/sdk_tests/sandbox_place_order_v3.py | 14 ++++++++++++ upstox_client/api_client.py | 2 +- 5 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 test/sdk_tests/sandbox_place_order_v3.py diff --git a/README.md b/README.md index 903703c..3236d09 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,30 @@ Then import the package: import upstox_client ``` +## Sandbox Mode +We recommend using the sandbox environment for testing purposes. To enable sandbox mode, set the `sandbox` flag to `True` in the configuration object. + +```python +import upstox_client +from upstox_client.rest import ApiException + +configuration = upstox_client.Configuration(sandbox=True) +configuration.access_token = 'SANDBOX_ACCESS_TOKEN' + +api_instance = upstox_client.OrderApiV3(upstox_client.ApiClient(configuration)) +body = upstox_client.PlaceOrderV3Request(quantity=1, product="D",validity="DAY", price=9.12, tag="string", instrument_token="NSE_EQ|INE669E01016", order_type="LIMIT", + transaction_type="BUY", disclosed_quantity=0, trigger_price=0.0, is_amo=True, slice=True) + +try: + api_response = api_instance.place_order(body) + print(api_response) +except ApiException as e: + print("Exception when calling OrderApi->place_order: %s\n" % e) +``` +To learn more about the sandbox environment and the available sandbox APIs, please visit the [Upstox API documentation - Sandbox](https://upstox.com/developer/api-documentation/sandbox). + + + ## Examples [Sample Implementations](examples/) can be found within `/examples` folder. diff --git a/examples/websocket/market_data/README.md b/examples/websocket/market_data/README.md index ed243c5..b8467c6 100644 --- a/examples/websocket/market_data/README.md +++ b/examples/websocket/market_data/README.md @@ -4,7 +4,8 @@ This Python project demonstrates how to connect to the Upstox Websocket API for ## Getting Started -These instructions will help you run the sample websocket client. +We recommend using the v3 WebSocket over the v2 version for enhanced functionality. For an example, please refer to the [V3 Example](https://github.com/upstox/upstox-nodejs/tree/include-v3-url/examples/websocket/market_data/v3). +These instructions will help you run the sample v2 websocket client. ### Prerequisites diff --git a/examples/websocket/market_data/v3/README.md b/examples/websocket/market_data/v3/README.md index 5e83e3f..10c7aab 100644 --- a/examples/websocket/market_data/v3/README.md +++ b/examples/websocket/market_data/v3/README.md @@ -4,7 +4,7 @@ This Python project demonstrates how to connect to the Upstox Websocket API for ## Getting Started -These instructions will help you run the sample websocket client. +These instructions will help you run the sample v3 websocket client. ### Prerequisites diff --git a/test/sdk_tests/sandbox_place_order_v3.py b/test/sdk_tests/sandbox_place_order_v3.py new file mode 100644 index 0000000..87f2ca3 --- /dev/null +++ b/test/sdk_tests/sandbox_place_order_v3.py @@ -0,0 +1,14 @@ +import upstox_client +from upstox_client.rest import ApiException + +configuration = upstox_client.Configuration(sandbox=True) +configuration.access_token = 'SANDBOX_ACCESS_TOKEN' + +api_instance = upstox_client.OrderApiV3(upstox_client.ApiClient(configuration)) +body = upstox_client.PlaceOrderV3Request(quantity=1, product="D",validity="DAY", price=9.12, tag="string", instrument_token="NSE_EQ|INE669E01016", order_type="LIMIT",transaction_type="BUY", disclosed_quantity=0, trigger_price=0.0, is_amo=True, slice=True) + +try: + api_response = api_instance.place_order(body) + print(api_response) +except ApiException as e: + print("Exception when calling OrderApi->place_order: %s\n" % e) \ No newline at end of file diff --git a/upstox_client/api_client.py b/upstox_client/api_client.py index 6ca1a9b..d3f9714 100644 --- a/upstox_client/api_client.py +++ b/upstox_client/api_client.py @@ -321,7 +321,7 @@ def call_api(self, resource_path, method, """ if self.configuration.sandbox and (not self.configuration.sandbox_urls.__contains__(resource_path)): - raise ValueError(f'URL {resource_path} is not allowed for sandbox.') + raise ValueError('This API is not available in sandbox mode.') if not async_req: return self.__call_api(resource_path, method, From 47bcdabc329493c2b04b2d3b619450dbd96f3b6d Mon Sep 17 00:00:00 2001 From: KETAN GUPTA Date: Mon, 27 Jan 2025 18:32:15 +0530 Subject: [PATCH 7/7] added v3 in readme url --- examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index 4db2020..32cad1e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -6,7 +6,7 @@ Python script to connect to the Upstox Websocket API for streaming live market data. It fetches market data for a list of instrument keys and decodes the incoming protobuf data to a JSON format. -[Market updates using Upstox's websocket](websocket/market_data/) +[Market updates using Upstox's websocket](websocket/market_data/v3) ### Porfolio stream feed