From 9451b5f88d9f0b6342d581aab0241c3798601f19 Mon Sep 17 00:00:00 2001 From: noddy09 Date: Thu, 16 Sep 2021 12:55:05 +0530 Subject: [PATCH 01/11] Keeping host as argument for session initialization. Updated documents. Default hosts are hardcoded in constructor, if host value is not provided while initializing as per requirements. --- README.md | 7 +++--- docs/SessionApi.md | 2 +- ks_api_client/ks_api.py | 53 +++++++++++++++++++++++++---------------- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 68c9075..f0de200 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,9 @@ from ks_api_client import ks_api client = ks_api.KSTradeApi(access_token = "", userid = "", \ consumer_key = "", ip = "127.0.0.1", app_id = "") -#For using specific environment use hosts as ["https://tradeapi.kotaksecurities.com/apim","https://ctradeapi.kotaksecurities.com/apim"] -client = ks_api.KSTradeApi(access_token = "", userid = "", \ - consumer_key = "", ip = "127.0.0.1", app_id = "", - hosts = ["https://tradeapi.kotaksecurities.com/apim","https://ctradeapi.kotaksecurities.com/apim"]) +#For using specific environment use host="https://tradeapi.kotaksecurities.com/apim" +client = ks_api.KSTradeApi(access_token = "", userid = "", consumer_key = "", + ip = "127.0.0.1", app_id = "", host ="https://sbx.kotaksecurities.com/apim") # Get session for user client.login(password = "") diff --git a/docs/SessionApi.md b/docs/SessionApi.md index c5d7850..9dff60a 100644 --- a/docs/SessionApi.md +++ b/docs/SessionApi.md @@ -37,7 +37,7 @@ Name | Type | Description | Notes **consumer_key** | **str**| | **ip** | **str**| | **app_id** | **str**| | - **host** | **list**| List of trade API host URLs | [optional] + **host** | **str**| API host URL| [optional] **proxy_url** | **str**| Proxy url | [optional] **proxy_user** | **str**| Proxy user's Username | [optional] **proxy_pass** | **str**| Proxy user's Password | [optional] diff --git a/ks_api_client/ks_api.py b/ks_api_client/ks_api.py index 5438b91..350914d 100644 --- a/ks_api_client/ks_api.py +++ b/ks_api_client/ks_api.py @@ -1,3 +1,4 @@ +from re import S import ks_api_client import base64 import json @@ -12,10 +13,10 @@ UserCredentials, UserDetails, NewMISOrder, InlineObject class KSTradeApi(): - def __init__(self, access_token, userid, consumer_key, ip, app_id, - hosts=["https://tradeapi.kotaksecurities.com/apim","https://sbx.kotaksecurities.com/apim"], + def __init__(self, access_token, userid, consumer_key, ip, app_id, host = None, proxy_url = '', proxy_user = '', proxy_pass = ''): self.userid = userid + self.host = host self.consumer_key = consumer_key self.ip = ip self.app_id = app_id @@ -24,30 +25,42 @@ def __init__(self, access_token, userid, consumer_key, ip, app_id, self._proxy_pass = proxy_pass self._proxy_url = proxy_url error = None - session_init = None - for host in hosts: - self.host = host - configuration = self.get_config(proxy_url, proxy_user, proxy_pass) - try: - self.api_client = ks_api_client.ApiClient(configuration) - session_init_res = ks_api_client.SessionApi(self.api_client).session_init(self.userid, \ - self.consumer_key, self.ip, self.app_id) - except ApiException as ex: - error = ex - continue + self.__session_init = None + + def init_session(self, session_init_res): if(session_init_res.get("Success")): - session_init = session_init_res.get("Success") + self.__session_init = session_init_res.get("Success") elif(session_init_res.get("success")): - session_init = session_init_res.get("success") - if self.host != session_init['redirect']['host']: - self.host = session_init['redirect']['host'] + self.__session_init = session_init_res.get("success") + if self.host != self.__session_init['redirect']['host']: + self.host = self.__session_init['redirect']['host'] configuration = self.get_config(proxy_url, proxy_user, proxy_pass) self.api_client = ks_api_client.ApiClient(configuration) - session_init = ks_api_client.SessionApi(self.api_client).session_init(self.userid, \ + self.__session_init = ks_api_client.SessionApi(self.api_client).session_init(self.userid, \ self.consumer_key, self.ip, self.app_id) - break - if not session_init and error: + if self.host: + configuration = self.get_config(proxy_url, proxy_user, proxy_pass) + self.api_client = ks_api_client.ApiClient(configuration) + session_init_res = ks_api_client.SessionApi(self.api_client).session_init(self.userid, \ + self.consumer_key, self.ip, self.app_id) + init_session(self, session_init_res) + else: + hosts = ["https://tradeapi.kotaksecurities.com/apim","https://sbx.kotaksecurities.com/apim"] + for host in hosts: + self.host = host + configuration = self.get_config(proxy_url, proxy_user, proxy_pass) + try: + self.api_client = ks_api_client.ApiClient(configuration) + session_init_res = ks_api_client.SessionApi(self.api_client).session_init(self.userid, \ + self.consumer_key, self.ip, self.app_id) + except ApiException as ex: + error = ex + continue + init_session(self, session_init_res) + break + if not self.__session_init and error: raise error + del self.__session_init def get_config(self, proxy_url = '', proxy_user = '', proxy_pass = ''): configuration = ks_api_client.Configuration(self.host) From bfb76d9e9a590dbacefe4177db69696d44e07c2b Mon Sep 17 00:00:00 2001 From: noddy09 Date: Thu, 16 Sep 2021 12:56:59 +0530 Subject: [PATCH 02/11] Updated host value as str object in settings.py --- ks_api_client/settings.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ks_api_client/settings.py b/ks_api_client/settings.py index 0717f01..f2185d6 100644 --- a/ks_api_client/settings.py +++ b/ks_api_client/settings.py @@ -1,5 +1,4 @@ -host = ["https://tradeapi.kotaksecurities.com/apim", - "https://sbx.kotaksecurities.com/apim"] +host = "https://sbx.kotaksecurities.com/apim" access_token = "" userid = "" consumer_key = "" From a0f4c3516c3ce8b51f7ef240a04dcf0fe7c28f60 Mon Sep 17 00:00:00 2001 From: noddy09 Date: Thu, 16 Sep 2021 17:57:12 +0530 Subject: [PATCH 03/11] Added CHANGELOG.md for initial release. --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f245d7d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,23 @@ +# Changelog +All notable changes to this project will be documented in this file. + + +## v1.0.1-BETA (16-Sep-2021) +### Added : +- Support for multiple default hosts. [ Internal ] +- Support to update endpoint's host after generating session according to `redirect` response. [ Internal ] +- Method to consume Streaming API: `subscribe()` and `unsubscribe()`. + +### Updated: +- Method `session_2fa()` to be `access_code` optional parameter, and able to generate session token with OTT only. +- Method `order_report()`, allowing additional boolean value parameter`is_fno`, keeping default value as `False`. +- Related documents. + +### Fixed: + +#### Minor: +- `__doc__` strings of few methods. + +## v1.0.0-BETA (Unreleased) +### Initial commits. +- For more details, refer [documentation](README.md) \ No newline at end of file From e9ae829ddbf8c728c9688429b6fefd0b96c90dd3 Mon Sep 17 00:00:00 2001 From: noddy09 Date: Mon, 20 Sep 2021 10:22:32 +0530 Subject: [PATCH 04/11] Added documentation of steaming api and Updated readme.md document. --- CHANGELOG.md | 10 +++--- README.md | 17 ++++++++- docs/StreamingApi.md | 77 +++++++++++++++++++++++++++++++++++++++++ ks_api_client/ks_api.py | 8 ++--- 4 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 docs/StreamingApi.md diff --git a/CHANGELOG.md b/CHANGELOG.md index f245d7d..abfe687 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,17 @@ # Changelog All notable changes to this project will be documented in this file. - ## v1.0.1-BETA (16-Sep-2021) ### Added : - Support for multiple default hosts. [ Internal ] - Support to update endpoint's host after generating session according to `redirect` response. [ Internal ] -- Method to consume Streaming API: `subscribe()` and `unsubscribe()`. +- Methods to consume Streaming API: `subscribe()` and `unsubscribe()`. For more details, refer [documentation](docs/StreamingApi.md). [ Feature ] +- Method `get_margin()`, For more details, refer [documentation](docs/MarginApi.md#get_margins) [ Feature ] ### Updated: -- Method `session_2fa()` to be `access_code` optional parameter, and able to generate session token with OTT only. -- Method `order_report()`, allowing additional boolean value parameter`is_fno`, keeping default value as `False`. -- Related documents. +- In method `session_2fa()`, the `access_code` is now an optional parameter. It is able to generate session token with OTT only. [ Feature ] +- Method `order_report()` now takes an additional boolean parameter `is_fno` whose default value is `False`. [ Feature ] +- The documentation. ### Fixed: diff --git a/README.md b/README.md index f0de200..f3ba393 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,9 @@ order_info = [ ] client.margin_required(transaction_type = "BUY",order_info = order_info) +# Get calculate margins +client.get_margins() + # Get Positions client.positions(position_type = "TODAYS") @@ -101,12 +104,21 @@ client.history("historicalprices-unadjusted",{"exchange":"bse","co_code":"476"," client.history("NSEFNO_HistoricalContinuousChart",{"symbol":"HDFC","expiry type": "near"}) client.history("LiveorEODHistorical",{"exchange":"BSE","co_code":"5400","period":"Y","cnt":"3"}) +# Subscribe to instrument token's stream. +def callback_method(message): + print(message) + print("Your logic/computation will come here.") +client.subscribe(input_token="745,754", auth_token="", callback=callback_method) + +# Unsubscribe from streaming service. +client.unsubscribe() + #Terminate user's Session client.logout() ``` ## Documentation for API Endpoints -All URIs are relative to *https://tradeapi.kotaksecurities.com/apim* +All URIs are relative to *https://tradeapi.kotaksecurities.com/apim* and *https://ctradeapi.kotaksecurities.com/apim* Class | Method | Description ------------ | ------------- | ------------- @@ -119,9 +131,12 @@ Class | Method | Description *ReportsApi* | [**order_report**](docs/ReportsApi.md#order_report) | Get order report *ReportsApi* | [**trade_report**](docs/ReportsApi.md#trade_report) | Get trade report *MarginApi* | [**margin_required**](docs/MarginApi.md#margin_required) | Get Margin Required for an order by amount or quantity. +*MarginApi* | [**get_margins**](docs/MarginApi.md#get_margins) | Get all calculated margins. *PositionsApi* | [**positions**](docs/PositionsApi.md#positions) | Get's Open position. *QuoteApi* | [**quote**](docs/QuoteApi.md#quote_details) | Get Quote details *HistoricalApi* | [**history**](docs/HistoricalApi.md#history) | Get historical data. +*StreamingApi* | [**subscribe**](docs/StreamingApi.md#subscribe) | Subscribe to streaming api of specified instrument tokens. +*StreamingApi* | [**unsubscribe**](docs/StreamingApi.md#unsubscribe) | Unsubscribe from streaming api. *SessionApi* | [**logout**](docs/SessionApi.md#logout) | Invalidate Session Token diff --git a/docs/StreamingApi.md b/docs/StreamingApi.md new file mode 100644 index 0000000..600d29f --- /dev/null +++ b/docs/StreamingApi.md @@ -0,0 +1,77 @@ +# ks_api_client.StreamingApi + +All URIs are relative to *https://tradeapi.kotaksecurities.com/apim* + +Method | Description +------------- | ------------- +[**subscribe**](StreamingApi.md#subscribe) | Get Margin Required for an order by amount or quantity. +[**unsubscribe**](StreamingApi.md#unsubscribe) | Gives complete Margin Details of a Client from RMS. + + +# **subscribe** +> object subscribe(input_tokens, auth_token, callback, broadcast_host): + +Get streaming service subscription for specified instruments inputs. + +### Example + + +```python +from ks_api_client import ks_api + +client = ks_api.KSTradeApi(access_token = "access_token", userid = "userid", \ + consumer_key = "consumer_key", ip = "IP", app_id = "app_id") + +#First initialize session and generate session token + +try: + # Get Margin Required for an order by amount or quantity. + client.subscribe(input_tokens="", auth_token="", callback=print, broadcast_host="https://wstreamer.kotaksecurities.com") +except Exception as e: + print("Exception when calling StreamingApi->subscribe: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**input_token** | **str** | Instrument tokens with comma seperated. | +**auth_token** | **str** | Authentication token | +**callback** | **obj** | Method object | method of function should have one mandatory parameter to accept message. Default method is print() +**broadcast_host** | **str** | String host URL | default value: "https://wstreamer.kotaksecurities.com" + +### Return type + +**object** + + +# **unsubscribe** +> object unsubscribe() + +Request to unsubscribe from streaming service. + +### Example + + +```python +from ks_api_client import ks_api + +client = ks_api.KSTradeApi(access_token = "access_token", userid = "userid", \ + consumer_key = "consumer_key", ip = "IP", app_id = "app_id") + +#First initialize session and generate session token + +try: + # Get Margin details. + client.unsubscribe() +except Exception as e: + print("Exception when calling StreamingApi->unsubscribe: %s\n" % e) +``` + +### Return type + +**object** + + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/ks_api_client/ks_api.py b/ks_api_client/ks_api.py index 350914d..2de4def 100644 --- a/ks_api_client/ks_api.py +++ b/ks_api_client/ks_api.py @@ -4,6 +4,8 @@ import json import os import socketio +import requests +import urllib.parse from urllib3 import make_headers from ks_api_client.exceptions import ApiException, ApiValueError @@ -328,13 +330,11 @@ def convertArray(self, array): return new_array - def subscribe(self, input_tokens, callback, auth_token, broadcast_host="https://wstreamer.kotaksecurities.com"): + def subscribe(self, input_tokens, auth_token, callback=print, broadcast_host="https://wstreamer.kotaksecurities.com"): try: proxy = "" + session = requests.session() if self._proxy_pass or self._proxy_url or self._proxy_user: - import urllib.parse - import requests - session = requests.session() scheme = "" parsed = urllib.parse.urlparse(self._proxy_url) if not parsed.scheme: From 9cbfd7c007d197a66439378cfaf93522d0253037 Mon Sep 17 00:00:00 2001 From: noddy09 Date: Thu, 23 Sep 2021 18:19:35 +0530 Subject: [PATCH 05/11] Updated dependencies --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 41101bf..9b16313 100644 --- a/setup.py +++ b/setup.py @@ -11,9 +11,7 @@ # prerequisite: setuptools # http://pypi.python.org/pypi/setuptools -REQUIRES = ["certifi >= 14.05.14", "future; python_version<=2.7", "six >= 1.10", - "python_dateutil >= 2.5.3", "setuptools >= 21.0.0", "urllib3 >= 1.15.1", - "python-socketio[client]==5.3.0", "requests==2.26.0"] +REQUIRES = ["certifi>=14.05.14", "six >= 1.10", "python_dateutil >= 2.5.3", "urllib3 > 1.15", "python-socketio[client]==5.3.0", "requests==2.26.0"] setup( name=NAME, From 480d1ed6fb89f9a20810cbe1624bc013cecc9900 Mon Sep 17 00:00:00 2001 From: noddy09 Date: Thu, 23 Sep 2021 18:20:43 +0530 Subject: [PATCH 06/11] Updated git url in installation command. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f3ba393..1f2b562 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ Python 2.7 and 3.4+ If the python package is hosted on a repository, you can install directly using: ```sh -pip install git+https://github.com/osparamatrix/ks-orderapi-python.git +pip install git+https://github.com/noddy09/ks-orderapi-python.git ``` -(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/osparamatrix/ks-orderapi-python.git`) +(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/noddy09/ks-orderapi-python.git`) Then import the package: ```python From 7121c38d0111e655ab1b3b7b65dd63063d789bc7 Mon Sep 17 00:00:00 2001 From: noddy09 Date: Thu, 30 Sep 2021 01:20:55 +0530 Subject: [PATCH 07/11] Added parameter for SSL verification and with default True value in configuration. --- ks_api_client/configuration.py | 2 +- ks_api_client/ks_api.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ks_api_client/configuration.py b/ks_api_client/configuration.py index 52bfce6..6df3de1 100644 --- a/ks_api_client/configuration.py +++ b/ks_api_client/configuration.py @@ -137,7 +137,7 @@ def __init__(self, host=None, """Debug switch """ - self.verify_ssl = False + self.verify_ssl = True """SSL/TLS verification Set this to false to skip verifying SSL certificate when calling API from https server. diff --git a/ks_api_client/ks_api.py b/ks_api_client/ks_api.py index 2de4def..18b1150 100644 --- a/ks_api_client/ks_api.py +++ b/ks_api_client/ks_api.py @@ -16,7 +16,7 @@ class KSTradeApi(): def __init__(self, access_token, userid, consumer_key, ip, app_id, host = None, - proxy_url = '', proxy_user = '', proxy_pass = ''): + proxy_url = '', proxy_user = '', proxy_pass = '', verify_ssl=True): self.userid = userid self.host = host self.consumer_key = consumer_key @@ -26,6 +26,7 @@ def __init__(self, access_token, userid, consumer_key, ip, app_id, host = None, self._proxy_user = proxy_user self._proxy_pass = proxy_pass self._proxy_url = proxy_url + self._verify_ssl = verify_ssl error = None self.__session_init = None @@ -36,12 +37,12 @@ def init_session(self, session_init_res): self.__session_init = session_init_res.get("success") if self.host != self.__session_init['redirect']['host']: self.host = self.__session_init['redirect']['host'] - configuration = self.get_config(proxy_url, proxy_user, proxy_pass) + configuration = self.get_config(proxy_url, proxy_user, proxy_pass, verify_ssl) self.api_client = ks_api_client.ApiClient(configuration) self.__session_init = ks_api_client.SessionApi(self.api_client).session_init(self.userid, \ self.consumer_key, self.ip, self.app_id) if self.host: - configuration = self.get_config(proxy_url, proxy_user, proxy_pass) + configuration = self.get_config(proxy_url, proxy_user, proxy_pass, verify_ssl) self.api_client = ks_api_client.ApiClient(configuration) session_init_res = ks_api_client.SessionApi(self.api_client).session_init(self.userid, \ self.consumer_key, self.ip, self.app_id) @@ -50,7 +51,7 @@ def init_session(self, session_init_res): hosts = ["https://tradeapi.kotaksecurities.com/apim","https://sbx.kotaksecurities.com/apim"] for host in hosts: self.host = host - configuration = self.get_config(proxy_url, proxy_user, proxy_pass) + configuration = self.get_config(proxy_url, proxy_user, proxy_pass, verify_ssl) try: self.api_client = ks_api_client.ApiClient(configuration) session_init_res = ks_api_client.SessionApi(self.api_client).session_init(self.userid, \ @@ -64,13 +65,15 @@ def init_session(self, session_init_res): raise error del self.__session_init - def get_config(self, proxy_url = '', proxy_user = '', proxy_pass = ''): + def get_config(self, proxy_url = '', proxy_user = '', proxy_pass = '', verify_ssl=True): configuration = ks_api_client.Configuration(self.host) configuration.access_token = self.access_token if proxy_url: configuration.proxy = proxy_url if proxy_user: configuration.proxy_headers = make_headers(proxy_basic_auth = ':'.join((proxy_user,proxy_pass))) + if not verify_ssl: + configuration.verify_ssl = False return configuration def login(self, password): @@ -347,7 +350,7 @@ def subscribe(self, input_tokens, auth_token, callback=print, broadcast_host="ht if parsed.port: proxy += ":" + str(parsed.port) session.proxies.update({'http':proxy, 'https':proxy}) - session.verify = 's' in scheme + session.verify = self._verify_ssl # Generating base64 encoding of consumer credentials AUTH_BASE64 = base64.b64encode(auth_token.encode("UTF-8")) PAYLOAD = {"authentication": AUTH_BASE64.decode("UTF-8")} @@ -378,8 +381,7 @@ def disconnect(): @self.sio.on('getdata') def on_getdata(data, callback=callback): callback(data) - - # Do the connection using above access token + self.sio.connect(broadcast_host, headers={'Authorization': 'Bearer ' + jsonResponse['result']['token']}, transports=["websocket"], socketio_path='/feed') From a45bb790fbf7cdef43ce4b80c4b80cd1b59f5299 Mon Sep 17 00:00:00 2001 From: noddy09 Date: Thu, 30 Sep 2021 08:22:01 +0530 Subject: [PATCH 08/11] Renamed 'get_margins' method name to 'margins'. --- ks_api_client/ks_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ks_api_client/ks_api.py b/ks_api_client/ks_api.py index 18b1150..a74c06d 100644 --- a/ks_api_client/ks_api.py +++ b/ks_api_client/ks_api.py @@ -252,7 +252,7 @@ def margin_required(self, transaction_type, order_info): ReqMargin = req_margin) return margin_required - def get_margins(self): + def margins(self): margins = ks_api_client.MarginApi(self.api_client).get_margins(self.consumer_key,self.session_token) return margins @@ -311,7 +311,8 @@ def history(self, resource, json_input): raise ApiValueError("exchange,co_code,period,cnt fields are required.") encoded_json = base64.urlsafe_b64encode(json.dumps(json_input).encode()).decode() data = ks_api_client.HistoricalApi(self.api_client).get_resource(resource,encoded_json) - return data + return data + #-------- Convert Array and object snake_case keys to camelCase ----------- def convertObject(self, object): newObj={} From 82368917938855c8309ea15be2e9305a9c6c42e4 Mon Sep 17 00:00:00 2001 From: noddy09 Date: Thu, 30 Sep 2021 13:08:10 +0530 Subject: [PATCH 09/11] Renamed 'get_margins' method name to 'margin'. Subscribe method takes consumer_key, consumer_secrete as a input instead of auth_token. . --- ks_api_client/ks_api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ks_api_client/ks_api.py b/ks_api_client/ks_api.py index a74c06d..ca4b4ca 100644 --- a/ks_api_client/ks_api.py +++ b/ks_api_client/ks_api.py @@ -252,7 +252,7 @@ def margin_required(self, transaction_type, order_info): ReqMargin = req_margin) return margin_required - def margins(self): + def margin(self): margins = ks_api_client.MarginApi(self.api_client).get_margins(self.consumer_key,self.session_token) return margins @@ -334,8 +334,9 @@ def convertArray(self, array): return new_array - def subscribe(self, input_tokens, auth_token, callback=print, broadcast_host="https://wstreamer.kotaksecurities.com"): + def subscribe(self, input_tokens, consumer_key, consumer_secrete, callback=print, broadcast_host="https://wstreamer.kotaksecurities.com"): try: + auth_token = ":".join(consumer_key, consumer_secrete) proxy = "" session = requests.session() if self._proxy_pass or self._proxy_url or self._proxy_user: @@ -365,7 +366,7 @@ def subscribe(self, input_tokens, auth_token, callback=print, broadcast_host="ht else: self.sio = socketio.Client( reconnection=True, request_timeout=20, reconnection_attempts=5, engineio_logger=True, - logger=True,http_session=session, ssl_verify=session.verify) + logger=True, http_session=session, ssl_verify=session.verify) @self.sio.event def connect(): From 1f9021ccf2f954608468a78423e554285ddea4e0 Mon Sep 17 00:00:00 2001 From: Nagesh Mhapadi Date: Sun, 3 Oct 2021 10:49:06 +0530 Subject: [PATCH 10/11] Changed subscribe() method parameter. subscribe() method takes consumer_key, consumer_secrete as an input instead of auth_token. --- ks_api_client/ks_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ks_api_client/ks_api.py b/ks_api_client/ks_api.py index ca4b4ca..08bb30e 100644 --- a/ks_api_client/ks_api.py +++ b/ks_api_client/ks_api.py @@ -336,7 +336,7 @@ def convertArray(self, array): def subscribe(self, input_tokens, consumer_key, consumer_secrete, callback=print, broadcast_host="https://wstreamer.kotaksecurities.com"): try: - auth_token = ":".join(consumer_key, consumer_secrete) + auth_token = ":".join((consumer_key, consumer_secrete)) proxy = "" session = requests.session() if self._proxy_pass or self._proxy_url or self._proxy_user: From a1d56af6e3562d22b754006f2f32a4c076002790 Mon Sep 17 00:00:00 2001 From: noddy09 Date: Tue, 19 Oct 2021 22:03:53 +0530 Subject: [PATCH 11/11] Updated documenatation. Fixed typos. --- docs/StreamingApi.md | 7 ++++--- ks_api_client/ks_api.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/StreamingApi.md b/docs/StreamingApi.md index 600d29f..92f700d 100644 --- a/docs/StreamingApi.md +++ b/docs/StreamingApi.md @@ -26,7 +26,7 @@ client = ks_api.KSTradeApi(access_token = "access_token", userid = "userid", \ try: # Get Margin Required for an order by amount or quantity. - client.subscribe(input_tokens="", auth_token="", callback=print, broadcast_host="https://wstreamer.kotaksecurities.com") + client.subscribe(input_tokens="", consumer_key="", consumer_secret="", callback=print, broadcast_host="https://wstreamer.kotaksecurities.com") except Exception as e: print("Exception when calling StreamingApi->subscribe: %s\n" % e) ``` @@ -35,8 +35,9 @@ except Exception as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**input_token** | **str** | Instrument tokens with comma seperated. | -**auth_token** | **str** | Authentication token | +**input_tokens** | **str** | Instrument tokens with comma seperated. | Example: "475,745" +**consumer_key** | **str** | Consumer Key | Mandatory field +**consumer_secret** | **str** | Consumer Secret | Mandatory field **callback** | **obj** | Method object | method of function should have one mandatory parameter to accept message. Default method is print() **broadcast_host** | **str** | String host URL | default value: "https://wstreamer.kotaksecurities.com" diff --git a/ks_api_client/ks_api.py b/ks_api_client/ks_api.py index ca4b4ca..b23f773 100644 --- a/ks_api_client/ks_api.py +++ b/ks_api_client/ks_api.py @@ -334,9 +334,9 @@ def convertArray(self, array): return new_array - def subscribe(self, input_tokens, consumer_key, consumer_secrete, callback=print, broadcast_host="https://wstreamer.kotaksecurities.com"): + def subscribe(self, input_tokens, consumer_key, consumer_secret, callback=print, broadcast_host="https://wstreamer.kotaksecurities.com"): try: - auth_token = ":".join(consumer_key, consumer_secrete) + auth_token = ":".join(consumer_key, consumer_secret) proxy = "" session = requests.session() if self._proxy_pass or self._proxy_url or self._proxy_user: