diff --git a/README.md b/README.md index b9d21a4..e87c640 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The official Python client for communicating with the search_instrument: %s\n" % e) + +# Search with exchange filter +try: + api_response = api_instance.search_instrument("Reliance", exchanges="NSE") + + if api_response.status != "success": + print("error in search_instrument with exchange filter") +except ApiException as e: + print("Exception when calling InstrumentsApi->search_instrument with exchange: %s\n" % e) + +# Search with segment filter +try: + api_response = api_instance.search_instrument("TCS", segments="EQ") + + if api_response.status != "success": + print("error in search_instrument with segment filter") +except ApiException as e: + print("Exception when calling InstrumentsApi->search_instrument with segment: %s\n" % e) + +# Search with instrument type filter +try: + api_response = api_instance.search_instrument("Nifty", instrument_types="INDEX") + + if api_response.status != "success": + print("error in search_instrument with instrument type filter") +except ApiException as e: + print("Exception when calling InstrumentsApi->search_instrument with instrument_types: %s\n" % e) + +# Search with pagination +try: + api_response = api_instance.search_instrument("HDFC", page_number=1, records=5) + + if api_response.status != "success": + print("error in search_instrument with pagination") +except ApiException as e: + print("Exception when calling InstrumentsApi->search_instrument with pagination: %s\n" % e) diff --git a/test/sdk_tests/sanity.py b/test/sdk_tests/sanity.py index 584db9c..6142d33 100644 --- a/test/sdk_tests/sanity.py +++ b/test/sdk_tests/sanity.py @@ -779,6 +779,53 @@ def is_within_market_hours(): print("\n=== Algo ID Tests Complete ===") print("All 12 APIs tested with algo_name parameter successfully!") +api_instance = upstox_client.InstrumentsApi(upstox_client.ApiClient(configuration)) + +# Basic search with just query +try: + api_response = api_instance.search_instrument("Nifty 50") + + if api_response.status != "success": + print("error in search_instrument basic query") +except ApiException as e: + print("Exception when calling InstrumentsApi->search_instrument: %s\n" % e) + +# Search with exchange filter +try: + api_response = api_instance.search_instrument("Reliance", exchanges="NSE") + + if api_response.status != "success": + print("error in search_instrument with exchange filter") +except ApiException as e: + print("Exception when calling InstrumentsApi->search_instrument with exchange: %s\n" % e) + +# Search with segment filter +try: + api_response = api_instance.search_instrument("TCS", segments="EQ") + + if api_response.status != "success": + print("error in search_instrument with segment filter") +except ApiException as e: + print("Exception when calling InstrumentsApi->search_instrument with segment: %s\n" % e) + +# Search with instrument type filter +try: + api_response = api_instance.search_instrument("Nifty", instrument_types="INDEX") + + if api_response.status != "success": + print("error in search_instrument with instrument type filter") +except ApiException as e: + print("Exception when calling InstrumentsApi->search_instrument with instrument_types: %s\n" % e) + +# Search with pagination +try: + api_response = api_instance.search_instrument("HDFC", page_number=1, records=5) + + if api_response.status != "success": + print("error in search_instrument with pagination") +except ApiException as e: + print("Exception when calling InstrumentsApi->search_instrument with pagination: %s\n" % e) + api_instance = upstox_client.LoginApi(upstox_client.ApiClient(configuration)) api_version = '2.0' diff --git a/upstox_client/__init__.py b/upstox_client/__init__.py index 6a72d4e..c42e5e1 100644 --- a/upstox_client/__init__.py +++ b/upstox_client/__init__.py @@ -19,6 +19,7 @@ from upstox_client.api.expired_instrument_api import ExpiredInstrumentApi from upstox_client.api.history_api import HistoryApi from upstox_client.api.history_v3_api import HistoryV3Api +from upstox_client.api.instruments_api import InstrumentsApi from upstox_client.api.login_api import LoginApi from upstox_client.api.market_holidays_and_timings_api import MarketHolidaysAndTimingsApi from upstox_client.api.market_quote_api import MarketQuoteApi @@ -101,6 +102,9 @@ 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.search_instrument_response import SearchInstrumentResponse +from upstox_client.models.search_meta_data import SearchMetaData +from upstox_client.models.search_page import SearchPage from upstox_client.models.intra_day_candle_data import IntraDayCandleData from upstox_client.models.logout_response import LogoutResponse from upstox_client.models.margin import Margin diff --git a/upstox_client/api/__init__.py b/upstox_client/api/__init__.py index f015cae..8452ee5 100644 --- a/upstox_client/api/__init__.py +++ b/upstox_client/api/__init__.py @@ -7,6 +7,7 @@ from upstox_client.api.expired_instrument_api import ExpiredInstrumentApi from upstox_client.api.history_api import HistoryApi from upstox_client.api.history_v3_api import HistoryV3Api +from upstox_client.api.instruments_api import InstrumentsApi from upstox_client.api.login_api import LoginApi from upstox_client.api.market_holidays_and_timings_api import MarketHolidaysAndTimingsApi from upstox_client.api.market_quote_api import MarketQuoteApi diff --git a/upstox_client/api/instruments_api.py b/upstox_client/api/instruments_api.py new file mode 100644 index 0000000..4606386 --- /dev/null +++ b/upstox_client/api/instruments_api.py @@ -0,0 +1,156 @@ +# 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 InstrumentsApi(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 search_instrument(self, query, **kwargs): # noqa: E501 + """Search instruments # noqa: E501 + + This API provides the functionality to retrieve the instrument details for searched query # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.search_instrument(query, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param object query: natural language query (required) + :param object exchanges: Comma separated exchanges + :param object segments: Comma separated segments + :param object instrument_types: Comma separated instrument types + :param object expiry: expiry in format: yyyy-MM-dd + :param object atm_offset: page number greater than or equal to 1 + :param object page_number: ATM offset number for queries like ATM, ATM+1, ATM-1, etc. + :param object records: no of records in a single page + :return: SearchInstrumentResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.search_instrument_with_http_info(query, **kwargs) # noqa: E501 + else: + (data) = self.search_instrument_with_http_info(query, **kwargs) # noqa: E501 + return data + + def search_instrument_with_http_info(self, query, **kwargs): # noqa: E501 + """Search instruments # noqa: E501 + + This API provides the functionality to retrieve the instrument details for searched query # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.search_instrument_with_http_info(query, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param object query: natural language query (required) + :param object exchanges: Comma separated exchanges + :param object segments: Comma separated segments + :param object instrument_types: Comma separated instrument types + :param object expiry: expiry in format: yyyy-MM-dd + :param object atm_offset: page number greater than or equal to 1 + :param object page_number: ATM offset number for queries like ATM, ATM+1, ATM-1, etc. + :param object records: no of records in a single page + :return: SearchInstrumentResponse + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['query', 'exchanges', 'segments', 'instrument_types', 'expiry', 'atm_offset', 'page_number', 'records'] # 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 search_instrument" % key + ) + params[key] = val + del params['kwargs'] + # verify the required parameter 'query' is set + if ('query' not in params or + params['query'] is None): + raise ValueError("Missing the required parameter `query` when calling `search_instrument`") # noqa: E501 + + collection_formats = {} + + path_params = {} + + query_params = [] + if 'query' in params: + query_params.append(('query', params['query'])) # noqa: E501 + if 'exchanges' in params: + query_params.append(('exchanges', params['exchanges'])) # noqa: E501 + if 'segments' in params: + query_params.append(('segments', params['segments'])) # noqa: E501 + if 'instrument_types' in params: + query_params.append(('instrument_types', params['instrument_types'])) # noqa: E501 + if 'expiry' in params: + query_params.append(('expiry', params['expiry'])) # noqa: E501 + if 'atm_offset' in params: + query_params.append(('atm_offset', params['atm_offset'])) # noqa: E501 + if 'page_number' in params: + query_params.append(('page_number', params['page_number'])) # noqa: E501 + if 'records' in params: + query_params.append(('records', params['records'])) # noqa: E501 + + 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( + '/v2/instruments/search', 'GET', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='SearchInstrumentResponse', # 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/login_api.py b/upstox_client/api/login_api.py index 5edfaa6..309a5e5 100644 --- a/upstox_client/api/login_api.py +++ b/upstox_client/api/login_api.py @@ -369,7 +369,6 @@ def token(self, api_version, **kwargs): # noqa: E501 :param str client_secret: :param str redirect_uri: :param str grant_type: - :param bool refresh_extended_token: :return: TokenResponse If the method is called asynchronously, returns the request thread. @@ -397,13 +396,12 @@ def token_with_http_info(self, api_version, **kwargs): # noqa: E501 :param str client_secret: :param str redirect_uri: :param str grant_type: - :param bool refresh_extended_token: :return: TokenResponse If the method is called asynchronously, returns the request thread. """ - all_params = ['api_version', 'code', 'client_id', 'client_secret', 'redirect_uri', 'grant_type', 'refresh_extended_token'] # noqa: E501 + all_params = ['api_version', 'code', 'client_id', 'client_secret', 'redirect_uri', 'grant_type'] # noqa: E501 all_params.append('async_req') all_params.append('_return_http_data_only') all_params.append('_preload_content') @@ -445,8 +443,6 @@ def token_with_http_info(self, api_version, **kwargs): # noqa: E501 form_params.append(('redirect_uri', params['redirect_uri'])) # noqa: E501 if 'grant_type' in params: form_params.append(('grant_type', params['grant_type'])) # noqa: E501 - if 'refresh_extended_token' in params and params['refresh_extended_token'] is not None: - form_params.append(('refresh_extended_token', 'true' if params['refresh_extended_token'] else 'false')) # noqa: E501 body_params = None # HTTP header `Accept` diff --git a/upstox_client/api_client.py b/upstox_client/api_client.py index 57720a7..1a2dc04 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.20.0" + self.default_headers["X-Upstox-SDK-Version"] = "2.21.0" def __del__(self): try: diff --git a/upstox_client/models/__init__.py b/upstox_client/models/__init__.py index 5d63b87..964fac6 100644 --- a/upstox_client/models/__init__.py +++ b/upstox_client/models/__init__.py @@ -77,6 +77,9 @@ 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.search_instrument_response import SearchInstrumentResponse +from upstox_client.models.search_meta_data import SearchMetaData +from upstox_client.models.search_page import SearchPage from upstox_client.models.intra_day_candle_data import IntraDayCandleData from upstox_client.models.logout_response import LogoutResponse from upstox_client.models.margin import Margin diff --git a/upstox_client/models/search_instrument_response.py b/upstox_client/models/search_instrument_response.py new file mode 100644 index 0000000..d3b55b1 --- /dev/null +++ b/upstox_client/models/search_instrument_response.py @@ -0,0 +1,166 @@ +# 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 SearchInstrumentResponse(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': 'object', + 'data': 'object', + 'meta_data': 'SearchMetaData' + } + + attribute_map = { + 'status': 'status', + 'data': 'data', + 'meta_data': 'meta_data' + } + + def __init__(self, status=None, data=None, meta_data=None): # noqa: E501 + """SearchInstrumentResponse - a model defined in Swagger""" # noqa: E501 + self._status = None + self._data = None + self._meta_data = None + self.discriminator = None + if status is not None: + self.status = status + if data is not None: + self.data = data + if meta_data is not None: + self.meta_data = meta_data + + @property + def status(self): + """Gets the status of this SearchInstrumentResponse. # noqa: E501 + + + :return: The status of this SearchInstrumentResponse. # noqa: E501 + :rtype: object + """ + return self._status + + @status.setter + def status(self, status): + """Sets the status of this SearchInstrumentResponse. + + + :param status: The status of this SearchInstrumentResponse. # noqa: E501 + :type: object + """ + + self._status = status + + @property + def data(self): + """Gets the data of this SearchInstrumentResponse. # noqa: E501 + + Response data for search instrument request # noqa: E501 + + :return: The data of this SearchInstrumentResponse. # noqa: E501 + :rtype: object + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this SearchInstrumentResponse. + + Response data for search instrument request # noqa: E501 + + :param data: The data of this SearchInstrumentResponse. # noqa: E501 + :type: object + """ + + self._data = data + + @property + def meta_data(self): + """Gets the meta_data of this SearchInstrumentResponse. # noqa: E501 + + Meta data for search instrument response # noqa: E501 + + :return: The meta_data of this SearchInstrumentResponse. # noqa: E501 + :rtype: SearchMetaData + """ + return self._meta_data + + @meta_data.setter + def meta_data(self, meta_data): + """Sets the meta_data of this SearchInstrumentResponse. + + Meta data for search instrument response # noqa: E501 + + :param meta_data: The meta_data of this SearchInstrumentResponse. # noqa: E501 + :type: SearchMetaData + """ + + self._meta_data = meta_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(SearchInstrumentResponse, 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, SearchInstrumentResponse): + 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/search_meta_data.py b/upstox_client/models/search_meta_data.py new file mode 100644 index 0000000..397e8aa --- /dev/null +++ b/upstox_client/models/search_meta_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 SearchMetaData(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 = { + 'page': 'SearchPage' + } + + attribute_map = { + 'page': 'page' + } + + def __init__(self, page=None): # noqa: E501 + """SearchMetaData - a model defined in Swagger""" # noqa: E501 + self._page = None + self.discriminator = None + if page is not None: + self.page = page + + @property + def page(self): + """Gets the page of this SearchMetaData. # noqa: E501 + + + :return: The page of this SearchMetaData. # noqa: E501 + :rtype: SearchPage + """ + return self._page + + @page.setter + def page(self, page): + """Sets the page of this SearchMetaData. + + + :param page: The page of this SearchMetaData. # noqa: E501 + :type: SearchPage + """ + + self._page = page + + 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(SearchMetaData, 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, SearchMetaData): + 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/search_page.py b/upstox_client/models/search_page.py new file mode 100644 index 0000000..a3a5bac --- /dev/null +++ b/upstox_client/models/search_page.py @@ -0,0 +1,188 @@ +# 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 SearchPage(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 = { + 'page_number': 'object', + 'total_pages': 'object', + 'records': 'object', + 'total_records': 'object' + } + + attribute_map = { + 'page_number': 'page_number', + 'total_pages': 'total_pages', + 'records': 'records', + 'total_records': 'total_records' + } + + def __init__(self, page_number=None, total_pages=None, records=None, total_records=None): # noqa: E501 + """SearchPage - a model defined in Swagger""" # noqa: E501 + self._page_number = None + self._total_pages = None + self._records = None + self._total_records = None + self.discriminator = None + if page_number is not None: + self.page_number = page_number + if total_pages is not None: + self.total_pages = total_pages + if records is not None: + self.records = records + if total_records is not None: + self.total_records = total_records + + @property + def page_number(self): + """Gets the page_number of this SearchPage. # noqa: E501 + + + :return: The page_number of this SearchPage. # noqa: E501 + :rtype: object + """ + return self._page_number + + @page_number.setter + def page_number(self, page_number): + """Sets the page_number of this SearchPage. + + + :param page_number: The page_number of this SearchPage. # noqa: E501 + :type: object + """ + + self._page_number = page_number + + @property + def total_pages(self): + """Gets the total_pages of this SearchPage. # noqa: E501 + + + :return: The total_pages of this SearchPage. # noqa: E501 + :rtype: object + """ + return self._total_pages + + @total_pages.setter + def total_pages(self, total_pages): + """Sets the total_pages of this SearchPage. + + + :param total_pages: The total_pages of this SearchPage. # noqa: E501 + :type: object + """ + + self._total_pages = total_pages + + @property + def records(self): + """Gets the records of this SearchPage. # noqa: E501 + + + :return: The records of this SearchPage. # noqa: E501 + :rtype: object + """ + return self._records + + @records.setter + def records(self, records): + """Sets the records of this SearchPage. + + + :param records: The records of this SearchPage. # noqa: E501 + :type: object + """ + + self._records = records + + @property + def total_records(self): + """Gets the total_records of this SearchPage. # noqa: E501 + + + :return: The total_records of this SearchPage. # noqa: E501 + :rtype: object + """ + return self._total_records + + @total_records.setter + def total_records(self, total_records): + """Sets the total_records of this SearchPage. + + + :param total_records: The total_records of this SearchPage. # noqa: E501 + :type: object + """ + + self._total_records = total_records + + 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(SearchPage, 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, SearchPage): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other