From bdb171f418a0bd517e8f9f83c36556504c9d659b Mon Sep 17 00:00:00 2001 From: ketangupta12 Date: Mon, 1 Jul 2024 13:01:55 +0530 Subject: [PATCH 1/8] added update_types parameter --- .../portfolio-websocket/basic.py | 36 +++++++++++++++++++ upstox_client/feeder/portfolio_data_feeder.py | 29 +++++++++++++-- .../feeder/portfolio_data_streamer.py | 10 ++++-- 3 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 test/websocket-tests/portfolio-websocket/basic.py diff --git a/test/websocket-tests/portfolio-websocket/basic.py b/test/websocket-tests/portfolio-websocket/basic.py new file mode 100644 index 0000000..d8ec7e1 --- /dev/null +++ b/test/websocket-tests/portfolio-websocket/basic.py @@ -0,0 +1,36 @@ +import upstox_client +import websocket + +configuration = upstox_client.Configuration() + +access_token = "access_token" + +configuration.access_token = access_token +streamer = upstox_client.PortfolioDataStreamer(upstox_client.ApiClient(configuration),order_update=False,holding_update=True,position_update=False) + +def on_open(): + print("on open message") + + +def close(a, b): + print(f"on close message {a}") + + +def message(data): + print(f"on message message{data}") + + +def error(er): + print(f"on error message= {er}") + + +def reconnecting(data): + print(f"reconnecting event= {data}") + + +streamer.on("open", on_open) +streamer.on("message", message) +streamer.on("close", close) +streamer.on("reconnecting", reconnecting) +streamer.on("error", error) +streamer.connect() diff --git a/upstox_client/feeder/portfolio_data_feeder.py b/upstox_client/feeder/portfolio_data_feeder.py index 3ddb97d..a67edaa 100644 --- a/upstox_client/feeder/portfolio_data_feeder.py +++ b/upstox_client/feeder/portfolio_data_feeder.py @@ -6,7 +6,8 @@ class PortfolioDataFeeder(Feeder): - def __init__(self, api_client=None, on_open=None, on_message=None, on_error=None, on_close=None): + def __init__(self, api_client=None, on_open=None, on_message=None, on_error=None, on_close=None, order_update=True, + position_update=False, holding_update=False): super().__init__(api_client=api_client) self.api_client = api_client self.on_open = on_open @@ -15,6 +16,9 @@ def __init__(self, api_client=None, on_open=None, on_message=None, on_error=None self.on_close = on_close self.ws = None self.closingCode = -1 + self.order_update = order_update + self.position_update = position_update + self.holding_update = holding_update def connect(self): if self.ws and self.ws.sock: @@ -24,8 +28,8 @@ def connect(self): "cert_reqs": ssl.CERT_NONE, "check_hostname": False, } + ws_url = self.get_websocket_url() - ws_url = "wss://api.upstox.com/v2/feed/portfolio-stream-feed" headers = {'Authorization': self.api_client.configuration.auth_settings().get("OAUTH2")[ "value"]} self.ws = websocket.WebSocketApp(ws_url, @@ -37,3 +41,24 @@ def connect(self): threading.Thread(target=self.ws.run_forever, kwargs={"sslopt": sslopt}).start() + + def get_websocket_url(self): + ws_url = "wss://api.upstox.com/v2/feed/portfolio-stream-feed" + update_types = [] + if self.order_update: + update_types.append("order") + if self.holding_update: + update_types.append("holding") + if self.position_update: + update_types.append("position") + + if len(update_types) >= 1: + ws_url += "?update_types=" + + for i in range(len(update_types) - 1): + ws_url += update_types[i] + "%2C" + + if len(update_types) >= 1: + ws_url += update_types[-1] + + return ws_url diff --git a/upstox_client/feeder/portfolio_data_streamer.py b/upstox_client/feeder/portfolio_data_streamer.py index 3092fa0..d0ce7f7 100644 --- a/upstox_client/feeder/portfolio_data_streamer.py +++ b/upstox_client/feeder/portfolio_data_streamer.py @@ -4,14 +4,19 @@ class PortfolioDataStreamer(Streamer): - def __init__(self, api_client=None): + def __init__(self, api_client=None, order_update=True, position_update=False, holding_update=False): super().__init__(api_client) self.api_client = api_client + self.order_update = order_update + self.position_update = position_update + self.holding_update = holding_update self.feeder = None def connect(self): self.feeder = PortfolioDataFeeder( - api_client=self.api_client, on_open=self.handle_open, on_message=self.handle_message, on_error=self.handle_error, on_close=self.handle_close) + api_client=self.api_client, on_open=self.handle_open, on_message=self.handle_message, + on_error=self.handle_error, on_close=self.handle_close, order_update=self.order_update, + position_update=self.position_update, holding_update=self.holding_update) self.feeder.connect() def handle_open(self, ws): @@ -22,4 +27,3 @@ def handle_open(self, ws): def handle_message(self, ws, message): self.emit(self.Event["MESSAGE"], message) - From 4ee86bd908dd4d5d6937df6d8e25c6631149725b Mon Sep 17 00:00:00 2001 From: ketangupta12 Date: Fri, 5 Jul 2024 11:11:00 +0530 Subject: [PATCH 2/8] PR review changes --- .../market_websocket}/basic.py | 0 .../market_websocket}/disconnect.py | 0 .../market_websocket}/subscribe.py | 0 .../portfolio_websocket}/basic.py | 2 +- upstox_client/api/websocket_api.py | 24 +++++++++++++++++-- upstox_client/feeder/portfolio_data_feeder.py | 10 ++------ 6 files changed, 25 insertions(+), 11 deletions(-) rename test/{websocket-tests/market-websocket => websocket_tests/market_websocket}/basic.py (100%) rename test/{websocket-tests/market-websocket => websocket_tests/market_websocket}/disconnect.py (100%) rename test/{websocket-tests/market-websocket => websocket_tests/market_websocket}/subscribe.py (100%) rename test/{websocket-tests/portfolio-websocket => websocket_tests/portfolio_websocket}/basic.py (89%) diff --git a/test/websocket-tests/market-websocket/basic.py b/test/websocket_tests/market_websocket/basic.py similarity index 100% rename from test/websocket-tests/market-websocket/basic.py rename to test/websocket_tests/market_websocket/basic.py diff --git a/test/websocket-tests/market-websocket/disconnect.py b/test/websocket_tests/market_websocket/disconnect.py similarity index 100% rename from test/websocket-tests/market-websocket/disconnect.py rename to test/websocket_tests/market_websocket/disconnect.py diff --git a/test/websocket-tests/market-websocket/subscribe.py b/test/websocket_tests/market_websocket/subscribe.py similarity index 100% rename from test/websocket-tests/market-websocket/subscribe.py rename to test/websocket_tests/market_websocket/subscribe.py diff --git a/test/websocket-tests/portfolio-websocket/basic.py b/test/websocket_tests/portfolio_websocket/basic.py similarity index 89% rename from test/websocket-tests/portfolio-websocket/basic.py rename to test/websocket_tests/portfolio_websocket/basic.py index d8ec7e1..21d6af6 100644 --- a/test/websocket-tests/portfolio-websocket/basic.py +++ b/test/websocket_tests/portfolio_websocket/basic.py @@ -6,7 +6,7 @@ access_token = "access_token" configuration.access_token = access_token -streamer = upstox_client.PortfolioDataStreamer(upstox_client.ApiClient(configuration),order_update=False,holding_update=True,position_update=False) +streamer = upstox_client.PortfolioDataStreamer(upstox_client.ApiClient(configuration),order_update=True,holding_update=False,position_update=True) def on_open(): print("on open message") diff --git a/upstox_client/api/websocket_api.py b/upstox_client/api/websocket_api.py index e4773e7..3a21636 100644 --- a/upstox_client/api/websocket_api.py +++ b/upstox_client/api/websocket_api.py @@ -31,6 +31,9 @@ def __init__(self, api_client=None): if api_client is None: api_client = ApiClient() self.api_client = api_client + self.order_update = True + self.holding_update = False + self.position_update = False def get_market_data_feed(self, api_version, **kwargs): # noqa: E501 """Market Data Feed # noqa: E501 @@ -317,7 +320,7 @@ def get_portfolio_stream_feed_with_http_info(self, api_version, **kwargs): # no _request_timeout=params.get('_request_timeout'), collection_formats=collection_formats) - def get_portfolio_stream_feed_authorize(self, api_version, **kwargs): # noqa: E501 + def get_portfolio_stream_feed_authorize(self, api_version, order_update=True, position_update=False,holding_update=False,**kwargs): # noqa: E501 """Portfolio Stream Feed Authorize # noqa: E501 This API provides the functionality to retrieve the socket endpoint URI for Portfolio updates. # noqa: E501 @@ -332,6 +335,9 @@ def get_portfolio_stream_feed_authorize(self, api_version, **kwargs): # noqa: E If the method is called asynchronously, returns the request thread. """ + self.position_update = position_update + self.holding_update = holding_update + self.order_update = order_update kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): return self.get_portfolio_stream_feed_authorize_with_http_info(api_version, **kwargs) # noqa: E501 @@ -397,7 +403,7 @@ def get_portfolio_stream_feed_authorize_with_http_info(self, api_version, **kwar auth_settings = ['OAUTH2'] # noqa: E501 return self.api_client.call_api( - '/feed/portfolio-stream-feed/authorize', 'GET', + '/feed/portfolio-stream-feed/authorize' + self.get_websocket_parameters(), 'GET', path_params, query_params, header_params, @@ -411,3 +417,17 @@ def get_portfolio_stream_feed_authorize_with_http_info(self, api_version, **kwar _preload_content=params.get('_preload_content', True), _request_timeout=params.get('_request_timeout'), collection_formats=collection_formats) + + def get_websocket_parameters(self): + params = "" + update_types = [] + if self.order_update: + update_types.append("order") + if self.holding_update: + update_types.append("holding") + if self.position_update: + update_types.append("position") + + if update_types: + params += "?update_types=" + "%2C".join(update_types) + return params diff --git a/upstox_client/feeder/portfolio_data_feeder.py b/upstox_client/feeder/portfolio_data_feeder.py index a67edaa..562bddc 100644 --- a/upstox_client/feeder/portfolio_data_feeder.py +++ b/upstox_client/feeder/portfolio_data_feeder.py @@ -52,13 +52,7 @@ def get_websocket_url(self): if self.position_update: update_types.append("position") - if len(update_types) >= 1: - ws_url += "?update_types=" - - for i in range(len(update_types) - 1): - ws_url += update_types[i] + "%2C" - - if len(update_types) >= 1: - ws_url += update_types[-1] + if update_types: + ws_url += "?update_types=" + "%2C".join(update_types) return ws_url From 3f104b51d2343eb2365aa76a8b4a4f9eb75e5757 Mon Sep 17 00:00:00 2001 From: ketangupta12 Date: Wed, 31 Jul 2024 17:40:39 +0530 Subject: [PATCH 3/8] removed websocket local tests --- .../websocket_tests/market_websocket/basic.py | 37 ------------ .../market_websocket/disconnect.py | 60 ------------------- .../market_websocket/subscribe.py | 0 .../portfolio_websocket/basic.py | 36 ----------- 4 files changed, 133 deletions(-) delete mode 100644 test/websocket_tests/market_websocket/basic.py delete mode 100644 test/websocket_tests/market_websocket/disconnect.py delete mode 100644 test/websocket_tests/market_websocket/subscribe.py delete mode 100644 test/websocket_tests/portfolio_websocket/basic.py diff --git a/test/websocket_tests/market_websocket/basic.py b/test/websocket_tests/market_websocket/basic.py deleted file mode 100644 index d300e2b..0000000 --- a/test/websocket_tests/market_websocket/basic.py +++ /dev/null @@ -1,37 +0,0 @@ -import upstox_client -import data_token - -configuration = upstox_client.Configuration() -configuration.access_token = data_token.access_token -streamer = upstox_client.MarketDataStreamer( - upstox_client.ApiClient(configuration), instrumentKeys=["MCX_FO|426302", "NSE_EQ|INE528G01035"], mode="full") - -streamer.auto_reconnect(True, 5, 10) - - -def on_open(): - print("on open message") - - -def close(a, b): - print(f"on close message {a}") - - -def message(data): - print(f"on message message{data}") - - -def error(er): - print(f"on error message= {er}") - - -def reconnecting(data): - print(f"reconnecting event= {data}") - - -streamer.on("open", on_open) -streamer.on("message", message) -streamer.on("close", close) -streamer.on("reconnecting", reconnecting) -streamer.on("error", error) -streamer.connect() diff --git a/test/websocket_tests/market_websocket/disconnect.py b/test/websocket_tests/market_websocket/disconnect.py deleted file mode 100644 index c49ecf6..0000000 --- a/test/websocket_tests/market_websocket/disconnect.py +++ /dev/null @@ -1,60 +0,0 @@ - -import time -import threading -import upstox_client - -logging.basicConfig(level=logging.DEBUG) -configuration = upstox_client.Configuration() -access_token = "your_access_token" -configuration.access_token = access_token -streamer = upstox_client.MarketDataStreamer( - upstox_client.ApiClient(configuration), instrumentKeys=["MCX_FO|426302"], mode="full") - - -streamer.auto_reconnect(True, 5, 10) -def on_open(): - print("on open message") - -def close(a, b): - print(f"on close message {a}") - - -def message(data): - print(f"on message message{data}") - - -def error(er): - print(f"on error message= {er}") - -def add_subsriptions(): - time.sleep(5) - streamer.subscribe(["NSE_EQ|INE528G01035"], "full") - -def disconnection(): - time.sleep(10) - streamer.disconnect() - -def f_disconnection(): - time.sleep(15) - streamer.disconnect() - -def reconnecting(data): - print(f"reconnecting event= {data}") - -streamer.on("open", on_open) -streamer.on("message", message) -streamer.on("close", close) -streamer.on("reconnecting", reconnecting) -streamer.on("error", error) -# streamer.connect() -print("hello") - -t1 = threading.Thread(target=streamer.connect) -t2 = threading.Thread(target=add_subsriptions) -t3 = threading.Thread(target=disconnection) -t4 = threading.Thread(target=f_disconnection) -t1.start() -t2.start() -t3.start() -t4.start() - diff --git a/test/websocket_tests/market_websocket/subscribe.py b/test/websocket_tests/market_websocket/subscribe.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/websocket_tests/portfolio_websocket/basic.py b/test/websocket_tests/portfolio_websocket/basic.py deleted file mode 100644 index 21d6af6..0000000 --- a/test/websocket_tests/portfolio_websocket/basic.py +++ /dev/null @@ -1,36 +0,0 @@ -import upstox_client -import websocket - -configuration = upstox_client.Configuration() - -access_token = "access_token" - -configuration.access_token = access_token -streamer = upstox_client.PortfolioDataStreamer(upstox_client.ApiClient(configuration),order_update=True,holding_update=False,position_update=True) - -def on_open(): - print("on open message") - - -def close(a, b): - print(f"on close message {a}") - - -def message(data): - print(f"on message message{data}") - - -def error(er): - print(f"on error message= {er}") - - -def reconnecting(data): - print(f"reconnecting event= {data}") - - -streamer.on("open", on_open) -streamer.on("message", message) -streamer.on("close", close) -streamer.on("reconnecting", reconnecting) -streamer.on("error", error) -streamer.connect() From cd8003c8b0c7e3af37347a264ab32fea4c1c9440 Mon Sep 17 00:00:00 2001 From: ketangupta12 Date: Wed, 31 Jul 2024 18:16:26 +0530 Subject: [PATCH 4/8] updated readme file and adding swagger tests --- README.md | 79 +++++--- docs/ExchangeTimingData.md | 11 + docs/GetExchangeTimingResponse.md | 10 + docs/GetHolidayResponse.md | 10 + docs/GetMarketStatusResponse.md | 10 + docs/GetOptionChainResponse.md | 10 + docs/GetOptionContractResponse.md | 10 + docs/HolidayData.md | 13 ++ docs/InstrumentData.md | 44 ++++ docs/MarketData.md | 17 ++ docs/MarketHolidaysAndTimingsApi.md | 203 +++++++++++++++++++ docs/MarketStatusData.md | 11 + docs/OptionStrikeData.md | 15 ++ docs/OptionsApi.md | 117 +++++++++++ docs/PutCallOptionChainData.md | 11 + setup.py | 2 +- test/test_analytics_data.py | 39 ++++ test/test_exchange_timing_data.py | 39 ++++ test/test_get_exchange_timing_response.py | 39 ++++ test/test_get_holiday_response.py | 39 ++++ test/test_get_market_status_response.py | 39 ++++ test/test_get_option_chain_response.py | 39 ++++ test/test_get_option_contract_response.py | 39 ++++ test/test_holiday_data.py | 39 ++++ test/test_instrument_data.py | 39 ++++ test/test_market_data.py | 39 ++++ test/test_market_holidays_and_timings_api.py | 61 ++++++ test/test_market_status_data.py | 39 ++++ test/test_option_strike_data.py | 39 ++++ test/test_options_api.py | 47 +++++ test/test_put_call_option_chain_data.py | 39 ++++ 31 files changed, 1157 insertions(+), 31 deletions(-) create mode 100644 docs/ExchangeTimingData.md create mode 100644 docs/GetExchangeTimingResponse.md create mode 100644 docs/GetHolidayResponse.md create mode 100644 docs/GetMarketStatusResponse.md create mode 100644 docs/GetOptionChainResponse.md create mode 100644 docs/GetOptionContractResponse.md create mode 100644 docs/HolidayData.md create mode 100644 docs/InstrumentData.md create mode 100644 docs/MarketData.md create mode 100644 docs/MarketHolidaysAndTimingsApi.md create mode 100644 docs/MarketStatusData.md create mode 100644 docs/OptionStrikeData.md create mode 100644 docs/OptionsApi.md create mode 100644 docs/PutCallOptionChainData.md create mode 100644 test/test_analytics_data.py create mode 100644 test/test_exchange_timing_data.py create mode 100644 test/test_get_exchange_timing_response.py create mode 100644 test/test_get_holiday_response.py create mode 100644 test/test_get_market_status_response.py create mode 100644 test/test_get_option_chain_response.py create mode 100644 test/test_get_option_contract_response.py create mode 100644 test/test_holiday_data.py create mode 100644 test/test_instrument_data.py create mode 100644 test/test_market_data.py create mode 100644 test/test_market_holidays_and_timings_api.py create mode 100644 test/test_market_status_data.py create mode 100644 test/test_option_strike_data.py create mode 100644 test/test_options_api.py create mode 100644 test/test_put_call_option_chain_data.py diff --git a/README.md b/README.md index 7112685..abfdd8d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The official Python client for communicating with the get_exchange_timings: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **_date** | **str**| | + +### Return type + +[**GetExchangeTimingResponse**](GetExchangeTimingResponse.md) + +### Authorization + +No authorization required + +### 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_holiday** +> GetHolidayResponse get_holiday(_date) + +Get Holiday on particular date + +This API provides the functionality to retrieve the holiday on particular date + +### Example +```python +from __future__ import print_function +import time +import swagger_client +from swagger_client.rest import ApiException +from pprint import pprint + +# create an instance of the API class +api_instance = swagger_client.MarketHolidaysAndTimingsApi() +_date = '_date_example' # str | + +try: + # Get Holiday on particular date + api_response = api_instance.get_holiday(_date) + pprint(api_response) +except ApiException as e: + print("Exception when calling MarketHolidaysAndTimingsApi->get_holiday: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **_date** | **str**| | + +### Return type + +[**GetHolidayResponse**](GetHolidayResponse.md) + +### Authorization + +No authorization required + +### 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_holidays** +> GetHolidayResponse get_holidays() + +Get Holiday list of current year + +This API provides the functionality to retrieve the holiday list of current year + +### Example +```python +from __future__ import print_function +import time +import swagger_client +from swagger_client.rest import ApiException +from pprint import pprint + +# create an instance of the API class +api_instance = swagger_client.MarketHolidaysAndTimingsApi() + +try: + # Get Holiday list of current year + api_response = api_instance.get_holidays() + pprint(api_response) +except ApiException as e: + print("Exception when calling MarketHolidaysAndTimingsApi->get_holidays: %s\n" % e) +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**GetHolidayResponse**](GetHolidayResponse.md) + +### Authorization + +No authorization required + +### 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_market_status** +> GetMarketStatusResponse get_market_status(exchange) + +Get Market status for particular exchange + +This API provides the functionality to retrieve the market status for particular exchange + +### Example +```python +from __future__ import print_function +import time +import swagger_client +from swagger_client.rest import ApiException +from pprint import pprint + +# Configure OAuth2 access token for authorization: OAUTH2 +configuration = swagger_client.Configuration() +configuration.access_token = 'YOUR_ACCESS_TOKEN' + +# create an instance of the API class +api_instance = swagger_client.MarketHolidaysAndTimingsApi(swagger_client.ApiClient(configuration)) +exchange = 'exchange_example' # str | + +try: + # Get Market status for particular exchange + api_response = api_instance.get_market_status(exchange) + pprint(api_response) +except ApiException as e: + print("Exception when calling MarketHolidaysAndTimingsApi->get_market_status: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **exchange** | **str**| | + +### Return type + +[**GetMarketStatusResponse**](GetMarketStatusResponse.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) + diff --git a/docs/MarketStatusData.md b/docs/MarketStatusData.md new file mode 100644 index 0000000..7a03e13 --- /dev/null +++ b/docs/MarketStatusData.md @@ -0,0 +1,11 @@ +# MarketStatusData + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**exchange** | **str** | | [optional] +**status** | **str** | | [optional] +**last_updated** | **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/OptionStrikeData.md b/docs/OptionStrikeData.md new file mode 100644 index 0000000..b3c4924 --- /dev/null +++ b/docs/OptionStrikeData.md @@ -0,0 +1,15 @@ +# OptionStrikeData + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**expiry** | **datetime** | | [optional] +**pcr** | **float** | | [optional] +**strike_price** | **float** | | [optional] +**underlying_key** | **str** | | [optional] +**underlying_spot_price** | **float** | | [optional] +**call_options** | [**PutCallOptionChainData**](PutCallOptionChainData.md) | | [optional] +**put_options** | [**PutCallOptionChainData**](PutCallOptionChainData.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/docs/OptionsApi.md b/docs/OptionsApi.md new file mode 100644 index 0000000..2b50350 --- /dev/null +++ b/docs/OptionsApi.md @@ -0,0 +1,117 @@ +# swagger_client.OptionsApi + +All URIs are relative to *https://api-v2.upstox.com* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**get_option_contracts**](OptionsApi.md#get_option_contracts) | **GET** /v2/option/contract | Get option contracts +[**get_put_call_option_chain**](OptionsApi.md#get_put_call_option_chain) | **GET** /v2/option/chain | Get option chain + +# **get_option_contracts** +> GetOptionContractResponse get_option_contracts(instrument_key, expiry_date=expiry_date) + +Get option contracts + +This API provides the functionality to retrieve the option contracts + +### Example +```python +from __future__ import print_function +import time +import swagger_client +from swagger_client.rest import ApiException +from pprint import pprint + +# Configure OAuth2 access token for authorization: OAUTH2 +configuration = swagger_client.Configuration() +configuration.access_token = 'YOUR_ACCESS_TOKEN' + +# create an instance of the API class +api_instance = swagger_client.OptionsApi(swagger_client.ApiClient(configuration)) +instrument_key = 'instrument_key_example' # str | Instrument key for an underlying symbol +expiry_date = 'expiry_date_example' # str | Expiry date in format: YYYY-mm-dd (optional) + +try: + # Get option contracts + api_response = api_instance.get_option_contracts(instrument_key, expiry_date=expiry_date) + pprint(api_response) +except ApiException as e: + print("Exception when calling OptionsApi->get_option_contracts: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **instrument_key** | **str**| Instrument key for an underlying symbol | + **expiry_date** | **str**| Expiry date in format: YYYY-mm-dd | [optional] + +### Return type + +[**GetOptionContractResponse**](GetOptionContractResponse.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_put_call_option_chain** +> GetOptionChainResponse get_put_call_option_chain(instrument_key, expiry_date) + +Get option chain + +This API provides the functionality to retrieve the option chain + +### Example +```python +from __future__ import print_function +import time +import swagger_client +from swagger_client.rest import ApiException +from pprint import pprint + +# Configure OAuth2 access token for authorization: OAUTH2 +configuration = swagger_client.Configuration() +configuration.access_token = 'YOUR_ACCESS_TOKEN' + +# create an instance of the API class +api_instance = swagger_client.OptionsApi(swagger_client.ApiClient(configuration)) +instrument_key = 'instrument_key_example' # str | Instrument key for an underlying symbol +expiry_date = 'expiry_date_example' # str | Expiry date in format: YYYY-mm-dd + +try: + # Get option chain + api_response = api_instance.get_put_call_option_chain(instrument_key, expiry_date) + pprint(api_response) +except ApiException as e: + print("Exception when calling OptionsApi->get_put_call_option_chain: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **instrument_key** | **str**| Instrument key for an underlying symbol | + **expiry_date** | **str**| Expiry date in format: YYYY-mm-dd | + +### Return type + +[**GetOptionChainResponse**](GetOptionChainResponse.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) + diff --git a/docs/PutCallOptionChainData.md b/docs/PutCallOptionChainData.md new file mode 100644 index 0000000..a69d5cc --- /dev/null +++ b/docs/PutCallOptionChainData.md @@ -0,0 +1,11 @@ +# PutCallOptionChainData + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**instrument_key** | **str** | | [optional] +**market_data** | [**MarketData**](MarketData.md) | | [optional] +**option_greeks** | [**AnalyticsData**](AnalyticsData.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 6c35de2..a45eba8 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.4.3" +VERSION = "2.4.4" # To install the library, run the following # # python setup.py install diff --git a/test/test_analytics_data.py b/test/test_analytics_data.py new file mode 100644 index 0000000..448c45c --- /dev/null +++ b/test/test_analytics_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 swagger_client +from swagger_client.models.analytics_data import AnalyticsData # noqa: E501 +from swagger_client.rest import ApiException + + +class TestAnalyticsData(unittest.TestCase): + """AnalyticsData unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAnalyticsData(self): + """Test AnalyticsData""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.analytics_data.AnalyticsData() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_exchange_timing_data.py b/test/test_exchange_timing_data.py new file mode 100644 index 0000000..3863c86 --- /dev/null +++ b/test/test_exchange_timing_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 swagger_client +from swagger_client.models.exchange_timing_data import ExchangeTimingData # noqa: E501 +from swagger_client.rest import ApiException + + +class TestExchangeTimingData(unittest.TestCase): + """ExchangeTimingData unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testExchangeTimingData(self): + """Test ExchangeTimingData""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.exchange_timing_data.ExchangeTimingData() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_get_exchange_timing_response.py b/test/test_get_exchange_timing_response.py new file mode 100644 index 0000000..189edb5 --- /dev/null +++ b/test/test_get_exchange_timing_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 swagger_client +from swagger_client.models.get_exchange_timing_response import GetExchangeTimingResponse # noqa: E501 +from swagger_client.rest import ApiException + + +class TestGetExchangeTimingResponse(unittest.TestCase): + """GetExchangeTimingResponse unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testGetExchangeTimingResponse(self): + """Test GetExchangeTimingResponse""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.get_exchange_timing_response.GetExchangeTimingResponse() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_get_holiday_response.py b/test/test_get_holiday_response.py new file mode 100644 index 0000000..18b230c --- /dev/null +++ b/test/test_get_holiday_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 swagger_client +from swagger_client.models.get_holiday_response import GetHolidayResponse # noqa: E501 +from swagger_client.rest import ApiException + + +class TestGetHolidayResponse(unittest.TestCase): + """GetHolidayResponse unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testGetHolidayResponse(self): + """Test GetHolidayResponse""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.get_holiday_response.GetHolidayResponse() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_get_market_status_response.py b/test/test_get_market_status_response.py new file mode 100644 index 0000000..996f218 --- /dev/null +++ b/test/test_get_market_status_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 swagger_client +from swagger_client.models.get_market_status_response import GetMarketStatusResponse # noqa: E501 +from swagger_client.rest import ApiException + + +class TestGetMarketStatusResponse(unittest.TestCase): + """GetMarketStatusResponse unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testGetMarketStatusResponse(self): + """Test GetMarketStatusResponse""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.get_market_status_response.GetMarketStatusResponse() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_get_option_chain_response.py b/test/test_get_option_chain_response.py new file mode 100644 index 0000000..2bc6971 --- /dev/null +++ b/test/test_get_option_chain_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 swagger_client +from swagger_client.models.get_option_chain_response import GetOptionChainResponse # noqa: E501 +from swagger_client.rest import ApiException + + +class TestGetOptionChainResponse(unittest.TestCase): + """GetOptionChainResponse unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testGetOptionChainResponse(self): + """Test GetOptionChainResponse""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.get_option_chain_response.GetOptionChainResponse() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_get_option_contract_response.py b/test/test_get_option_contract_response.py new file mode 100644 index 0000000..84a4e9c --- /dev/null +++ b/test/test_get_option_contract_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 swagger_client +from swagger_client.models.get_option_contract_response import GetOptionContractResponse # noqa: E501 +from swagger_client.rest import ApiException + + +class TestGetOptionContractResponse(unittest.TestCase): + """GetOptionContractResponse unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testGetOptionContractResponse(self): + """Test GetOptionContractResponse""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.get_option_contract_response.GetOptionContractResponse() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_holiday_data.py b/test/test_holiday_data.py new file mode 100644 index 0000000..63293ca --- /dev/null +++ b/test/test_holiday_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 swagger_client +from swagger_client.models.holiday_data import HolidayData # noqa: E501 +from swagger_client.rest import ApiException + + +class TestHolidayData(unittest.TestCase): + """HolidayData unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testHolidayData(self): + """Test HolidayData""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.holiday_data.HolidayData() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_instrument_data.py b/test/test_instrument_data.py new file mode 100644 index 0000000..d7878aa --- /dev/null +++ b/test/test_instrument_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 swagger_client +from swagger_client.models.instrument_data import InstrumentData # noqa: E501 +from swagger_client.rest import ApiException + + +class TestInstrumentData(unittest.TestCase): + """InstrumentData unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testInstrumentData(self): + """Test InstrumentData""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.instrument_data.InstrumentData() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_market_data.py b/test/test_market_data.py new file mode 100644 index 0000000..86b72f9 --- /dev/null +++ b/test/test_market_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 swagger_client +from swagger_client.models.market_data import MarketData # noqa: E501 +from swagger_client.rest import ApiException + + +class TestMarketData(unittest.TestCase): + """MarketData unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testMarketData(self): + """Test MarketData""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.market_data.MarketData() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_market_holidays_and_timings_api.py b/test/test_market_holidays_and_timings_api.py new file mode 100644 index 0000000..d76b688 --- /dev/null +++ b/test/test_market_holidays_and_timings_api.py @@ -0,0 +1,61 @@ +# 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 swagger_client +from swagger_client.api.market_holidays_and_timings_api import MarketHolidaysAndTimingsApi # noqa: E501 +from swagger_client.rest import ApiException + + +class TestMarketHolidaysAndTimingsApi(unittest.TestCase): + """MarketHolidaysAndTimingsApi unit test stubs""" + + def setUp(self): + self.api = MarketHolidaysAndTimingsApi() # noqa: E501 + + def tearDown(self): + pass + + def test_get_exchange_timings(self): + """Test case for get_exchange_timings + + Get Exchange Timings on particular date # noqa: E501 + """ + pass + + def test_get_holiday(self): + """Test case for get_holiday + + Get Holiday on particular date # noqa: E501 + """ + pass + + def test_get_holidays(self): + """Test case for get_holidays + + Get Holiday list of current year # noqa: E501 + """ + pass + + def test_get_market_status(self): + """Test case for get_market_status + + Get Market status for particular exchange # noqa: E501 + """ + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_market_status_data.py b/test/test_market_status_data.py new file mode 100644 index 0000000..80982b9 --- /dev/null +++ b/test/test_market_status_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 swagger_client +from swagger_client.models.market_status_data import MarketStatusData # noqa: E501 +from swagger_client.rest import ApiException + + +class TestMarketStatusData(unittest.TestCase): + """MarketStatusData unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testMarketStatusData(self): + """Test MarketStatusData""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.market_status_data.MarketStatusData() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_option_strike_data.py b/test/test_option_strike_data.py new file mode 100644 index 0000000..de93e16 --- /dev/null +++ b/test/test_option_strike_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 swagger_client +from swagger_client.models.option_strike_data import OptionStrikeData # noqa: E501 +from swagger_client.rest import ApiException + + +class TestOptionStrikeData(unittest.TestCase): + """OptionStrikeData unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testOptionStrikeData(self): + """Test OptionStrikeData""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.option_strike_data.OptionStrikeData() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_options_api.py b/test/test_options_api.py new file mode 100644 index 0000000..ac71478 --- /dev/null +++ b/test/test_options_api.py @@ -0,0 +1,47 @@ +# 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 swagger_client +from swagger_client.api.options_api import OptionsApi # noqa: E501 +from swagger_client.rest import ApiException + + +class TestOptionsApi(unittest.TestCase): + """OptionsApi unit test stubs""" + + def setUp(self): + self.api = OptionsApi() # noqa: E501 + + def tearDown(self): + pass + + def test_get_option_contracts(self): + """Test case for get_option_contracts + + Get option contracts # noqa: E501 + """ + pass + + def test_get_put_call_option_chain(self): + """Test case for get_put_call_option_chain + + Get option chain # noqa: E501 + """ + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_put_call_option_chain_data.py b/test/test_put_call_option_chain_data.py new file mode 100644 index 0000000..7d67e48 --- /dev/null +++ b/test/test_put_call_option_chain_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 swagger_client +from swagger_client.models.put_call_option_chain_data import PutCallOptionChainData # noqa: E501 +from swagger_client.rest import ApiException + + +class TestPutCallOptionChainData(unittest.TestCase): + """PutCallOptionChainData unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testPutCallOptionChainData(self): + """Test PutCallOptionChainData""" + # FIXME: construct object with mandatory attributes with example values + # model = swagger_client.models.put_call_option_chain_data.PutCallOptionChainData() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() From 0d684ddfa0dd46ff1cd78292219b61e8e3274d0e Mon Sep 17 00:00:00 2001 From: ketangupta12 Date: Thu, 1 Aug 2024 08:29:08 +0530 Subject: [PATCH 5/8] updated git ignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 519fea5..66047e0 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ coverage.xml *,cover .hypothesis/ venv/ +myenv/ .python-version # Translations From a62402bbadde4f99a914ffdede03043ad5377e0a Mon Sep 17 00:00:00 2001 From: ketangupta12 Date: Thu, 1 Aug 2024 09:56:53 +0530 Subject: [PATCH 6/8] added update type example and tests --- README.md | 34 +++++++++++++++++++++++++ test/sdk_tests/place_order.py | 14 ++++++++++ test/sdk_tests/portfolio_update_type.py | 25 ++++++++++++++++++ test/sdk_tests/websocket_api.py | 11 ++++++++ 4 files changed, 84 insertions(+) create mode 100644 test/sdk_tests/place_order.py create mode 100644 test/sdk_tests/portfolio_update_type.py create mode 100644 test/sdk_tests/websocket_api.py diff --git a/README.md b/README.md index abfdd8d..d33948a 100644 --- a/README.md +++ b/README.md @@ -410,6 +410,40 @@ def main(): if __name__ == "__main__": main() ``` +
+ +You can also enable position and holding updates by providing a boolean value to the constructor of `PortfolioDataStreamer` + +```python +import upstox_client +import data_token + + +def on_message(message): + print(message) + + +def on_open(): + print("connection opened") + + +def main(): + configuration = upstox_client.Configuration() + configuration.access_token = + + streamer = upstox_client.PortfolioDataStreamer(upstox_client.ApiClient(configuration),order_update=True,position_update=True,holding_update=True) + + streamer.on("message", on_message) + streamer.on("open", on_open) + streamer.connect() + + +if __name__ == "__main__": + main() + +``` + +
This example demonstrates initializing the PortfolioDataStreamer, connecting it to the WebSocket, and setting up an event listener to receive and print order updates. Replace with your valid access token to authenticate the session. diff --git a/test/sdk_tests/place_order.py b/test/sdk_tests/place_order.py new file mode 100644 index 0000000..f435136 --- /dev/null +++ b/test/sdk_tests/place_order.py @@ -0,0 +1,14 @@ +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.OrderApi(upstox_client.ApiClient(configuration)) +body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 0.0, "string", "NSE_EQ|INE669E01016", "MARKET", "BUY", 0, 0.0, False) +api_version = '2.0' +try: + api_response = api_instance.place_order(body, api_version) + 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/portfolio_update_type.py b/test/sdk_tests/portfolio_update_type.py new file mode 100644 index 0000000..9f6aa63 --- /dev/null +++ b/test/sdk_tests/portfolio_update_type.py @@ -0,0 +1,25 @@ +import upstox_client +import data_token + + +def on_message(message): + print(message) + + +def on_open(): + print("connection opened") + + +def main(): + configuration = upstox_client.Configuration() + configuration.access_token = data_token.access_token + + streamer = upstox_client.PortfolioDataStreamer(upstox_client.ApiClient(configuration),order_update=True,position_update=True,holding_update=True) + + streamer.on("message", on_message) + streamer.on("open", on_open) + streamer.connect() + + +if __name__ == "__main__": + main() diff --git a/test/sdk_tests/websocket_api.py b/test/sdk_tests/websocket_api.py new file mode 100644 index 0000000..519f78f --- /dev/null +++ b/test/sdk_tests/websocket_api.py @@ -0,0 +1,11 @@ +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.WebsocketApi(upstox_client.ApiClient(configuration)) + +res = api_instance.get_portfolio_stream_feed_authorize("2.0",order_update=True,holding_update=True,position_update=True) +print("\n\n") +print(res.data.authorized_redirect_uri) \ No newline at end of file From 25499f61cbe21584e2d5175a609ebdb0b909d230 Mon Sep 17 00:00:00 2001 From: ketangupta12 Date: Thu, 1 Aug 2024 15:39:00 +0530 Subject: [PATCH 7/8] changed version to 2.5.0 --- README.md | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d33948a..17f11ea 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The official Python client for communicating with the
Date: Thu, 1 Aug 2024 15:47:07 +0530 Subject: [PATCH 8/8] updated readme file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 17f11ea..474b0c6 100644 --- a/README.md +++ b/README.md @@ -412,7 +412,7 @@ if __name__ == "__main__": ```
-You can also enable position and holding updates by providing a boolean value to the constructor of `PortfolioDataStreamer` +Position and holding updates can be enabled by setting the corresponding flag to `True` in the constructor of the `PortfolioDataStreamer` class. ```python import upstox_client