fyers-apiv3 3.1.7__py3-none-any.whl → 3.1.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -124,6 +124,10 @@ class FyersOrderSocket:
124
124
  for key , value in self.position_mapper.items():
125
125
  if key in msg["positions"]:
126
126
  position_data[value] = msg["positions"][key]
127
+
128
+ # Add id_fyers only if the key is present
129
+ if "id_fyers" in msg["positions"]:
130
+ position_data["id_fyers"] = msg["positions"]["id_fyers"]
127
131
 
128
132
  return { "s": msg["s"], "positions": position_data}
129
133
 
@@ -146,8 +150,10 @@ class FyersOrderSocket:
146
150
  for key , value in self.trade_mapper.items():
147
151
  if key in msg["trades"]:
148
152
  trade_data[value] = msg["trades"][key]
149
-
150
-
153
+
154
+ # Add id_fyers only if the key is present
155
+ if "id_fyers" in msg["trades"]:
156
+ trade_data["id_fyers"] = msg["trades"]["id_fyers"]
151
157
 
152
158
  return { "s": msg["s"], "trades": trade_data}
153
159
 
@@ -169,7 +175,11 @@ class FyersOrderSocket:
169
175
  for key , value in self.order_mapper.items():
170
176
  if key in msg["orders"]:
171
177
  order_data[value] = msg["orders"][key]
172
- order_data["orderNumStatus"] = msg["orders"]["id"] + ":" + str(msg["orders"]["org_ord_status"])
178
+
179
+ # Add id_fyers only if the key is present
180
+ if "id_fyers" in msg["orders"]:
181
+ order_data["id_fyers"] = msg["orders"]["id_fyers"]
182
+
173
183
  return { "s": msg["s"], "orders": order_data}
174
184
 
175
185
  except Exception as e:
fyers_apiv3/fyersModel.py CHANGED
@@ -41,6 +41,22 @@ class Config:
41
41
  option_chain = "/options-chain-v3"
42
42
  multileg_orders = "/multileg/orders/sync"
43
43
  logout = "/logout"
44
+ price_alert ="/price-alert"
45
+ toggle_alert = "/toggle-alert"
46
+ create_smartorder_step ="/smart-order/step"
47
+ create_smartorder_limit ="/smart-order/limit"
48
+ create_smartorder_trail ="/smart-order/trail"
49
+ create_smartorder_sip ="/smart-order/sip"
50
+ modify_smartorder="/smart-order/modify"
51
+ cancel_smartorder="/smart-order/cancel"
52
+ pause_smartorder="/smart-order/pause"
53
+ resume_smartorder="/smart-order/resume"
54
+ smartorder_orderbook="/smart-order/orderbook"
55
+ smartexit_trigger="/flows/tc/se"
56
+ activate_smartexit_trigger="/flows/tc/se/activate"
57
+
58
+
59
+
44
60
 
45
61
 
46
62
 
@@ -51,12 +67,14 @@ class FyersServiceSync:
51
67
 
52
68
  Args:
53
69
  logger: The logger object used for logging errors.
70
+ request_logger: The logger object used for logging requests.
54
71
  """
55
72
  self.api_logger = logger
56
73
  self.request_logger = request_logger
57
74
  self.content = "application/json"
58
75
  self.error_resp = {"s":"error", "code": 0 , "message":"Bad request"}
59
76
  self.error_message = "invalid input please check your input"
77
+ self.session = requests.Session()
60
78
 
61
79
 
62
80
  def post_call(self, api: str, header: str, data=None) -> dict:
@@ -73,7 +91,7 @@ class FyersServiceSync:
73
91
  """
74
92
  try:
75
93
  URL = Config.API + api
