vortex-api 2.1.6__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.6
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.6"
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
@@ -111,27 +122,31 @@ class Constants:
111
122
  def validate_inputs(func):
112
123
  @wrapt.decorator
113
124
  def wrapper(wrapped, instance, args, kwargs):
114
- # Get the function signature
115
125
  sig = inspect.signature(wrapped)
116
- # Validate the input arguments
117
- for param_name, param in sig.parameters.items():
118
- if param_name == 'self':
119
- continue
126
+ # Build ordered list of non-self params for positional index mapping.
127
+ # wrapt strips 'self' from args, so index 0 in args = first non-self param.
128
+ params = [(name, p) for name, p in sig.parameters.items() if name != 'self']
129
+
130
+ for idx, (param_name, param) in enumerate(params):
120
131
  param_type = param.annotation
121
132
  if param_type is inspect.Parameter.empty:
122
133
  continue
123
- if param_type is not inspect.Parameter.empty:
124
- if kwargs.get(param_name) != None:
125
- value = kwargs.get(param_name)
126
- else:
127
- value = args[list(sig.parameters.values()).index(param)]
128
- # value = args[list(sig.parameters.values()).index(param)] if param.kind == inspect.Parameter.POSITIONAL_ONLY else kwargs.get(param_name)
129
- if isinstance(param_type, Enum) and value not in param_type.__members__.values():
130
- raise ValueError(f'{param.name} must be one of {list(param_type.__members__.values())}')
131
- if not isinstance(value, param_type):
132
- raise TypeError(f'{param_name} must be of type {param_type.__name__}')
133
- sig.parameters.values()
134
- # Call the wrapped function
134
+
135
+ # Resolve value: check kwargs first, then positional args
136
+ if param_name in kwargs:
137
+ value = kwargs[param_name]
138
+ elif idx < len(args):
139
+ value = args[idx]
140
+ elif param.default is not inspect.Parameter.empty:
141
+ continue # has a default, skip validation
142
+ else:
143
+ raise TypeError(f"missing required argument: '{param_name}'")
144
+
145
+ if isinstance(param_type, Enum) and value not in param_type.__members__.values():
146
+ raise ValueError(f'{param_name} must be one of {list(param_type.__members__.values())}')
147
+ if not isinstance(value, param_type):
148
+ raise TypeError(f'{param_name} must be of type {param_type.__name__}')
149
+
135
150
  return wrapped(*args, **kwargs)
136
151
 
137
152
  return wrapper(func)
@@ -294,8 +309,8 @@ class VortexAPI:
294
309
  my_list = list(cr)
295
310
  return my_list
296
311
 
