fyers-apiv3 3.1.8__tar.gz → 3.1.9__tar.gz
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.
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/PKG-INFO +252 -9
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/README.md +251 -8
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3/fyersModel.py +568 -117
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3.egg-info/PKG-INFO +252 -9
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/setup.py +4 -4
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/LICENSE.txt +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3/FyersWebsocket/__init__.py +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3/FyersWebsocket/data_ws.py +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3/FyersWebsocket/defines.py +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3/FyersWebsocket/map.json +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3/FyersWebsocket/msg_pb2.py +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3/FyersWebsocket/order_ws.py +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3/FyersWebsocket/tbt_ws.py +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3/__init__.py +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3/fyers_logger.py +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3.egg-info/SOURCES.txt +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3.egg-info/dependency_links.txt +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3.egg-info/requires.txt +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/fyers_apiv3.egg-info/top_level.txt +0 -0
- {fyers_apiv3-3.1.8 → fyers_apiv3-3.1.9}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fyers_apiv3
|
|
3
|
-
Version: 3.1.
|
|
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
|
|
@@ -182,7 +182,8 @@ data = {
|
|
|
182
182
|
"disclosedQty":0,
|
|
183
183
|
"offlineOrder":False,
|
|
184
184
|
"stopLoss":0,
|
|
185
|
-
"takeProfit":0
|
|
185
|
+
"takeProfit":0,
|
|
186
|
+
"isSliceOrder":False
|
|
186
187
|
} ## This is a sample example to place a limit order you can make the further changes based on your requriements
|
|
187
188
|
|
|
188
189
|
print(fyers.place_order(data))
|
|
@@ -350,6 +351,230 @@ data = {"symbol":"NSE:SBIN-EQ","ohlcv_flag":"1"}
|
|
|
350
351
|
print(fyers.depth(data))
|
|
351
352
|
|
|
352
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
|
+
|
|
353
578
|
```
|
|
354
579
|
|
|
355
580
|
## Getting started with Data Socket
|
|
@@ -437,43 +662,61 @@ from fyers_apiv3.FyersWebsocket import order_ws
|
|
|
437
662
|
|
|
438
663
|
def onTrade(message):
|
|
439
664
|
"""
|
|
440
|
-
Callback function to handle incoming messages from the
|
|
665
|
+
Callback function to handle incoming trade messages from the FyersOrderSocket WebSocket.
|
|
441
666
|
|
|
442
667
|
Parameters:
|
|
443
668
|
message (dict): The received message from the WebSocket.
|
|
444
|
-
|
|
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.
|
|
445
674
|
"""
|
|
446
675
|
print("Trade Response:", message)
|
|
447
676
|
|
|
677
|
+
|
|
448
678
|
def onOrder(message):
|
|
449
679
|
"""
|
|
450
|
-
Callback function to handle incoming messages from the
|
|
680
|
+
Callback function to handle incoming order messages from the FyersOrderSocket WebSocket.
|
|
451
681
|
|
|
452
682
|
Parameters:
|
|
453
683
|
message (dict): The received message from the WebSocket.
|
|
454
|
-
|
|
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.
|
|
455
689
|
"""
|
|
456
690
|
print("Order Response:", message)
|
|
457
691
|
|
|
692
|
+
|
|
458
693
|
def onPosition(message):
|
|
459
694
|
"""
|
|
460
|
-
Callback function to handle incoming messages from the
|
|
695
|
+
Callback function to handle incoming position messages from the FyersOrderSocket WebSocket.
|
|
461
696
|
|
|
462
697
|
Parameters:
|
|
463
698
|
message (dict): The received message from the WebSocket.
|
|
464
|
-
|
|
699
|
+
- message["positions"]: Contains position data including id_fyers field if present
|
|
700
|
+
- message["s"]: Status of the message
|
|
701
|
+
|
|
465
702
|
"""
|
|
466
703
|
print("Position Response:", message)
|
|
467
704
|
|
|
705
|
+
|
|
468
706
|
def onGeneral(message):
|
|
469
707
|
"""
|
|
470
|
-
Callback function to handle incoming messages from the
|
|
708
|
+
Callback function to handle incoming general messages from the FyersOrderSocket WebSocket.
|
|
709
|
+
This includes eDIS updates, price alerts, and login events.
|
|
471
710
|
|
|
472
711
|
Parameters:
|
|
473
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
|
|
474
716
|
|
|
475
717
|
"""
|
|
476
718
|
print("General Response:", message)
|
|
719
|
+
|
|
477
720
|
def onerror(message):
|
|
478
721
|
"""
|
|
479
722
|
Callback function to handle WebSocket errors.
|
|
@@ -154,7 +154,8 @@ data = {
|
|
|
154
154
|
"disclosedQty":0,
|
|
155
155
|
"offlineOrder":False,
|
|
156
156
|
"stopLoss":0,
|
|
157
|
-
"takeProfit":0
|
|
157
|
+
"takeProfit":0,
|
|
158
|
+
"isSliceOrder":False
|
|
158
159
|
} ## This is a sample example to place a limit order you can make the further changes based on your requriements
|
|
159
160
|
|
|
160
161
|
print(fyers.place_order(data))
|
|
@@ -322,6 +323,230 @@ data = {"symbol":"NSE:SBIN-EQ","ohlcv_flag":"1"}
|
|
|
322
323
|
print(fyers.depth(data))
|
|
323
324
|
|
|
324
325
|
|
|
326
|
+
#################################################################################################################
|
|
327
|
+
|
|
328
|
+
"""
|
|
329
|
+
PRICE ALERTS : This includes following APIs (create_alert, get_alert, update_alert, delete_alert, toggle_alert)
|
|
330
|
+
"""
|
|
331
|
+
|
|
332
|
+
## Create Price Alert
|
|
333
|
+
data = {
|
|
334
|
+
"agent": "fyers-api",
|
|
335
|
+
"alert-type": 1,
|
|
336
|
+
"name": "gold alert",
|
|
337
|
+
"symbol": "NSE:GOLDBEES-EQ",
|
|
338
|
+
"comparisonType": "LTP",
|
|
339
|
+
"condition": "GT",
|
|
340
|
+
"value": "9888",
|
|
341
|
+
"notes": " iji"
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
print(fyers.create_alert(data))
|
|
345
|
+
|
|
346
|
+
## Get Price Alerts
|
|
347
|
+
# Get all active alerts
|
|
348
|
+
print(fyers.get_alert())
|
|
349
|
+
|
|
350
|
+
# Get archived alerts
|
|
351
|
+
data = {"archive": "1"}
|
|
352
|
+
print(fyers.get_alert(data))
|
|
353
|
+
|
|
354
|
+
## Update Price Alert
|
|
355
|
+
data = {
|
|
356
|
+
"alertId": "6249977",
|
|
357
|
+
"agent": "fyers-api",
|
|
358
|
+
"alert-type": 1,
|
|
359
|
+
"name": "goldy bees",
|
|
360
|
+
"symbol": "NSE:GOLDBEES-EQ",
|
|
361
|
+
"comparisonType": "OPEN",
|
|
362
|
+
"condition": "GT",
|
|
363
|
+
"value": "10000.00676766767676676667"
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
print(fyers.update_alert(data))
|
|
367
|
+
|
|
368
|
+
## Delete Price Alert
|
|
369
|
+
data = {"alertId": "6131416", "agent": "fyers-api"}
|
|
370
|
+
print(fyers.delete_alert(data))
|
|
371
|
+
|
|
372
|
+
## Toggle Price Alert (Enable/Disable)
|
|
373
|
+
data = {"alertId": "3870991"}
|
|
374
|
+
print(fyers.toggle_alert(data))
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
#################################################################################################################
|
|
378
|
+
|
|
379
|
+
"""
|
|
380
|
+
SMART ORDERS : This includes following APIs (create, modify, cancel, pause, resume, orderbook)
|
|
381
|
+
Smart orders support different flow types: step, limit, trail, sip
|
|
382
|
+
"""
|
|
383
|
+
|
|
384
|
+
## Create Smart Order - Step
|
|
385
|
+
data = {
|
|
386
|
+
"symbol": "NSE:SBIN-EQ",
|
|
387
|
+
"qty": 10,
|
|
388
|
+
"type": 1,
|
|
389
|
+
"side": 1,
|
|
390
|
+
"productType": "INTRADAY",
|
|
391
|
+
"limitPrice": 600.00,
|
|
392
|
+
"stopPrice": 0,
|
|
393
|
+
"validity": "DAY",
|
|
394
|
+
"disclosedQty": 0,
|
|
395
|
+
"offlineOrder": False
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
print(fyers.create_smart_order_step(data))
|
|
399
|
+
|
|
400
|
+
## Create Smart Order - Limit
|
|
401
|
+
data = {
|
|
402
|
+
"symbol": "NSE:SBIN-EQ",
|
|
403
|
+
"qty": 10,
|
|
404
|
+
"type": 1,
|
|
405
|
+
"side": 1,
|
|
406
|
+
"productType": "INTRADAY",
|
|
407
|
+
"limitPrice": 600.00,
|
|
408
|
+
"stopPrice": 0,
|
|
409
|
+
"validity": "DAY",
|
|
410
|
+
"disclosedQty": 0,
|
|
411
|
+
"offlineOrder": False
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
print(fyers.create_smart_order_limit(data))
|
|
415
|
+
|
|
416
|
+
## Create Smart Order - Trail
|
|
417
|
+
data = {
|
|
418
|
+
"symbol": "NSE:SBIN-EQ",
|
|
419
|
+
"qty": 10,
|
|
420
|
+
"type": 1,
|
|
421
|
+
"side": 1,
|
|
422
|
+
"productType": "INTRADAY",
|
|
423
|
+
"limitPrice": 600.00,
|
|
424
|
+
"stopPrice": 0,
|
|
425
|
+
"validity": "DAY",
|
|
426
|
+
"disclosedQty": 0,
|
|
427
|
+
"offlineOrder": False
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
print(fyers.create_smart_order_trail(data))
|
|
431
|
+
|
|
432
|
+
## Create Smart Order - SIP
|
|
433
|
+
data = {
|
|
434
|
+
"symbol": "NSE:SBIN-EQ",
|
|
435
|
+
"qty": 10,
|
|
436
|
+
"type": 1,
|
|
437
|
+
"side": 1,
|
|
438
|
+
"productType": "CNC",
|
|
439
|
+
"limitPrice": 600.00,
|
|
440
|
+
"stopPrice": 0,
|
|
441
|
+
"validity": "DAY",
|
|
442
|
+
"disclosedQty": 0,
|
|
443
|
+
"offlineOrder": False
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
print(fyers.create_smart_order_sip(data))
|
|
447
|
+
|
|
448
|
+
## Modify Smart Order
|
|
449
|
+
data = {
|
|
450
|
+
"flowId": "123456789",
|
|
451
|
+
"limitPrice": 610.00,
|
|
452
|
+
"qty": 15
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
print(fyers.modify_smart_order(data))
|
|
456
|
+
|
|
457
|
+
## Cancel Smart Order
|
|
458
|
+
data = {"flowId": "123456789"}
|
|
459
|
+
print(fyers.cancel_order(data))
|
|
460
|
+
|
|
461
|
+
## Pause Smart Order
|
|
462
|
+
data = {"flowId": "123456789"}
|
|
463
|
+
print(fyers.pause_order(data))
|
|
464
|
+
|
|
465
|
+
## Resume Smart Order
|
|
466
|
+
data = {"flowId": "123456789"}
|
|
467
|
+
print(fyers.resume_order(data))
|
|
468
|
+
|
|
469
|
+
## Get Smart Order Book with Filter
|
|
470
|
+
# Get all smart orders
|
|
471
|
+
print(fyers.smart_orderbook_with_filter())
|
|
472
|
+
|
|
473
|
+
# Get filtered smart orders
|
|
474
|
+
# Filter by side (1 for Buy, -1 for Sell)
|
|
475
|
+
data = {"side": [1]}
|
|
476
|
+
print(fyers.smart_orderbook_with_filter(data))
|
|
477
|
+
|
|
478
|
+
# Filter by multiple parameters
|
|
479
|
+
data = {
|
|
480
|
+
"exchange": ["NSE"],
|
|
481
|
+
"side": [1, -1],
|
|
482
|
+
"flowtype": [1, 2],
|
|
483
|
+
"product": ["CNC", "INTRADAY"],
|
|
484
|
+
"messageType": [1, 2],
|
|
485
|
+
"search": "SBIN",
|
|
486
|
+
"sort_by": "CreatedTime",
|
|
487
|
+
"ord_by": 1,
|
|
488
|
+
"page_no": 1,
|
|
489
|
+
"page_size": 15
|
|
490
|
+
}
|
|
491
|
+
print(fyers.smart_orderbook_with_filter(data))
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
#################################################################################################################
|
|
495
|
+
|
|
496
|
+
"""
|
|
497
|
+
SMART EXIT TRIGGERS : This includes following APIs (create, get, update, activate)
|
|
498
|
+
"""
|
|
499
|
+
|
|
500
|
+
## Create Smart Exit Trigger
|
|
501
|
+
|
|
502
|
+
# Type 1: Only Alert (notification only, no auto-exit)
|
|
503
|
+
data = {
|
|
504
|
+
"name": "Alert Only Strategy",
|
|
505
|
+
"type": 1,
|
|
506
|
+
"profitRate": 5000,
|
|
507
|
+
"lossRate": -2000
|
|
508
|
+
}
|
|
509
|
+
print(fyers.create_smartexit_trigger(data))
|
|
510
|
+
|
|
511
|
+
# Type 2: Exit with Alert (notification + immediate exit)
|
|
512
|
+
data = {
|
|
513
|
+
"name": "Auto Exit Strategy",
|
|
514
|
+
"type": 2,
|
|
515
|
+
"profitRate": 5000,
|
|
516
|
+
"lossRate": -2000
|
|
517
|
+
}
|
|
518
|
+
print(fyers.create_smartexit_trigger(data))
|
|
519
|
+
|
|
520
|
+
# Type 3: Exit with Alert + Wait for Recovery (notification + delayed exit)
|
|
521
|
+
data = {
|
|
522
|
+
"name": "Recovery Exit Strategy",
|
|
523
|
+
"type": 3,
|
|
524
|
+
"profitRate": 10000,
|
|
525
|
+
"lossRate": -3000,
|
|
526
|
+
"waitTime": 5
|
|
527
|
+
}
|
|
528
|
+
print(fyers.create_smartexit_trigger(data))
|
|
529
|
+
|
|
530
|
+
## Get Smart Exit Triggers
|
|
531
|
+
# Get all smart exit triggers
|
|
532
|
+
print(fyers.get_smartexit_triggers())
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
## Update Smart Exit Trigger
|
|
536
|
+
data = {
|
|
537
|
+
"flowId": "123456789",
|
|
538
|
+
"triggerPrice": 610.00,
|
|
539
|
+
"stopLoss": 600.00,
|
|
540
|
+
"takeProfit": 630.00
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
print(fyers.update_smartexit_trigger(data))
|
|
544
|
+
|
|
545
|
+
## Activate Smart Exit Trigger
|
|
546
|
+
data = {"flowId": "123456789"}
|
|
547
|
+
print(fyers.activate_smartexit_trigger(data))
|
|
548
|
+
|
|
549
|
+
|
|
325
550
|
```
|
|
326
551
|
|
|
327
552
|
## Getting started with Data Socket
|
|
@@ -409,43 +634,61 @@ from fyers_apiv3.FyersWebsocket import order_ws
|
|
|
409
634
|
|
|
410
635
|
def onTrade(message):
|
|
411
636
|
"""
|
|
412
|
-
Callback function to handle incoming messages from the
|
|
637
|
+
Callback function to handle incoming trade messages from the FyersOrderSocket WebSocket.
|
|
413
638
|
|
|
414
639
|
Parameters:
|
|
415
640
|
message (dict): The received message from the WebSocket.
|
|
416
|
-
|
|
641
|
+
- message["trades"]: Contains trade data including id_fyers field if present
|
|
642
|
+
- message["s"]: Status of the message
|
|
643
|
+
|
|
644
|
+
Note: The message may contain an "id_fyers" field in the trades data, which is a unique identifier
|
|
645
|
+
for Fyers-specific trade tracking.
|
|
417
646
|
"""
|
|
418
647
|
print("Trade Response:", message)
|
|
419
648
|
|
|
649
|
+
|
|
420
650
|
def onOrder(message):
|
|
421
651
|
"""
|
|
422
|
-
Callback function to handle incoming messages from the
|
|
652
|
+
Callback function to handle incoming order messages from the FyersOrderSocket WebSocket.
|
|
423
653
|
|
|
424
654
|
Parameters:
|
|
425
655
|
message (dict): The received message from the WebSocket.
|
|
426
|
-
|
|
656
|
+
- message["orders"]: Contains order data including id_fyers field if present
|
|
657
|
+
- message["s"]: Status of the message
|
|
658
|
+
|
|
659
|
+
Note: The message may contain an "id_fyers" field in the orders data, which is a unique identifier
|
|
660
|
+
for Fyers-specific order tracking.
|
|
427
661
|
"""
|
|
428
662
|
print("Order Response:", message)
|
|
429
663
|
|
|
664
|
+
|
|
430
665
|
def onPosition(message):
|
|
431
666
|
"""
|
|
432
|
-
Callback function to handle incoming messages from the
|
|
667
|
+
Callback function to handle incoming position messages from the FyersOrderSocket WebSocket.
|
|
433
668
|
|
|
434
669
|
Parameters:
|
|
435
670
|
message (dict): The received message from the WebSocket.
|
|
436
|
-
|
|
671
|
+
- message["positions"]: Contains position data including id_fyers field if present
|
|
672
|
+
- message["s"]: Status of the message
|
|
673
|
+
|
|
437
674
|
"""
|
|
438
675
|
print("Position Response:", message)
|
|
439
676
|
|
|
677
|
+
|
|
440
678
|
def onGeneral(message):
|
|
441
679
|
"""
|
|
442
|
-
Callback function to handle incoming messages from the
|
|
680
|
+
Callback function to handle incoming general messages from the FyersOrderSocket WebSocket.
|
|
681
|
+
This includes eDIS updates, price alerts, and login events.
|
|
443
682
|
|
|
444
683
|
Parameters:
|
|
445
684
|
message (dict): The received message from the WebSocket.
|
|
685
|
+
- May contain price alerts with id_fyers field if present
|
|
686
|
+
- May contain eDIS updates
|
|
687
|
+
- May contain login events
|
|
446
688
|
|
|
447
689
|
"""
|
|
448
690
|
print("General Response:", message)
|
|
691
|
+
|
|
449
692
|
def onerror(message):
|
|
450
693
|
"""
|
|
451
694
|
Callback function to handle WebSocket errors.
|