@@ -11,6 +11,18 @@ Use the package manager [pip](https://pip.pypa.io/en/stable/) to install smartap
1111pip install -r requirements_dev.txt # for downloading the other required packages
1212```
1313
14+ Download the following packages
15+ ``` bash
16+ pip install pyotp
17+ pip install logzero
18+ pip install websocket-client
19+ ```
20+ For Downloading pycryptodome package
21+ ``` bash
22+ pip uninstall pycrypto
23+ pip install pycryptodome
24+ ```
25+
1426## Usage
1527
1628``` python
@@ -123,56 +135,54 @@ else:
123135 ```
124136
125137 # # Getting started with SmartAPI Websocket's
126-
127- ```python
128138 # ###### Websocket V2 sample code #######
129139
130140 from SmartApi.smartWebSocketV2 import SmartWebSocketV2
131141 from logzero import logger
132142
133- AUTH_TOKEN = " Your Auth_Token "
134- API_KEY = " Your Api_Key "
135- CLIENT_CODE = " Your Client Code "
136- FEED_TOKEN = " Your Feed_Token "
143+ AUTH_TOKEN = " authToken "
144+ API_KEY = " api_key "
145+ CLIENT_CODE = " client code "
146+ FEED_TOKEN = " feedToken "
137147 correlation_id = " abc123"
138148 action = 1
139149 mode = 1
150+
140151 token_list = [
141152 {
142153 " exchangeType" : 1 ,
143154 " tokens" : [" 26009" ]
144155 }
145156 ]
146- # retry_strategy=0 for simple retry mechanism
147- sws = SmartWebSocketV2(AUTH_TOKEN , API_KEY , CLIENT_CODE , FEED_TOKEN ,max_retry_attempt = 2 , retry_strategy = 0 , retry_delay = 10 , retry_duration = 30 )
157+ token_list1 = [
158+ {
159+ " action" : 0 ,
160+ " exchangeType" : 1 ,
161+ " tokens" : [" 26009" ]
162+ }
163+ ]
148164
149- # retry_strategy=1 for exponential retry mechanism
150- # sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN,max_retry_attempt=3, retry_strategy=1, retry_delay=10,retry_multiplier=2, retry_duration=30)
165+ sws = SmartWebSocketV2(AUTH_TOKEN , API_KEY , CLIENT_CODE , FEED_TOKEN )
151166
152167 def on_data (wsapp , message ):
153168 logger.info(" Ticks: {} " .format(message))
154169 # close_connection()
155170
156- def on_control_message (wsapp , message ):
157- logger.info(f " Control Message: { message} " )
158-
159171 def on_open (wsapp ):
160172 logger.info(" on open" )
161- some_error_condition = False
162- if some_error_condition:
163- error_message = " Simulated error"
164- if hasattr (wsapp, ' on_error' ):
165- wsapp.on_error(" Custom Error Type" , error_message)
166- else :
167- sws.subscribe(correlation_id, mode, token_list)
168- # sws.unsubscribe(correlation_id, mode, token_list1)
173+ sws.subscribe(correlation_id, mode, token_list)
174+ # sws.unsubscribe(correlation_id, mode, token_list1)
175+
169176
170177 def on_error (wsapp , error ):
171178 logger.error(error)
172179
180+
173181 def on_close (wsapp ):
174182 logger.info(" Close" )
175183
184+
185+
176186 def close_connection ():
177187 sws.close_connection()
178188
@@ -182,7 +192,6 @@ else:
182192 sws.on_data = on_data
183193 sws.on_error = on_error
184194 sws.on_close = on_close
185- sws.on_control_message = on_control_message
186195
187196 sws.connect()
188197 # ###### Websocket V2 sample code ENDS Here #######
0 commit comments