297
- def place_order(self,exchange: Constants.ExchangeTypes, token: int, transaction_type: Constants.TransactionSides, product: Constants.ProductTypes, variety: Constants.VarietyTypes,
298
- 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:
299
314
  """
300
315
  Place an order for a specific security
301
316
 
@@ -303,44 +318,62 @@ class VortexAPI:
303
318
  https://vortex.rupeezy.in/docs/latest/order/#placing-an-order
304
319
 
305
320
  Args:
306
- exchange (Constants.ExchangeTypes): Possible values: [NSE_EQ, NSE_FO, BSE_EQ, BSE_FO, NSE_CD or MCX_FO]
307
- 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.
308
325
  transaction_type (Constants.TransactionSides): Possible values: [BUY, SELL]
309
326
  product (Constants.ProductTypes): Possible values: [INTRADAY, DELIVERY, MTF]. MTF product can only be used in NSE_EQ exchange.
310
- 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.
311
328
  MKT means that the trade will happen at market price
312
- quantity (int): For exchange NSE_FO, if you want to trade in 2 lots and lot size is 50, you should pass 100.
313
- 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,
314
331
  if you want to trade 5 lots, you should pass just 5.
315
- price (float): Price should be an integer multiple of Tick Size. For example, IDEA's tick size is 0.05.
316
- 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.
317
334
  In case of market orders, you should send the Last Trade Price received from the Quote API or Websocket API
318
- 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
319
336
  lesser than price. for SELL side SL orders, trigger_price should be greater than price.
320
337
  disclosed_quantity (int): Can be any number lesser than or equal to quantity, including 0
321
- 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.
322
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.
323
343
  Returns:
324
344
  dict: JSON response containing the details of the placed order
325
345
 
326
346
  Raises:
327
347
  HTTPError: If any HTTP error occurs during the API call
348
+ ValueError: If neither ``ticker`` nor (``exchange`` and ``token``) is provided.
328
349
  """
329
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
+
330
365
  endpoint = "/trading/orders/regular"
331
- if validity == Constants.ValidityTypes.FULL_DAY:
332
- validity_days = 1
366
+ if validity == Constants.ValidityTypes.FULL_DAY:
367
+ validity_days = 1
333
368
  is_amo = False
334
- elif validity == Constants.ValidityTypes.IMMEDIATE_OR_CANCEL:
335
- validity_days = 0
369
+ elif validity == Constants.ValidityTypes.IMMEDIATE_OR_CANCEL:
370
+ validity_days = 0
336
371
  is_amo = False
337
- else:
338
- validity_days = 1
339
- is_amo = True
372
+ else:
373
+ validity_days = 1
374
+ is_amo = True
340
375
 
341
376
  data = {
342
- "exchange": exchange,
343
- "token": token,
344
377
  "transaction_type": transaction_type,
345
378
  "product": product,
346
379
  "variety": variety,
@@ -352,7 +385,13 @@ class VortexAPI:
352
385
  "validity_days": validity_days,
353
386
  "is_amo": is_amo
354
387
  }
355
-
388
+
389
+ if ticker is not None:
390
+ data["ticker"] = ticker
391
+ else:
392
+ data["exchange"] = exchange
393
+ data["token"] = token
394
+
356
395
  return self._make_api_request("POST", endpoint, data=data)
357
396
 
358
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:
@@ -501,43 +540,60 @@ class VortexAPI:
501
540
  endpoint = "/user/funds"
502
541
  return self._make_api_request("GET", endpoint)
503
542
 
504
- def get_order_margin(self, exchange: Constants.ExchangeTypes, token: int, transaction_type: Constants.TransactionSides, product: Constants.ProductTypes, variety: Constants.VarietyTypes,
505
- 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:
506
545
  """
507
546
  Get the margin required for placing an order for a specific security.
508
547
 
509
- Documentation:
548
+ Documentation:
510
549
  https://vortex.rupeezy.in/docs/latest/margin/#order-margin
511
550
 
512
551
  Args:
513
- exchange (Constants.ExchangeTypes): Possible values: [NSE_EQ, NSE_FO, BSE_EQ, BSE_FO, NSE_CD or MCX_FO]
514
- 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.
515
556
  transaction_type (Constants.TransactionSides): Possible values: [BUY, SELL]
516
557
  product (Constants.ProductTypes): Possible values: [INTRADAY, DELIVERY, MTF]. MTF product can only be used in NSE_EQ exchange.
517
- 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.
518
559
  MKT means that the trade will happen at market price
519
- quantity (int): For exchange NSE_FO, if you want to trade in 2 lots and lot size is 50, you should pass 100.
520
- 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,
521
562
  if you want to trade 5 lots, you should pass just 5.
522
- price (float): Price should be an integer multiple of Tick Size. For example, IDEA's tick size is 0.05.
523
- 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.
524
565
  In case of market orders, you should send the Last Trade Price received from the Quote API or Websocket API
525
- 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.
526
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
527
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.
528
572
 
529
573
  Returns:
530
574
  dict: JSON response containing the details of the margin required to place the order
531
575
 
532
576
  Raises:
533
577
  HTTPError: If any HTTP error occurs during the API call
578
+ ValueError: If neither ``ticker`` nor (``exchange`` and ``token``) is provided.
534
579
  """
535
-
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
+
536
594
  endpoint = "/margins/order"
537
-
595
+
538
596
  data = {
539
- "exchange": exchange,
540
- "token": token,
541
597
  "transaction_type": transaction_type,
542
598
  "product": product,
543
599
  "variety": variety,
@@ -547,6 +603,13 @@ class VortexAPI:
547
603
  "old_price": old_price,
548
604
  "mode": mode,
549
605
  }
606
+
607
+ if ticker is not None:
608
+ data["ticker"] = ticker
609
+ else:
610
+ data["exchange"] = exchange
611
+ data["token"] = token
612
+
550
613
  return self._make_api_request("POST", endpoint, data=data)
551
614
 
552
615
  def brokerage_plan(self)-> dict:
@@ -581,35 +644,48 @@ class VortexAPI:
581
644
  params = {"q": instruments,"mode": mode}
582
645
  return self._make_api_request("GET", endpoint, data=None,params=params)
583
646
 
584
- 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):
585
648
  """
586
- Gets historical candle data of a particular instrument.
649
+ Gets historical candle data of a particular instrument.
587
650
 
588
- Documentation:
651
+ Documentation:
589
652
  https://vortex.rupeezy.in/docs/latest/historical/#fetch-historical-candle-data
590
653
 
591
654
  Args:
592
- exchange (Constants.ExchangeTypes): Possible values: [NSE_EQ, NSE_FO, BSE_EQ, BSE_FO, NSE_CD or MCX_FO]
593
- token (int): Security token of the scrip. It can be found in the instruments master file:
594
- to (datetime): datetime up till when you want to receive candles
595
- 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
596
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"
597
-
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
+
598
666
  Returns:
599
667
  dict: JSON response containing the historical candles
600
668
  """
601
669
 
602
- if not isinstance(token, int):
603
- raise TypeError("token must be an integer")
604
- 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):
605
677
  raise TypeError("to must be a datetime")
606
- if not isinstance(start,datetime.datetime):
678
+ if not isinstance(start, datetime.datetime):
607
679
  raise TypeError("start must be a datetime")
608
680
 
609
-
610
681
  endpoint = "/data/history"
611
- params = {"exchange": exchange,"token": token , "to": int(to.timestamp()), "from": int(start.timestamp()), "resolution": resolution}
612
- 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)
613
689
 
614
690
  def login_url(self, callback_param: str) -> str:
615
691
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vortex_api
3
- Version: 2.1.6
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.6"
File without changes
File without changes
File without changes