Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The official Python client for communicating with the <a href="https://upstox.co
Upstox API is a set of rest APIs that provide data required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (using Websocket), and more, with the easy to understand API collection.

- API version: v2
- Package version: 2.20.0
- Package version: 2.21.0
- Build package: io.swagger.codegen.v3.generators.python.PythonClientCodegen

This Python package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
long_description = (this_directory / "README.md").read_text()

NAME = "upstox-python-sdk"
VERSION = "2.20.0"
VERSION = "2.21.0"
# To install the library, run the following
#
# python setup.py install
Expand Down
53 changes: 53 additions & 0 deletions test/sdk_tests/instrument_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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.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)
47 changes: 47 additions & 0 deletions test/sdk_tests/sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions upstox_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions upstox_client/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
156 changes: 156 additions & 0 deletions upstox_client/api/instruments_api.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 1 addition & 5 deletions upstox_client/api/login_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion upstox_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions upstox_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading