vortex-api 2.1.7__tar.gz → 2.1.8b1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vortex_api
3
- Version: 2.1.7
3
+ Version: 2.1.8b1
4
4
  Summary: Vortex APIs to place orders in Rupeezy application
5
5
  Author-email: "Astha Credit & Securities Pvt Ltd." <tech@rupeezy.in>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "vortex_api"
7
- version = "2.1.7"
7
+ version = "2.1.8b1"
8
8
  description = "Vortex APIs to place orders in Rupeezy application"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -0,0 +1 @@
1
+ __version__ = "2.1.8b1"
@@ -2,11 +2,22 @@ import requests
2
2
  import csv
3
3
  import datetime
4
4
  import logging
5
+ import warnings
5
6
  from enum import Enum
6
7
  import inspect
7
8
  import wrapt
8
9
  import hashlib
9
10
  import os
11
+
12
+
13
+ def _warn_token_exchange_deprecated(method_name: str) -> None:
14
+ """Emit a FutureWarning when callers pass ``token``/``exchange`` instead of ``ticker``."""
15
+ warnings.warn(
16
+ f"Passing 'exchange' and 'token' to {method_name}() is deprecated and will be "
17
+ "removed in a future release. Use 'ticker' instead (e.g. ticker=\"NSE:RELIANCE\").",
18
+ FutureWarning,
19
+ stacklevel=3,
20
+ )
10
21
  class Constants:
11
22
  """
12
23
  Constants used in the API
@@ -298,8 +309,8 @@ class VortexAPI:
298
309
  my_list = list(cr)
299
310
  return my_list
300
311
 
301
- def place_order(self,exchange: Constants.ExchangeTypes, token: int, transaction_type: Constants.TransactionSides, product: Constants.ProductTypes, variety: Constants.VarietyTypes,
302
- quantity: int, price: float, trigger_price: float, disclosed_quantity: int, validity: Constants.ValidityTypes) -> dict:
312
+ def place_order(self, exchange: Constants.ExchangeTypes = None, token: int = None, transaction_type: Constants.TransactionSides = None, product: Constants.ProductTypes = None, variety: Constants.VarietyTypes = None,
313
+ quantity: int = None, price: float = None, trigger_price: float = None, disclosed_quantity: int = None, validity: Constants.ValidityTypes = None, ticker: str = None) -> dict:
303
314
  """
304
315
  Place an order for a specific security
305
316
 
@@ -307,44 +318,62 @@ class VortexAPI:
307
318
  https://vortex.rupeezy.in/docs/latest/order/#placing-an-order
308
319
 
309
320
  Args:
310
- exchange (Constants.ExchangeTypes): Possible values: [NSE_EQ, NSE_FO, BSE_EQ, BSE_FO, NSE_CD or MCX_FO]
311
- token (int): Security token of the scrip. It can be found in the scripmaster file
321
+ exchange (Constants.ExchangeTypes, optional): Possible values: [NSE_EQ, NSE_FO, BSE_EQ, BSE_FO, NSE_CD or MCX_FO].
322
+ Required together with ``token`` when ``ticker`` is not supplied.
323
+ token (int, optional): Security token of the scrip. It can be found in the scripmaster file.
324
+ Required together with ``exchange`` when ``ticker`` is not supplied.
312
325
  transaction_type (Constants.TransactionSides): Possible values: [BUY, SELL]
313
326
  product (Constants.ProductTypes): Possible values: [INTRADAY, DELIVERY, MTF]. MTF product can only be used in NSE_EQ exchange.
314
- variety (Constants.VarietyTypes): Possible values: [RL, RL-MKT, SL, SL-MKT]. RL means regular orders, SL means Stop Loss order.
327
+ variety (Constants.VarietyTypes): Possible values: [RL, RL-MKT, SL, SL-MKT]. RL means regular orders, SL means Stop Loss order.
315
328
  MKT means that the trade will happen at market price
316
- quantity (int): For exchange NSE_FO, if you want to trade in 2 lots and lot size is 50, you should pass 100.
317
- In all other exchanges, you should pass just the number of lots. For example, in MCX_FO,
329
+ quantity (int): For exchange NSE_FO, if you want to trade in 2 lots and lot size is 50, you should pass 100.
330
+ In all other exchanges, you should pass just the number of lots. For example, in MCX_FO,
318
331
  if you want to trade 5 lots, you should pass just 5.
319
- price (float): Price should be an integer multiple of Tick Size. For example, IDEA's tick size is 0.05.
320
- So the price entered can be 9.5 or 9.65. It cannot be 9.67.
332
+ price (float): Price should be an integer multiple of Tick Size. For example, IDEA's tick size is 0.05.
333
+ So the price entered can be 9.5 or 9.65. It cannot be 9.67.
321
334
  In case of market orders, you should send the Last Trade Price received from the Quote API or Websocket API
322
- trigger_price (float): To be used for Stop loss orders. For BUY side SL orders, trigger_price should be
335
+ trigger_price (float): To be used for Stop loss orders. For BUY side SL orders, trigger_price should be
323
336
  lesser than price. for SELL side SL orders, trigger_price should be greater than price.
324
337
  disclosed_quantity (int): Can be any number lesser than or equal to quantity, including 0
325
- validity (Constants.ValidityTypes): Can be DAY for orders which are valid throughout the day, or IOC.
338
+ validity (Constants.ValidityTypes): Can be DAY for orders which are valid throughout the day, or IOC.
326
339
  IOC order will be cancelled if it is not traded immediately
340
+ ticker (str, optional): Instrument ticker in the form ``<EXCHANGE>:<SYMBOL>`` (e.g. "NSE:RELIANCE").
341
+ Pass this as an alternative to ``exchange`` and ``token``.
342
+ Either ``ticker`` or (``exchange`` and ``token``) must be provided.
327
343
  Returns:
328
344
  dict: JSON response containing the details of the placed order
329
345
 
330
346
  Raises:
331
347
  HTTPError: If any HTTP error occurs during the API call
348
+ ValueError: If neither ``ticker`` nor (``exchange`` and ``token``) is provided.
332
349
  """
333
350
 
351
+ if ticker is None and (exchange is None or token is None):
352
+ raise ValueError("Either 'ticker' or both 'exchange' and 'token' must be provided")
353
+
354
+ if ticker is None:
355
+ _warn_token_exchange_deprecated("place_order")
356
+
357
+ for required_name, required_value in (
358
+ ("transaction_type", transaction_type), ("product", product), ("variety", variety),
359
+ ("quantity", quantity), ("price", price), ("trigger_price", trigger_price),
360
+ ("disclosed_quantity", disclosed_quantity), ("validity", validity),
361
+ ):
362
+ if required_value is None:
363
+ raise TypeError(f"missing required argument: '{required_name}'")
364
+
334
365
  endpoint = "/trading/orders/regular"
335
- if validity == Constants.ValidityTypes.FULL_DAY:
336
- validity_days = 1
366
+ if validity == Constants.ValidityTypes.FULL_DAY:
367
+ validity_days = 1
337
368
  is_amo = False
338
- elif validity == Constants.ValidityTypes.IMMEDIATE_OR_CANCEL:
339
- validity_days = 0
369
+ elif validity == Constants.ValidityTypes.IMMEDIATE_OR_CANCEL:
370
+ validity_days = 0
340
371
  is_amo = False
341
- else:
342
- validity_days = 1
343
- is_amo = True
372
+ else:
373
+ validity_days = 1
374
+ is_amo = True
344
375
 
345
376
  data = {
346
- "exchange": exchange,
347
- "token": token,
348
377
  "transaction_type": transaction_type,
349
378
  "product": product,
350
379
  "variety": variety,
@@ -356,7 +385,13 @@ class VortexAPI:
356
385
  "validity_days": validity_days,
357
386
  "is_amo": is_amo
358
387
  }
359
-
388
+
389
+ if ticker is not None:
390
+ data["ticker"] = ticker
391
+ else:
392
+ data["exchange"] = exchange
393
+ data["token"] = token
394
+
360
395
  return self._make_api_request("POST", endpoint, data=data)
361
396
 
362
397
  def modify_order(self, order_id: str, variety: Constants.VarietyTypes, quantity: int, traded_quantity: int, price: float, trigger_price: float, disclosed_quantity: int, validity: Constants.ValidityTypes) -> dict:
@@ -505,43 +540,60 @@ class VortexAPI:
505
540
  endpoint = "/user/funds"
506
541
  return self._make_api_request("GET", endpoint)
507
542
 
508
- def get_order_margin(self, exchange: Constants.ExchangeTypes, token: int, transaction_type: Constants.TransactionSides, product: Constants.ProductTypes, variety: Constants.VarietyTypes,
509
- quantity: int, price: float,mode: Constants.OrderMarginModes, old_quantity: int = 0 , old_price: float = 0 ) -> dict:
543
+ def get_order_margin(self, exchange: Constants.ExchangeTypes = None, token: int = None, transaction_type: Constants.TransactionSides = None, product: Constants.ProductTypes = None, variety: Constants.VarietyTypes = None,
544
+ quantity: int = None, price: float = None, mode: Constants.OrderMarginModes = None, old_quantity: int = 0, old_price: float = 0, ticker: str = None) -> dict:
510
545
  """
511
546
  Get the margin required for placing an order for a specific security.
512
547
 
513
- Documentation:
548
+ Documentation:
514
549
  https://vortex.rupeezy.in/docs/latest/margin/#order-margin
515
550
 
516
551
  Args:
517
- exchange (Constants.ExchangeTypes): Possible values: [NSE_EQ, NSE_FO, BSE_EQ, BSE_FO, NSE_CD or MCX_FO]
518
- token (int): Security token of the scrip. It can be found in the scripmaster file
552
+ exchange (Constants.ExchangeTypes, optional): Possible values: [NSE_EQ, NSE_FO, BSE_EQ, BSE_FO, NSE_CD or MCX_FO].
553
+ Required together with ``token`` when ``ticker`` is not supplied.
554
+ token (int, optional): Security token of the scrip. It can be found in the scripmaster file.
555
+ Required together with ``exchange`` when ``ticker`` is not supplied.
519
556
  transaction_type (Constants.TransactionSides): Possible values: [BUY, SELL]
520
557
  product (Constants.ProductTypes): Possible values: [INTRADAY, DELIVERY, MTF]. MTF product can only be used in NSE_EQ exchange.
521
- variety (Constants.VarietyTypes): Possible values: [RL, RL-MKT, SL, SL-MKT]. RL means regular orders, SL means Stop Loss order.
558
+ variety (Constants.VarietyTypes): Possible values: [RL, RL-MKT, SL, SL-MKT]. RL means regular orders, SL means Stop Loss order.
522
559
  MKT means that the trade will happen at market price
523
- quantity (int): For exchange NSE_FO, if you want to trade in 2 lots and lot size is 50, you should pass 100.
524
- In all other exchanges, you should pass just the number of lots. For example, in MCX_FO,
560
+ quantity (int): For exchange NSE_FO, if you want to trade in 2 lots and lot size is 50, you should pass 100.
561
+ In all other exchanges, you should pass just the number of lots. For example, in MCX_FO,
525
562
  if you want to trade 5 lots, you should pass just 5.
526
- price (float): Price should be an integer multiple of Tick Size. For example, IDEA's tick size is 0.05.
527
- So the price entered can be 9.5 or 9.65. It cannot be 9.67.
563
+ price (float): Price should be an integer multiple of Tick Size. For example, IDEA's tick size is 0.05.
564
+ So the price entered can be 9.5 or 9.65. It cannot be 9.67.
528
565
  In case of market orders, you should send the Last Trade Price received from the Quote API or Websocket API
529
- mode (Constants.OrderMarginModes): Possible values: [NEW, MODIFY] , Whether you are trying to modify an existing order or placing a new order.
566
+ mode (Constants.OrderMarginModes): Possible values: [NEW, MODIFY] , Whether you are trying to modify an existing order or placing a new order.
530
567
  old_quantity (int): For NSE_FO segments, old_quantity is lots * lot_size. For all others, enter just the number of lots. Required if mode is MODIFY
531
568
  old_price (float): Old Price in INR. Required if mode is MODIFY
569
+ ticker (str, optional): Instrument ticker in the form ``<EXCHANGE>:<SYMBOL>`` (e.g. "NSE:RELIANCE").
570
+ Pass this as an alternative to ``exchange`` and ``token``.
571
+ Either ``ticker`` or (``exchange`` and ``token``) must be provided.
532
572
 
533
573
  Returns:
534
574
  dict: JSON response containing the details of the margin required to place the order
535
575
 
536
576
  Raises:
537
577
  HTTPError: If any HTTP error occurs during the API call
578
+ ValueError: If neither ``ticker`` nor (``exchange`` and ``token``) is provided.
538
579
  """
539
-
580
+
581
+ if ticker is None and (exchange is None or token is None):
582
+ raise ValueError("Either 'ticker' or both 'exchange' and 'token' must be provided")
583
+
584
+ if ticker is None:
585
+ _warn_token_exchange_deprecated("get_order_margin")
586
+
587
+ for required_name, required_value in (
588
+ ("transaction_type", transaction_type), ("product", product), ("variety", variety),
589
+ ("quantity", quantity), ("price", price), ("mode", mode),
590
+ ):
591
+ if required_value is None:
592
+ raise TypeError(f"missing required argument: '{required_name}'")
593
+
540
594
  endpoint = "/margins/order"
541
-
595
+
542
596
  data = {
543
- "exchange": exchange,
544
- "token": token,
545
597
  "transaction_type": transaction_type,
546
598
  "product": product,
547
599
  "variety": variety,
@@ -551,6 +603,13 @@ class VortexAPI:
551
603
  "old_price": old_price,
552
604
  "mode": mode,
553
605
  }
606
+
607
+ if ticker is not None:
608
+ data["ticker"] = ticker
609
+ else:
610
+ data["exchange"] = exchange
611
+ data["token"] = token
612
+
554
613
  return self._make_api_request("POST", endpoint, data=data)
555
614
 
556
615
  def brokerage_plan(self)-> dict:
@@ -585,35 +644,48 @@ class VortexAPI:
585
644
  params = {"q": instruments,"mode": mode}
586
645
  return self._make_api_request("GET", endpoint, data=None,params=params)
587
646
 
588
- def historical_candles(self, exchange: Constants.ExchangeTypes, token: int, to: datetime.datetime , start: datetime.datetime, resolution: Constants.Resolutions):
647
+ def historical_candles(self, exchange: Constants.ExchangeTypes = None, token: int = None, to: datetime.datetime = None, start: datetime.datetime = None, resolution: Constants.Resolutions = None, ticker: str = None):
589
648
  """
590
- Gets historical candle data of a particular instrument.
649
+ Gets historical candle data of a particular instrument.
591
650
 
592
- Documentation:
651
+ Documentation:
593
652
  https://vortex.rupeezy.in/docs/latest/historical/#fetch-historical-candle-data
594
653
 
595
654
  Args:
596
- exchange (Constants.ExchangeTypes): Possible values: [NSE_EQ, NSE_FO, BSE_EQ, BSE_FO, NSE_CD or MCX_FO]
597
- token (int): Security token of the scrip. It can be found in the instruments master file:
598
- to (datetime): datetime up till when you want to receive candles
599
- start (datetime): datetime from when you want to receive candles
655
+ exchange (Constants.ExchangeTypes, optional): Possible values: [NSE_EQ, NSE_FO, BSE_EQ, BSE_FO, NSE_CD or MCX_FO].
656
+ Required together with ``token`` when ``ticker`` is not supplied.
657
+ token (int, optional): Security token of the scrip. It can be found in the instruments master file.
658
+ Required together with ``exchange`` when ``ticker`` is not supplied.
659
+ to (datetime): datetime up till when you want to receive candles
660
+ start (datetime): datetime from when you want to receive candles
600
661
  resolution (Constants.Resolutions): resoulution of the candle. can be "1", "2", "3", "4", "5", "10", "15", "30", "45", "60", "120", "180", "240", "1D", "1W", "1M"
601
-
662
+ ticker (str, optional): Instrument ticker in the form ``<EXCHANGE>:<SYMBOL>`` (e.g. "NSE:RELIANCE").
663
+ Pass this as an alternative to ``exchange`` and ``token``.
664
+ Either ``ticker`` or (``exchange`` and ``token``) must be provided.
665
+
602
666
  Returns:
603
667
  dict: JSON response containing the historical candles
604
668
  """
605
669
 
606
- if not isinstance(token, int):
607
- raise TypeError("token must be an integer")
608
- if not isinstance(to,datetime.datetime):
670
+ if ticker is None and (exchange is None or token is None):
671
+ raise ValueError("Either 'ticker' or both 'exchange' and 'token' must be provided")
672
+ if ticker is None:
673
+ _warn_token_exchange_deprecated("historical_candles")
674
+ if not isinstance(token, int):
675
+ raise TypeError("token must be an integer")
676
+ if not isinstance(to, datetime.datetime):
609
677
  raise TypeError("to must be a datetime")
610
- if not isinstance(start,datetime.datetime):
678
+ if not isinstance(start, datetime.datetime):
611
679
  raise TypeError("start must be a datetime")
612
680
 
613
-
614
681
  endpoint = "/data/history"
615
- params = {"exchange": exchange,"token": token , "to": int(to.timestamp()), "from": int(start.timestamp()), "resolution": resolution}
616
- return self._make_api_request("GET", endpoint, data=None,params=params)
682
+ params = {"to": int(to.timestamp()), "from": int(start.timestamp()), "resolution": resolution}
683
+ if ticker is not None:
684
+ params["ticker"] = ticker
685
+ else:
686
+ params["exchange"] = exchange
687
+ params["token"] = token
688
+ return self._make_api_request("GET", endpoint, data=None, params=params)
617
689
 
618
690
  def login_url(self, callback_param: str) -> str:
619
691
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vortex_api
3
- Version: 2.1.7
3
+ Version: 2.1.8b1
4
4
  Summary: Vortex APIs to place orders in Rupeezy application
5
5
  Author-email: "Astha Credit & Securities Pvt Ltd." <tech@rupeezy.in>
6
6
  License: MIT
@@ -1 +0,0 @@
1
- __version__ = "2.1.7"
File without changes
File without changes
File without changes