76
- response = requests.post(
94
+ response = self.session.post(
77
95
  URL,
78
96
  data=json.dumps(data),
79
97
  headers={"Authorization": header, "Content-Type": self.content ,"version": "3"},
@@ -129,7 +147,7 @@ class FyersServiceSync:
129
147
  if data is not None:
130
148
  url_params = urllib.parse.urlencode(data)
131
149
  URL = URL + "?" + url_params
132
- response = requests.get(
150
+ response = self.session.get(
133
151
  url=URL,
134
152
  headers={
135
153
  "Authorization": header,
@@ -179,7 +197,7 @@ class FyersServiceSync:
179
197
  """
180
198
  try:
181
199
  URL = Config.API + api
182
- response = requests.delete(
200
+ response = self.session.delete(
183
201
  URL,
184
202
  data=json.dumps(data),
185
203
  headers={"Authorization": header, "Content-Type": self.content ,"version": "3"},
@@ -229,7 +247,56 @@ class FyersServiceSync:
229
247
  """
230
248
  try:
231
249
  URL = Config.API + api
232
- response = requests.patch(
250
+ response = self.session.patch(
251
+ URL,
252
+ data=json.dumps(data),
253
+ headers={"Authorization": header, "Content-Type": self.content ,"version": "3"},
254
+ )
255
+ self.request_logger.debug({"Status Code":response.status_code, "API":api })
256
+ self.api_logger.debug({"URL": URL, "data": json.dumps(data), \
257
+ "Response Status Code": response.status_code, \
258
+ "Response": response.json()})
259
+ response.raise_for_status()
260
+ return response.json()
261
+
262
+ except requests.HTTPError as e:
263
+ self.api_logger.error({"API":api, "Error": response.json()})
264
+ return response.json()
265
+
266
+ except TypeError as e:
267
+ if "response" in locals():
268
+ self.error_resp["code"] = response.status_code
269
+ else:
270
+ self.error_resp["code"] = -99
271
+ self.error_resp["message"]=self.error_message
272
+ self.api_logger.error({"API": api, "error": e})
273
+ self.api_logger.debug({"URL": URL,"data": json.dumps(data),"message": self.error_resp})
274
+ return self.error_resp
275
+
276
+ except Exception as e:
277
+ if "response" in locals():
278
+ self.error_resp["code"] = response.status_code
279
+ else:
280
+ self.error_resp["code"] = -99
281
+ self.api_logger.error({"API": api, "error": e})
282
+ self.api_logger.debug({"URL": URL,"data": json.dumps(data),"message": e})
283
+ return self.error_resp
284
+
285
+ def put_call(self, api: str, header: str, data) -> dict:
286
+ """
287
+ Makes a PUT request to the specified API.
288
+
289
+ Args:
290
+ api: The API endpoint to make the request to.
291
+ header: The authorization header for the request.
292
+ data: The data to send in the request payload.
293
+
294
+ Returns:
295
+ The response JSON as a dictionary, or the response object if an error occurs.
296
+ """
297
+ try:
298
+ URL = Config.API + api
299
+ response = self.session.put(
233
300
  URL,
234
301
  data=json.dumps(data),
235
302
  headers={"Authorization": header, "Content-Type": self.content ,"version": "3"},
@@ -271,12 +338,15 @@ class FyersServiceAsync:
271
338
 
272
339
  Args:
273
340
  logger: The logger object used for logging errors.
341
+ request_logger: The logger object used for logging requests.
274
342
  """
275
343
  self.api_logger = logger
276
344
  self.request_logger = request_logger
277
345
  self.content = "application/json"
278
346
  self.error_resp = {"s":"error", "code": 0 , "message":"Bad request"}
279
347
  self.error_message = "invalid input please check your input"
348
+ self.session = None
349
+ self._session_created_here = True
280
350
 
281
351
 
282
352
  async def post_async_call(self, api: str, header: str, data=None) -> dict:
@@ -293,18 +363,20 @@ class FyersServiceAsync:
293
363
  """
294
364
  try:
295
365
  url = Config.API + api
296
- async with aiohttp.ClientSession(
297
- headers={"Authorization": header, "Content-Type": self.content ,"version": "3"}
298
- ) as session:
299
- async with session.post(url, data=json.dumps(data)) as response:
300
- self.request_logger.debug({"Status Code":response.status, "API":api })
301
- content = await response.read()
302
- self.api_logger.debug({"URL": url,"Post Data": json.dumps(data), \
303
- "Response Status Code": response.status, \
304
- "Response": json.loads(content)})
305
- response.raise_for_status()
306
- response = await response.json()
307
- return response
366
+ # Create session on first use if not provided
367
+ if self.session is None:
368
+ self.session = aiohttp.ClientSession()
369
+
370
+ headers = {"Authorization": header, "Content-Type": self.content, "version": "3"}
371
+ async with self.session.post(url, data=json.dumps(data), headers=headers) as response:
372
+ self.request_logger.debug({"Status Code":response.status, "API":api })
373
+ content = await response.read()
374
+ self.api_logger.debug({"URL": url,"Post Data": json.dumps(data), \
375
+ "Response Status Code": response.status, \
376
+ "Response": json.loads(content)})
377
+ response.raise_for_status()
378
+ response = await response.json()
379
+ return response
308
380
 
309
381
  except aiohttp.ClientResponseError as e:
310
382
  self.api_logger.error({"Api": api, "Response": json.loads(content)})
@@ -349,20 +421,22 @@ class FyersServiceAsync:
349
421
  URL = Config.DATA_API + api
350
422
  else:
351
423
  URL = Config.API + api
352
- async with aiohttp.ClientSession(
353
- headers={
354
- "Authorization": header,
355
- "Content-Type": self.content,
356
- "version": "3",
357
- }
358
- ) as session:
359
- async with session.get(URL, params=params) as response:
360
- self.request_logger.debug({"Status Code": response.status, "API":api })
361
- content = await response.read()
362
- self.api_logger.debug({"URL": URL, "Status Code": response.status, "Response": json.loads(content)})
363
- response.raise_for_status()
364
- response = await response.json()
365
- return response
424
+ # Create session on first use if not provided
425
+ if self.session is None:
426
+ self.session = aiohttp.ClientSession()
427
+
428
+ headers = {
429
+ "Authorization": header,
430
+ "Content-Type": self.content,
431
+ "version": "3",
432
+ }
433
+ async with self.session.get(URL, params=params, headers=headers) as response:
434
+ self.request_logger.debug({"Status Code": response.status, "API":api })
435
+ content = await response.read()
436
+ self.api_logger.debug({"URL": URL, "Status Code": response.status, "Response": json.loads(content)})
437
+ response.raise_for_status()
438
+ response = await response.json()
439
+ return response
366
440
 
367
441
  except aiohttp.ClientResponseError as e:
368
442
  self.api_logger.error({"Api": api, "Response": json.loads(content)})
@@ -401,18 +475,20 @@ class FyersServiceAsync:
401
475
  """
402
476
  try:
403
477
  url = Config.API + api
404
- async with aiohttp.ClientSession(
405
- headers={"Authorization": header, "Content-Type": self.content ,"version": "3"}
406
- ) as session:
407
- async with session.delete(url, data=json.dumps(data)) as response:
408
- self.request_logger.debug({"Status Code": response.status, "API":api })
409
- content = await response.read()
410
- self.api_logger.debug({"URL": url, "data": json.dumps(data), \
411
- "Response Status Code": response.status, \
412
- "Response": json.loads(content)})
413
- response.raise_for_status()
414
- response = await response.json()
415
- return response
478
+ # Create session on first use if not provided
479
+ if self.session is None:
480
+ self.session = aiohttp.ClientSession()
481
+
482
+ headers = {"Authorization": header, "Content-Type": self.content, "version": "3"}
483
+ async with self.session.delete(url, data=json.dumps(data), headers=headers) as response:
484
+ self.request_logger.debug({"Status Code": response.status, "API":api })
485
+ content = await response.read()
486
+ self.api_logger.debug({"URL": url, "data": json.dumps(data), \
487
+ "Response Status Code": response.status, \
488
+ "Response": json.loads(content)})
489
+ response.raise_for_status()
490
+ response = await response.json()
491
+ return response
416
492
 
417
493
  except aiohttp.ClientResponseError as e:
418
494
  self.api_logger.error({"Api": api, "Response": json.loads(content)})
@@ -451,20 +527,21 @@ class FyersServiceAsync:
451
527
  """
452
528
  try:
453
529
  url = Config.API + api
454
- async with aiohttp.ClientSession(
455
- headers={"Authorization": header, "Content-Type": self.content ,"version": "3"}
456
- ) as session:
457
- json_data = json.dumps(data).encode("utf-8")
458
-
459
- async with session.patch(url, data=json_data) as response:
460
- self.request_logger.debug({"Status Code": response.status, "API":api })
461
- content = await response.read()
462
- self.api_logger.debug({"URL": url, "data": json.dumps(data), \
463
- "Status Code": response.status, \
464
- "Response": json.loads(content)})
465
- response.raise_for_status()
466
- response = await response.json()
467
- return response
530
+ # Create session on first use if not provided
531
+ if self.session is None:
532
+ self.session = aiohttp.ClientSession()
533
+
534
+ json_data = json.dumps(data).encode("utf-8")
535
+ headers = {"Authorization": header, "Content-Type": self.content, "version": "3"}
536
+ async with self.session.patch(url, data=json_data, headers=headers) as response:
537
+ self.request_logger.debug({"Status Code": response.status, "API":api })
538
+ content = await response.read()
539
+ self.api_logger.debug({"URL": url, "data": json.dumps(data), \
540
+ "Status Code": response.status, \
541
+ "Response": json.loads(content)})
542
+ response.raise_for_status()
543
+ response = await response.json()
544
+ return response
468
545
 
469
546
  except aiohttp.ClientResponseError as e:
470
547
  self.api_logger.error({"Api": api, "Response": json.loads(content)})
@@ -489,6 +566,68 @@ class FyersServiceAsync:
489
566
  self.api_logger.debug({"URL": url,"data": json.dumps(data),"message": e})
490
567
  return self.error_resp
491
568
 
569
+ async def put_async_call(self, api: str, header: str, data) -> dict:
570
+ """
571
+ Makes an asynchronous PUT request to the specified API.
572
+
573
+ Args:
574
+ api: The API endpoint to make the request to.
575
+ header: The authorization header for the request.
576
+ data: The data to send in the request payload.
577
+
578
+ Returns:
579
+ The response JSON as a dictionary, or the response object if an error occurs.
580
+ """
581
+ try:
582
+ url = Config.API + api
583
+ # Create session on first use if not provided
584
+ if self.session is None:
585
+ self.session = aiohttp.ClientSession()
586
+
587
+ json_data = json.dumps(data).encode("utf-8")
588
+ headers = {"Authorization": header, "Content-Type": self.content, "version": "3"}
589
+ async with self.session.put(url, data=json_data, headers=headers) as response:
590
+ self.request_logger.debug({"Status Code": response.status, "API":api })
591
+ content = await response.read()
592
+ self.api_logger.debug({"URL": url, "data": json.dumps(data), \
593
+ "Status Code": response.status, \
594
+ "Response": json.loads(content)})
595
+ response.raise_for_status()
596
+ response = await response.json()
597
+ return response
598
+
599
+ except aiohttp.ClientResponseError as e:
600
+ self.api_logger.error({"Api": api, "Response": json.loads(content)})
601
+ return await response.json()
602
+
603
+ except TypeError as e:
604
+ if "response" in locals():
605
+ self.error_resp["code"] = response.status
606
+ else:
607
+ self.error_resp["code"] = -99
608
+ self.error_resp["message"]=self.error_message
609
+ self.api_logger.error({"API": api, "error": e})
610
+ self.api_logger.debug({"URL": url,"data": json.dumps(data),"message": self.error_resp})
611
+ return self.error_resp
612
+
613
+ except Exception as e:
614
+ if "response" in locals():
615
+ self.error_resp["code"] = response.status
616
+ else:
617
+ self.error_resp["code"] = -99
618
+ self.api_logger.error({"API": api, "error": e})
619
+ self.api_logger.debug({"URL": url,"data": json.dumps(data),"message": e})
620
+ return self.error_resp
621
+
622
+ async def close(self):
623
+ """
624
+ Closes the aiohttp session if it was created by this instance.
625
+ Should be called when done with the service to properly clean up resources.
626
+ """
627
+ if self.session is not None and self._session_created_here:
628
+ await self.session.close()
629
+ self.session = None
630
+
492
631
 
493
632
 
494
633
  class SessionModel:
@@ -590,7 +729,7 @@ class FyersModel:
590
729
  if is_async:
591
730
  self.service = FyersServiceAsync(self.api_logger, self.request_logger)
592
731
  else:
593
- self.service = FyersServiceSync(self.api_logger,self.request_logger)
732
+ self.service = FyersServiceSync(self.api_logger, self.request_logger)
594
733
 
595
734
  def get_profile(self) -> dict:
596
735
  """
@@ -814,6 +953,7 @@ class FyersModel:
814
953
  - 'limitPrice' (float): Valid price for Limit and Stoplimit orders. Default: 0.
815
954
  - 'stopPrice' (float): Valid price for Stop and Stoplimit orders. Default: 0.
816
955
  - 'offlineOrder' (bool): Specifies if the order is placed when the market is open (False) or as an AMO order (True).
956
+ - 'isSliceOrder' (bool): Specifies if the order is a slice order. Default: False.
817
957
 
818
958
  Returns:
819
959
  The response JSON as a dictionary.
@@ -1133,4 +1273,560 @@ class FyersModel:
1133
1273
  response = self.service.get_call(
1134
1274
  Config.option_chain, self.header, data, data_flag=True
1135
1275
  )
1136
- return response
1276
+ return response
1277
+
1278
+ def create_alert(self, data) -> dict:
1279
+ """
1280
+ Creates a new price alert for a user.
1281
+
1282
+ Args:
1283
+ data (dict): A dictionary containing the alert details.
1284
+ Required:
1285
+ - alert-type (int): Type of alert. 1 usually means price-based alert.
1286
+ - name (str): User-provided name/label for the alert.
1287
+ - symbol (str): Trading symbol in full format.
1288
+ Eg: "NSE:SBIN-EQ", "NSE:SILVERMIC25DECFUT"
1289
+ - comparisonType (str): Price parameter used for comparison.
1290
+ Allowed: "OPEN", "HIGH", "LOW", "CLOSE", "LTP"
1291
+ - condition (str): Price comparison operator.
1292
+ Allowed: "GT" (greater), "LT" (lesser), "EQ" (equal)
1293
+ - value (float/int/str): Target price against which comparison is performed.
1294
+ Optional:
1295
+ - agent (str): Source of alert creation. Eg: "fyers-api"
1296
+ - notes (str): Additional notes for the alert.
1297
+
1298
+ Returns:
1299
+ The response JSON as a dictionary.
1300
+ """
1301
+ if self.is_async:
1302
+ response = self.service.post_async_call(Config.price_alert, self.header, data)
1303
+ else:
1304
+ response = self.service.post_call(Config.price_alert, self.header, data)
1305
+ return response
1306
+
1307
+ def get_alert(self, data=None) -> dict:
1308
+ """
1309
+ Retrieves alert details. If data with 'id' is provided, filters alerts by ID(s).
1310
+ Otherwise, returns all alerts. Supports fetching archived alerts via 'archive' parameter.
1311
+
1312
+ Args:
1313
+ data (dict, optional): Optional dictionary containing query parameters.
1314
+ - 'archive' (int, optional): Set to 1 to retrieve archived alerts instead of active alerts.
1315
+ Default: 0 (active alerts)
1316
+
1317
+ Returns:
1318
+ The response JSON as a dictionary :
1319
+ """
1320
+ if data is None:
1321
+ data = {}
1322
+
1323
+ if self.is_async:
1324
+ response = self.service.get_async_call(Config.price_alert, self.header, data)
1325
+ else:
1326
+ response = self.service.get_call(Config.price_alert, self.header, data)
1327
+ return response
1328
+
1329
+ def delete_alert(self, data) -> dict:
1330
+ """
1331
+ Deletes a price alert.
1332
+
1333
+ Args:
1334
+ data (dict): A dictionary containing the alert deletion details.
1335
+ Required Attributes:
1336
+ - alertId (str): Alert ID from creation
1337
+ Optional Attributes:
1338
+ - agent (str): Client calling the API (e.g., "fyers-api")
1339
+
1340
+ Returns:
1341
+ The response JSON as a dictionary.
1342
+ """
1343
+ if self.is_async:
1344
+ response = self.service.delete_async_call(Config.price_alert, self.header, data)
1345
+ else:
1346
+ response = self.service.delete_call(Config.price_alert, self.header, data)
1347
+ return response
1348
+
1349
+ def update_alert(self, data) -> dict:
1350
+ """
1351
+ Modifies the parameters of an existing alert based on the provided details.
1352
+
1353
+ Args:
1354
+ data (dict): A dictionary containing the alert modification details.
1355
+ Required Attributes:
1356
+ - alertId (str): ID of the alert to be modified. Eg: "3870991"
1357
+ - alert-type (int): Type of alert. 1 usually means price-based alert.
1358
+ - symbol (str): Trading symbol in full format.
1359
+ Eg: "NSE:SBIN-EQ", "NSE:SILVERMIC25DECFUT"
1360
+ - comparisonType (str): Price parameter used for comparison.
1361
+ Allowed: "OPEN", "HIGH", "LOW", "CLOSE", "LTP"
1362
+ - condition (str): Price comparison operator.
1363
+ Allowed: "GT" (greater), "LT" (lesser), "E" (equal)
1364
+ - value (float/int/str): Target price against which comparison is performed.
1365
+ - name (str): User-provided name/label for the alert.
1366
+ Optional Attributes:
1367
+ - agent (str): Source of alert creation. Eg: "fyers-api"
1368
+
1369
+
1370
+ Returns:
1371
+ The response JSON as a dictionary.
1372
+ """
1373
+ if self.is_async:
1374
+ response = self.service.put_async_call(Config.price_alert, self.header, data)
1375
+ else:
1376
+ response = self.service.put_call(Config.price_alert, self.header, data)
1377
+ return response
1378
+
1379
+ def toggle_alert(self, data) -> dict:
1380
+ """
1381
+ Toggles the status of an existing alert between enabled (1) and disabled (2).
1382
+ If the alert is currently disabled, it will be enabled. If enabled, it will be disabled.
1383
+
1384
+ Args:
1385
+ data (dict): A dictionary containing the alert toggle details.
1386
+ - 'alertId' (str, mandatory): ID of the alert to be toggled. Eg: "3870991"
1387
+
1388
+ Returns:
1389
+ The response JSON as a dictionary with success message indicating the alert status has been modified.
1390
+ """
1391
+ if self.is_async:
1392
+ response = self.service.put_async_call(Config.toggle_alert, self.header, data)
1393
+ else:
1394
+ response = self.service.put_call(Config.toggle_alert, self.header, data)
1395
+ return response
1396
+
1397
+ def create_smart_order_step(self, data: dict) -> dict:
1398
+ """
1399
+ Creates a step smart order based on the provided data.
1400
+
1401
+ Args:
1402
+ data (dict): A dictionary containing the smart order creation details.
1403
+ Required Attributes:
1404
+ - symbol (str): Symbol of the product. Eg: "NSE:SBIN-EQ"
1405
+ - side (int): Side of the order. 1 for Buy, -1 for Sell
1406
+ - qty (int): Total quantity of the product
1407
+ - productType (str): Type of the product. Possible values: 'CNC', 'INTRADAY', 'MARGIN'
1408
+ - avgqty (int): Average quantity per step
1409
+ - avgdiff (int): Average difference between steps
1410
+ - direction (int): Direction of the order
1411
+ - orderType (int): Type of the order
1412
+ - startTime (int): Start time in epoch format
1413
+ - endTime (int): End time in epoch format
1414
+
1415
+ Conditional Attributes:
1416
+ - limitPrice (float): Limit price for the order
1417
+
1418
+ Optional Attributes:
1419
+ - initQty (int): Initial quantity to be placed
1420
+ - hpr (float): Higher price range
1421
+ - lpr (float): Lower price range
1422
+ - mpp (int): Maximum price per order
1423
+
1424
+ Returns:
1425
+ dict: The response JSON as a dictionary.
1426
+ """
1427
+
1428
+
1429
+
1430
+ if self.is_async:
1431
+ response = self.service.post_async_call(Config.create_smartorder_step, self.header, data)
1432
+ else:
1433
+ response = self.service.post_call(Config.create_smartorder_step, self.header, data)
1434
+ return response
1435
+
1436
+ async def close(self):
1437
+ """
1438
+ Closes the HTTP session(s) to properly clean up resources.
1439
+ Should be called when done with the FyersModel instance, especially for async mode.
1440
+ """
1441
+ if self.is_async:
1442
+ if hasattr(self, 'async_session') and self.async_session:
1443
+ await self.async_session.close()
1444
+ self.async_session = None
1445
+ if hasattr(self, 'service') and hasattr(self.service, 'close'):
1446
+ await self.service.close()
1447
+ else:
1448
+ if hasattr(self, 'session') and self.session:
1449
+ self.session.close()
1450
+ self.session = None
1451
+
1452
+
1453
+ def create_smart_order_limit(self,data: dict) -> dict:
1454
+ """
1455
+ Creates a Smart Limit Order based on the provided data.
1456
+
1457
+ Smart Limit Orders allow you to place limit orders that remain active until the specified end time.
1458
+ Once the end time is reached, the order can be converted to an MPP order or cancelled.
1459
+
1460
+ Args:
1461
+ data (dict): A dictionary containing the smart order creation details.
1462
+ Required Attributes:
1463
+ - symbol (str): The instrument's unique identifier, e.g., "NSE:SBIN-EQ"
1464
+ - side (int): Order side: 1 for Buy, -1 for Sell (enum: 1, -1)
1465
+ - qty (int): Order quantity (Min: 1, Max: 999999; must be a multiple of lot size)
1466
+ - productType (str): Must be one of: "CNC", "MARGIN", "INTRADAY", "MTF"
1467
+ - limitPrice (number): The price at which the order should be placed (Min: 0.01)
1468
+ - endTime (int): Order expiry time as a Unix timestamp (epoch)
1469
+ - orderType (int): Order type: 1 for Limit, 4 for Stop-Limit (enum: 1, 4)
1470
+ - onExp (int): Action on expiry: 1 = Cancel, 2 = Market (enum: 1, 2)
1471
+
1472
+ Optional Attributes:
1473
+ - stopPrice (number): Default: 0. Required when orderType is 4 (Stop-Limit)
1474
+ - hpr (number): Default: 0. 0 = no upper price limit. If provided, order executes only below this price
1475
+ - lpr (number): Default: 0. 0 = no lower price limit. If provided, order executes only above this price
1476
+ - mpp (number): Default: 0. 0 = no market protection. Valid values: 0–3 or -1 (disabled)
1477
+
1478
+ Returns:
1479
+ dict: The response JSON as a dictionary.
1480
+ """
1481
+ if self.is_async:
1482
+ response = self.service.post_async_call(Config.create_smartorder_limit, self.header, data)
1483
+ else:
1484
+ response = self.service.post_call(Config.create_smartorder_limit, self.header, data)
1485
+ return response
1486
+
1487
+ def create_smart_order_trail(self, data: dict) -> dict:
1488
+ """
1489
+ Creates a Smart Trail Order (Trailing Stop Loss) based on the provided data.
1490
+
1491
+ A Smart Trail Order is a trailing stop-loss that automatically adjusts the stop price as the market moves
1492
+ in your favour. The stop price trails the market by a specified jump price.
1493
+
1494
+ Args:
1495
+ data (dict): A dictionary containing the smart order creation details.
1496
+ Required Attributes:
1497
+ - symbol (str): The instrument's unique identifier, e.g., "NSE:SBIN-EQ"
1498
+ - side (int): Order side: 1 for Buy, -1 for Sell (enum: 1, -1)
1499
+ - qty (int): Order quantity (Min: 1, Max: 999999; must be a multiple of lot size)
1500
+ - productType (str): Must be one of: "CNC", "MARGIN", "INTRADAY", "MTF"
1501
+ - orderType (int): Order type: 1 for Limit Order, 2 for Market Order (enum: 1, 2)
1502
+ - stopPrice (number): Initial stop/trigger price (must be greater than 0)
1503
+ - jump_diff (number): Jump price — the value by which the stop price trails (Min: 0.2)
1504
+
1505
+ Optional Attributes:
1506
+ - limitPrice (number): Default: 0. If not provided, executes at market price. Required if orderType = 1
1507
+ - target_price (number): Default: 0 (no target). If provided, must be greater than current LTP
1508
+ - mpp (number): Default: 0 (no market protection). Valid values: 0–3 or -1 (disabled)
1509
+
1510
+ Returns:
1511
+ dict: The response JSON as a dictionary.
1512
+ """
1513
+ if self.is_async:
1514
+ response = self.service.post_async_call(Config.create_smartorder_trail, self.header, data)
1515
+ else:
1516
+ response = self.service.post_call(Config.create_smartorder_trail, self.header, data)
1517
+ return response
1518
+
1519
+ def create_smart_order_sip(self, data: dict) -> dict:
1520
+ """
1521
+ Creates a Smart SIP (Systematic Investment Plan) order based on the provided data.
1522
+
1523
+ Smart SIP allows you to automate recurring investments in equity stocks, ETFs, with orders placed automatically
1524
+ at your selected frequency—daily, weekly, monthly, or on custom dates.
1525
+
1526
+ Args:
1527
+ data (dict): A dictionary containing the smart order creation details.
1528
+ Required Attributes:
1529
+ - symbol (str): The instrument's unique identifier (Equity only), e.g., "NSE:SBIN-EQ"
1530
+ - productType (str): Must be one of: "CNC", "MTF"
1531
+ - freq (int): SIP frequency (enum: 1, 2, 3, 6)
1532
+ - sip_day (int): Day of the month for SIP execution (Min: 1, Max: 28)
1533
+ - qty OR amount (int/number): At least one required - Quantity or amount per SIP instalment (Max: 999999)
1534
+
1535
+ Conditional Attributes:
1536
+ - sip_time (int): Required if freq = 1 (Daily). Unix timestamp for SIP execution time (must be within market hours)
1537
+
1538
+ Optional Attributes:
1539
+ - imd_start (bool): Whether to start SIP immediately. true = start now, false = wait for schedule
1540
+ - endTime (int): Default: 0 (no end date). Unix timestamp when the SIP should end
1541
+ - hpr (number): Default: 0. Skips SIP if price is above this upper limit
1542
+ - lpr (number): Default: 0. Skips SIP if price is below this lower limit
1543
+ - step_up_freq (int): Frequency of step-up increase (enum: 3, 5). Default: 0 (no step-up)
1544
+ - step_up_qty (int): Quantity to increase at each step-up (Default: 0; Max: 999999)
1545
+ - step_up_amount (number): Amount to increase at each step-up (Default: 0; Max: 999999)
1546
+ - exp_qty (int): Quantity for expiry/final SIP order (Default: 0; Max: 999999)
1547
+
1548
+ Returns:
1549
+ dict: The response JSON as a dictionary.
1550
+ """
1551
+ if self.is_async:
1552
+ response = self.service.post_async_call(Config.create_smartorder_sip, self.header, data)
1553
+ else:
1554
+ response = self.service.post_call(Config.create_smartorder_sip, self.header, data)
1555
+ return response
1556
+
1557
+
1558
+
1559
+
1560
+ def modify_smart_order(self, data) -> dict:
1561
+ """
1562
+ Modifies a smart order based on the provided data.
1563
+
1564
+ Args:
1565
+ data (dict): A dictionary containing the smart order modification details.
1566
+
1567
+ Required:
1568
+ - flowId (str): Unique identifier of the Smart Order to be modified
1569
+
1570
+ Optional (by order type/flowtype):
1571
+
1572
+ Limit Order (flowtype: 4):
1573
+ - qty (int): To update order quantity
1574
+ - limitPrice (number): To update limit price
1575
+ - stopPrice (number): To update stop/trigger price
1576
+ - endTime (int): To update expiry time (Unix timestamp)
1577
+ - hpr (number): To update upper price limit (High Price Range)
1578
+ - lpr (number): To update lower price limit (Low Price Range)
1579
+ - mpp (number): To update market protection percentage
1580
+ - onExp (int): To update expiry action (1 = Cancel, 2 = Market Order)
1581
+
1582
+ Trail Order (flowtype: 6):
1583
+ - qty (int): To update order quantity
1584
+ - limitPrice (number): To update limit price (required if orderType = 1; must be 0 if orderType = 2)
1585
+ - stopPrice (number): To update stop/trigger price
1586
+ - jump_diff (number): To update jump value for trailing stop
1587
+ - target_price (number): To update target price (optional profit booking)
1588
+ - mpp (number): To update market protection percentage
1589
+
1590
+ Step Order (flowtype: 3):
1591
+ - qty (int): To update total order quantity
1592
+ - startTime (int): To update order start time
1593
+ - endTime (int): To update order end time
1594
+ - hpr (number): To update upper price limit (High Price Range)
1595
+ - lpr (number): To update lower price limit (Low Price Range)
1596
+ - mpp (number): To update market protection percentage
1597
+ - avgqty (int): To update quantity per averaging step
1598
+ - avgdiff (number): To update price gap between steps
1599
+ - initQty (int): To update initial quantity (only before order starts)
1600
+ - limitPrice (number): To update limit price (only before order starts)
1601
+ - direction (int): To update direction for averaging (1 = price drop, -1 = price rise)
1602
+
1603
+ SIP Order (flowtype: 7):
1604
+ - qty (int): To update investment quantity per instalment
1605
+ - amount (number): To update investment amount per instalment
1606
+ - hpr (number): To update upper price limit (skip if price is above this)
1607
+ - lpr (number): To update lower price limit (skip if price is below this)
1608
+ - sip_day (int): To update SIP day (applicable for monthly/custom frequency)
1609
+ - sip_time (int): To update SIP time (required for daily/custom frequency)
1610
+ - step_up_amount (number): To update step-up amount (amount-based SIP only)
1611
+ - step_up_qty (int): To update step-up quantity (qty-based SIP only)
1612
+ - exp_qty (int): To update expiry quantity
1613
+ - exp_amount (number): To update expiry amount
1614
+
1615
+ Returns:
1616
+ The response JSON as a dictionary.
1617
+ """
1618
+ if self.is_async:
1619
+ response = self.service.patch_async_call(Config.modify_smartorder, self.header, data)
1620
+ else:
1621
+ response = self.service.patch_call(Config.modify_smartorder, self.header, data)
1622
+ return response
1623
+
1624
+ def cancel_order(self, data) -> dict:
1625
+ """
1626
+ Cancels a smart order based on the provided data.
1627
+
1628
+ Args:
1629
+ data (dict): A dictionary containing the smart order cancellation details.
1630
+ - flowId (str): Unique identifier of the smart order flow to cancel
1631
+
1632
+ Returns:
1633
+ The response JSON as a dictionary.
1634
+ """
1635
+ if self.is_async:
1636
+ response = self.service.delete_async_call(Config.cancel_smartorder, self.header, data)
1637
+ else:
1638
+ response = self.service.delete_call(Config.cancel_smartorder, self.header, data)
1639
+ return response
1640
+
1641
+ def pause_order(self, data) -> dict:
1642
+ """
1643
+ Pauses a smart order based on the provided data.
1644
+
1645
+ Args:
1646
+ data (dict): A dictionary containing the smart order pause details.
1647
+ - flowId (str): Unique identifier of the smart order flow to pause
1648
+
1649
+ Returns:
1650
+ The response JSON as a dictionary.
1651
+ """
1652
+ if self.is_async:
1653
+ response = self.service.patch_async_call(Config.pause_smartorder, self.header, data)
1654
+ else:
1655
+ response = self.service.patch_call(Config.pause_smartorder, self.header, data)
1656
+ return response
1657
+
1658
+ def resume_order(self, data) -> dict:
1659
+ """
1660
+ Resumes a paused smart order based on the provided data.
1661
+
1662
+ Args:
1663
+ data (dict): A dictionary containing the smart order resume details.
1664
+ - flowId (str): Unique identifier of the smart order flow to resume
1665
+
1666
+ Returns:
1667
+ The response JSON as a dictionary.
1668
+ """
1669
+ if self.is_async:
1670
+ response = self.service.patch_async_call(Config.resume_smartorder, self.header, data)
1671
+ else:
1672
+ response = self.service.patch_call(Config.resume_smartorder, self.header, data)
1673
+ return response
1674
+
1675
+ def smart_orderbook_with_filter(self, data=None) -> dict:
1676
+ """
1677
+ Retrieves smart order book information with optional filters.
1678
+
1679
+ Optional Query Parameters (pass as keys in data dict for GET query params):
1680
+ - flowtype (int[]): Filter by order type (repeatable). 3 = Step, 4 = Limit, 5 = Peg, 6 = Trail, 7 = SIP. Default: all types
1681
+ - messageType (int[]): Filter by order status/message type (repeatable). Default: all
1682
+ - page_no (int): Page number for pagination. Default: 1
1683
+ - page_size (int): Number of records per page. Default: 15
1684
+ - sort_by (str): Sort by field: "CreatedTime", "UpdatedTime", "Alphabet". Default: "UpdatedTime"
1685
+ - ord_by (int): Sort order: 1 for ascending, -1 for descending. Default: -1
1686
+ - side (int[]): Filter by side (repeatable). 1 for buy, -1 for sell. Default: all
1687
+ - exchange (str[]): Filter by exchange (repeatable). "NSE", "BSE", "MCX". Default: all
1688
+ - product (str[]): Filter by product type (repeatable). "CNC", "MARGIN", "INTRADAY", "MTF". Default: all
1689
+ - search (str): Search by symbol name. Default: none
1690
+
1691
+ Args:
1692
+ data (dict, optional): A dictionary containing the optional query parameters above.
1693
+
1694
+ Returns:
1695
+ The response JSON as a dictionary.
1696
+ """
1697
+ if self.is_async:
1698
+ response = self.service.get_async_call(Config.smartorder_orderbook, self.header, data)
1699
+ else:
1700
+ response = self.service.get_call(Config.smartorder_orderbook, self.header, data)
1701
+ return response
1702
+
1703
+
1704
+ def create_smartexit_trigger(self, data) -> dict:
1705
+ """
1706
+ Creates a new smart exit trigger based on the provided data.
1707
+
1708
+ Smart exit triggers support three types of strategies:
1709
+
1710
+ Type 1: Only Alert (notification only, no auto-exit)
1711
+ - Sends notification when profit/loss thresholds are reached
1712
+ - Does not automatically exit positions
1713
+ - Example:
1714
+ {
1715
+ "name": "Alert Only Strategy",
1716
+ "type": 1,
1717
+ "profitRate": 5000,
1718
+ "lossRate": -2000
1719
+ }
1720
+
1721
+ Type 2: Exit with Alert (notification + immediate exit)
1722
+ - Sends notification and immediately exits positions when thresholds are reached
1723
+ - Example:
1724
+ {
1725
+ "name": "Auto Exit Strategy",
1726
+ "type": 2,
1727
+ "profitRate": 5000,
1728
+ "lossRate": -2000
1729
+ }
1730
+
1731
+ Type 3: Exit with Alert + Wait for Recovery (notification + delayed exit)
1732
+ - Sends notification and waits for recovery before exiting
1733
+ - Requires waitTime parameter (in minutes)
1734
+ - Example:
1735
+ {
1736
+ "name": "Recovery Exit Strategy",
1737
+ "type": 3,
1738
+ "profitRate": 10000,
1739
+ "lossRate": -3000,
1740
+ "waitTime": 5
1741
+ }
1742
+
1743
+ Args:
1744
+ data (dict): A dictionary containing the smart exit trigger creation details.
1745
+ - name (str): Name of the smart exit trigger strategy
1746
+ - type (int): Type of the trigger (1: Alert only, 2: Exit with alert, 3: Exit with alert + wait for recovery)
1747
+ - profitRate (float): Profit rate threshold (positive value, e.g., 5000)
1748
+ - lossRate (float): Loss rate threshold (negative value, e.g., -2000)
1749
+ - waitTime (int, optional): Wait time in minutes (required for type 3, default: 0)
1750
+
1751
+ """
1752
+ if self.is_async:
1753
+ response = self.service.post_async_call(Config.smartexit_trigger, self.header, data)
1754
+ else:
1755
+ response = self.service.post_call(Config.smartexit_trigger, self.header, data)
1756
+ return response
1757
+
1758
+ def get_smartexit_triggers(self, data=None) -> dict:
1759
+ """
1760
+ Retrieves smart exit trigger information.
1761
+
1762
+ Args:
1763
+ data (dict, optional): A dictionary containing parameters for filtering smart exit triggers.
1764
+
1765
+ Returns:
1766
+ The response JSON as a dictionary.
1767
+ """
1768
+ if self.is_async:
1769
+ response = self.service.get_async_call(Config.smartexit_trigger, self.header, data)
1770
+ else:
1771
+ response = self.service.get_call(Config.smartexit_trigger, self.header, data)
1772
+ return response
1773
+
1774
+ def update_smartexit_trigger(self, data) -> dict:
1775
+ """
1776
+ Updates an existing smart exit trigger based on the provided data.
1777
+
1778
+ Use this endpoint to modify a Smart Exit trigger. You can update the target values, exit type, or wait time.
1779
+ If the trigger is active, updates are validated against the current P&L.
1780
+ Either a profit target or a loss limit must be provided.
1781
+
1782
+ Exit Types (type field):
1783
+ - Value 1: Only Alert - Notification Only
1784
+ Sends a notification when target is hit. Does NOT exit positions automatically.
1785
+ - Value 2: Exit with Alert - Notification + Immediate Exit
1786
+ Sends notification AND exits all intraday positions immediately.
1787
+ - Value 3: Exit with Alert (Wait for Recovery) - Notification + Delayed Exit
1788
+ Sends notification, waits for waitTime minutes, then exits positions.
1789
+
1790
+ Args:
1791
+ data (dict): A dictionary containing the smart exit trigger update details.
1792
+ Required Attributes:
1793
+ - flowId (str): The unique identifier of the smart exit to update
1794
+
1795
+ Optional Attributes:
1796
+ - name (str): Unique name for your Smart Exit trigger
1797
+ - profitRate (number): Book profit value (positive) or Minimize loss value (negative).
1798
+ (Min: -1,00,00,000, Max: 1,00,00,000)
1799
+ - lossRate (number): Max loss value (negative) or Min profit value (positive).
1800
+ (Min: -1,00,00,000, Max: 1,00,00,000)
1801
+ - type (int): Exit type (enum: 1, 2, 3). Default is 1 if not provided.
1802
+ - waitTime (int): Wait time in minutes (required if type=3). Default: 0 (Min: 0, Max: 60)
1803
+
1804
+ Note: Either profitRate or lossRate must be provided.
1805
+
1806
+ Returns:
1807
+ The response JSON as a dictionary.
1808
+ """
1809
+ if self.is_async:
1810
+ response = self.service.put_async_call(Config.smartexit_trigger, self.header, data)
1811
+ else:
1812
+ response = self.service.put_call(Config.smartexit_trigger, self.header, data)
1813
+ return response
1814
+
1815
+ def activate_deactivate_smartexit_trigger(self, data) -> dict:
1816
+ """
1817
+ Activates a smart exit trigger based on the provided data.
1818
+
1819
+ Args:
1820
+ data (dict): A dictionary containing the smart exit trigger activation details.
1821
+ - flowId (str): Unique identifier of the smart exit trigger flow to activate
1822
+
1823
+ Returns:
1824
+ The response JSON as a dictionary.
1825
+ """
1826
+ if self.is_async:
1827
+ response = self.service.post_async_call(Config.activate_smartexit_trigger, self.header, data)
1828
+ else:
1829
+ response = self.service.post_call(Config.activate_smartexit_trigger, self.header, data)
1830
+ return response
1831
+
1832
+
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: fyers_apiv3
3
- Version: 3.1.7
3
+ Version: 3.1.9
4
4
  Summary: Fyers trading APIs.
5
5
  Home-page: https://github.com/FyersDev/fyers-api-sample-code/tree/sample_v3/v3/python
6
6
  Author: Fyers-Tech
@@ -15,13 +15,14 @@ Requires-Dist: asyncio==3.4.3
15
15
  Requires-Dist: aiohttp==3.9.3
16
16
  Requires-Dist: aws_lambda_powertools==1.25.5
17
17
  Requires-Dist: websocket-client==1.6.1
18
- Requires-Dist: protobuf==5.29.3
18
+ Requires-Dist: setuptools==68.0.0
19
19
  Dynamic: author
20
20
  Dynamic: author-email
21
21
  Dynamic: classifier
22
22
  Dynamic: description
23
23
  Dynamic: description-content-type
24
24
  Dynamic: home-page
25
+ Dynamic: license-file
25
26
  Dynamic: requires-dist
26
27
  Dynamic: summary
27
28
 
@@ -181,7 +182,8 @@ data = {
181
182
  "disclosedQty":0,
182
183
  "offlineOrder":False,
183
184
  "stopLoss":0,
184
- "takeProfit":0
185
+ "takeProfit":0,
186
+ "isSliceOrder":False
185
187
  } ## This is a sample example to place a limit order you can make the further changes based on your requriements
186
188
 
187
189
  print(fyers.place_order(data))
@@ -349,6 +351,230 @@ data = {"symbol":"NSE:SBIN-EQ","ohlcv_flag":"1"}
349
351
  print(fyers.depth(data))
350
352
 
351
353
 
354
+ #################################################################################################################
355
+
356
+ """
357
+ PRICE ALERTS : This includes following APIs (create_alert, get_alert, update_alert, delete_alert, toggle_alert)
358
+ """
359
+
360
+ ## Create Price Alert
361
+ data = {
362
+ "agent": "fyers-api",
363
+ "alert-type": 1,
364
+ "name": "gold alert",
365
+ "symbol": "NSE:GOLDBEES-EQ",
366
+ "comparisonType": "LTP",
367
+ "condition": "GT",
368
+ "value": "9888",
369
+ "notes": " iji"
370
+ }
371
+
372
+ print(fyers.create_alert(data))
373
+
374
+ ## Get Price Alerts
375
+ # Get all active alerts
376
+ print(fyers.get_alert())
377
+
378
+ # Get archived alerts
379
+ data = {"archive": "1"}
380
+ print(fyers.get_alert(data))
381
+
382
+ ## Update Price Alert
383
+ data = {
384
+ "alertId": "6249977",
385
+ "agent": "fyers-api",
386
+ "alert-type": 1,
387
+ "name": "goldy bees",
388
+ "symbol": "NSE:GOLDBEES-EQ",
389
+ "comparisonType": "OPEN",
390
+ "condition": "GT",
391
+ "value": "10000.00676766767676676667"
392
+ }
393
+
394
+ print(fyers.update_alert(data))
395
+
396
+ ## Delete Price Alert
397
+ data = {"alertId": "6131416", "agent": "fyers-api"}
398
+ print(fyers.delete_alert(data))
399
+
400
+ ## Toggle Price Alert (Enable/Disable)
401
+ data = {"alertId": "3870991"}
402
+ print(fyers.toggle_alert(data))
403
+
404
+
405
+ #################################################################################################################
406
+
407
+ """
408
+ SMART ORDERS : This includes following APIs (create, modify, cancel, pause, resume, orderbook)
409
+ Smart orders support different flow types: step, limit, trail, sip
410
+ """
411
+
412
+ ## Create Smart Order - Step
413
+ data = {
414
+ "symbol": "NSE:SBIN-EQ",
415
+ "qty": 10,
416
+ "type": 1,
417
+ "side": 1,
418
+ "productType": "INTRADAY",
419
+ "limitPrice": 600.00,
420
+ "stopPrice": 0,
421
+ "validity": "DAY",
422
+ "disclosedQty": 0,
423
+ "offlineOrder": False
424
+ }
425
+
426
+ print(fyers.create_smart_order_step(data))
427
+
428
+ ## Create Smart Order - Limit
429
+ data = {
430
+ "symbol": "NSE:SBIN-EQ",
431
+ "qty": 10,
432
+ "type": 1,
433
+ "side": 1,
434
+ "productType": "INTRADAY",
435
+ "limitPrice": 600.00,
436
+ "stopPrice": 0,
437
+ "validity": "DAY",
438
+ "disclosedQty": 0,
439
+ "offlineOrder": False
440
+ }
441
+
442
+ print(fyers.create_smart_order_limit(data))
443
+
444
+ ## Create Smart Order - Trail
445
+ data = {
446
+ "symbol": "NSE:SBIN-EQ",
447
+ "qty": 10,
448
+ "type": 1,
449
+ "side": 1,
450
+ "productType": "INTRADAY",
451
+ "limitPrice": 600.00,
452
+ "stopPrice": 0,
453
+ "validity": "DAY",
454
+ "disclosedQty": 0,
455
+ "offlineOrder": False
456
+ }
457
+
458
+ print(fyers.create_smart_order_trail(data))
459
+
460
+ ## Create Smart Order - SIP
461
+ data = {
462
+ "symbol": "NSE:SBIN-EQ",
463
+ "qty": 10,
464
+ "type": 1,
465
+ "side": 1,
466
+ "productType": "CNC",
467
+ "limitPrice": 600.00,
468
+ "stopPrice": 0,
469
+ "validity": "DAY",
470
+ "disclosedQty": 0,
471
+ "offlineOrder": False
472
+ }
473
+
474
+ print(fyers.create_smart_order_sip(data))
475
+
476
+ ## Modify Smart Order
477
+ data = {
478
+ "flowId": "123456789",
479
+ "limitPrice": 610.00,
480
+ "qty": 15
481
+ }
482
+
483
+ print(fyers.modify_smart_order(data))
484
+
485
+ ## Cancel Smart Order
486
+ data = {"flowId": "123456789"}
487
+ print(fyers.cancel_order(data))
488
+
489
+ ## Pause Smart Order
490
+ data = {"flowId": "123456789"}
491
+ print(fyers.pause_order(data))
492
+
493
+ ## Resume Smart Order
494
+ data = {"flowId": "123456789"}
495
+ print(fyers.resume_order(data))
496
+
497
+ ## Get Smart Order Book with Filter
498
+ # Get all smart orders
499
+ print(fyers.smart_orderbook_with_filter())
500
+
501
+ # Get filtered smart orders
502
+ # Filter by side (1 for Buy, -1 for Sell)
503
+ data = {"side": [1]}
504
+ print(fyers.smart_orderbook_with_filter(data))
505
+
506
+ # Filter by multiple parameters
507
+ data = {
508
+ "exchange": ["NSE"],
509
+ "side": [1, -1],
510
+ "flowtype": [1, 2],
511
+ "product": ["CNC", "INTRADAY"],
512
+ "messageType": [1, 2],
513
+ "search": "SBIN",
514
+ "sort_by": "CreatedTime",
515
+ "ord_by": 1,
516
+ "page_no": 1,
517
+ "page_size": 15
518
+ }
519
+ print(fyers.smart_orderbook_with_filter(data))
520
+
521
+
522
+ #################################################################################################################
523
+
524
+ """
525
+ SMART EXIT TRIGGERS : This includes following APIs (create, get, update, activate)
526
+ """
527
+
528
+ ## Create Smart Exit Trigger
529
+
530
+ # Type 1: Only Alert (notification only, no auto-exit)
531
+ data = {
532
+ "name": "Alert Only Strategy",
533
+ "type": 1,
534
+ "profitRate": 5000,
535
+ "lossRate": -2000
536
+ }
537
+ print(fyers.create_smartexit_trigger(data))
538
+
539
+ # Type 2: Exit with Alert (notification + immediate exit)
540
+ data = {
541
+ "name": "Auto Exit Strategy",
542
+ "type": 2,
543
+ "profitRate": 5000,
544
+ "lossRate": -2000
545
+ }
546
+ print(fyers.create_smartexit_trigger(data))
547
+
548
+ # Type 3: Exit with Alert + Wait for Recovery (notification + delayed exit)
549
+ data = {
550
+ "name": "Recovery Exit Strategy",
551
+ "type": 3,
552
+ "profitRate": 10000,
553
+ "lossRate": -3000,
554
+ "waitTime": 5
555
+ }
556
+ print(fyers.create_smartexit_trigger(data))
557
+
558
+ ## Get Smart Exit Triggers
559
+ # Get all smart exit triggers
560
+ print(fyers.get_smartexit_triggers())
561
+
562
+
563
+ ## Update Smart Exit Trigger
564
+ data = {
565
+ "flowId": "123456789",
566
+ "triggerPrice": 610.00,
567
+ "stopLoss": 600.00,
568
+ "takeProfit": 630.00
569
+ }
570
+
571
+ print(fyers.update_smartexit_trigger(data))
572
+
573
+ ## Activate Smart Exit Trigger
574
+ data = {"flowId": "123456789"}
575
+ print(fyers.activate_smartexit_trigger(data))
576
+
577
+
352
578
  ```
353
579
 
354
580
  ## Getting started with Data Socket
@@ -436,43 +662,61 @@ from fyers_apiv3.FyersWebsocket import order_ws
436
662
 
437
663
  def onTrade(message):
438
664
  """
439
- Callback function to handle incoming messages from the FyersDataSocket WebSocket.
665
+ Callback function to handle incoming trade messages from the FyersOrderSocket WebSocket.
440
666
 
441
667
  Parameters:
442
668
  message (dict): The received message from the WebSocket.
443
-
669
+ - message["trades"]: Contains trade data including id_fyers field if present
670
+ - message["s"]: Status of the message
671
+
672
+ Note: The message may contain an "id_fyers" field in the trades data, which is a unique identifier
673
+ for Fyers-specific trade tracking.
444
674
  """
445
675
  print("Trade Response:", message)
446
676
 
677
+
447
678
  def onOrder(message):
448
679
  """
449
- Callback function to handle incoming messages from the FyersDataSocket WebSocket.
680
+ Callback function to handle incoming order messages from the FyersOrderSocket WebSocket.
450
681
 
451
682
  Parameters:
452
683
  message (dict): The received message from the WebSocket.
453
-
684
+ - message["orders"]: Contains order data including id_fyers field if present
685
+ - message["s"]: Status of the message
686
+
687
+ Note: The message may contain an "id_fyers" field in the orders data, which is a unique identifier
688
+ for Fyers-specific order tracking.
454
689
  """
455
690
  print("Order Response:", message)
456
691
 
692
+
457
693
  def onPosition(message):
458
694
  """
459
- Callback function to handle incoming messages from the FyersDataSocket WebSocket.
695
+ Callback function to handle incoming position messages from the FyersOrderSocket WebSocket.
460
696
 
461
697
  Parameters:
462
698
  message (dict): The received message from the WebSocket.
463
-
699
+ - message["positions"]: Contains position data including id_fyers field if present
700
+ - message["s"]: Status of the message
701
+
464
702
  """
465
703
  print("Position Response:", message)
466
704
 
705
+
467
706
  def onGeneral(message):
468
707
  """
469
- Callback function to handle incoming messages from the FyersDataSocket WebSocket.
708
+ Callback function to handle incoming general messages from the FyersOrderSocket WebSocket.
709
+ This includes eDIS updates, price alerts, and login events.
470
710
 
471
711
  Parameters:
472
712
  message (dict): The received message from the WebSocket.
713
+ - May contain price alerts with id_fyers field if present
714
+ - May contain eDIS updates
715
+ - May contain login events
473
716
 
474
717
  """
475
718
  print("General Response:", message)
719
+
476
720
  def onerror(message):
477
721
  """
478
722
  Callback function to handle WebSocket errors.
@@ -1,15 +1,15 @@
1
1
  fyers_apiv3/__init__.py,sha256=1vA_F8dAtLKcyOqrmdUOkw1Syl8gIFUtxDoLde8y94E,18
2
- fyers_apiv3/fyersModel.py,sha256=MHo1NWgphuZBUx-t1VAnqsuLZZS_-9P5xwWOBMIwj_U,45096
2
+ fyers_apiv3/fyersModel.py,sha256=ov1YZqRAtrE6nP7GG19nK8b2jHABHPMSBwbm9YTFGdY,78536
3
3
  fyers_apiv3/fyers_logger.py,sha256=S_WiIwBLytQ_tyHd9bUC8gZo7GHpANCJO0CS6rCJE90,3795
4
4
  fyers_apiv3/FyersWebsocket/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  fyers_apiv3/FyersWebsocket/data_ws.py,sha256=fSNfsUB_I5-MkWX4hQZvklRQhuQ9n3w5hMDRFrMaBE8,68105
6
6
  fyers_apiv3/FyersWebsocket/defines.py,sha256=mhKkkQ6FZHFa6e0_83cRYMOucmSn5yHtcod1Jn2ygCc,1143
7
7
  fyers_apiv3/FyersWebsocket/map.json,sha256=GfAgk-zqzUki5Cu0ZlG08PiMhfKTyGIsPo62mIYotZ4,10075
8
8
  fyers_apiv3/FyersWebsocket/msg_pb2.py,sha256=Po6emBFB6aCmt3rkuN6zjDA7JEzsixejfNSOQYtYgnE,6272
9
- fyers_apiv3/FyersWebsocket/order_ws.py,sha256=npLBtCcpPxclc5YRaVtLvBkRDCF3oV9NabK_y5EwoAk,16998
9
+ fyers_apiv3/FyersWebsocket/order_ws.py,sha256=B0ioHcFinlu40zIYWiU6nLpiEmID3317R_9gdmiPh5M,17451
10
10
  fyers_apiv3/FyersWebsocket/tbt_ws.py,sha256=rlg0taA9KCS8YbyKZ8UxqRw5rUcqRETz0sbM9KBUcF0,21191
11
- fyers_apiv3-3.1.7.dist-info/LICENSE.txt,sha256=_a5I4lWvSmoZQxwGSPGVVvUbuYby780N9YevsBqNY3k,1063
12
- fyers_apiv3-3.1.7.dist-info/METADATA,sha256=JOgjxfBjmTzfhPPt_A0rxaA_ThhD1Tf9_7TZBtKfTro,19232
13
- fyers_apiv3-3.1.7.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
14
- fyers_apiv3-3.1.7.dist-info/top_level.txt,sha256=IaT774gXqIM6uJpgCQPvXruJBOINsupO9oTe2ao6pkc,12
15
- fyers_apiv3-3.1.7.dist-info/RECORD,,
11
+ fyers_apiv3-3.1.9.dist-info/licenses/LICENSE.txt,sha256=_a5I4lWvSmoZQxwGSPGVVvUbuYby780N9YevsBqNY3k,1063
12
+ fyers_apiv3-3.1.9.dist-info/METADATA,sha256=oNJNLy6DpYePTpsdn9B5s-K-tA7UqlkGO3TKw8i8vdg,25190
13
+ fyers_apiv3-3.1.9.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
14
+ fyers_apiv3-3.1.9.dist-info/top_level.txt,sha256=IaT774gXqIM6uJpgCQPvXruJBOINsupO9oTe2ao6pkc,12
15
+ fyers_apiv3-3.1.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.2)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5