quantplay 2.0.145__tar.gz → 2.0.148__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.
Files changed (70) hide show
  1. {quantplay-2.0.145 → quantplay-2.0.148}/PKG-INFO +1 -1
  2. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/icici_direct.py +23 -19
  3. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/kotak.py +74 -1
  4. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/noren.py +1 -1
  5. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay.egg-info/PKG-INFO +1 -1
  6. {quantplay-2.0.145 → quantplay-2.0.148}/setup.py +1 -1
  7. {quantplay-2.0.145 → quantplay-2.0.148}/README.md +0 -0
  8. {quantplay-2.0.145 → quantplay-2.0.148}/pyproject.toml +0 -0
  9. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/__init__.py +0 -0
  10. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/__init__.py +0 -0
  11. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/aliceblue.py +0 -0
  12. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/angelone.py +0 -0
  13. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/auto_login/__init__.py +0 -0
  14. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/auto_login/aliceblue.py +0 -0
  15. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/breeze/__init__.py +0 -0
  16. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/breeze/breeze_utils.py +0 -0
  17. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/broker_factory.py +0 -0
  18. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/dhan.py +0 -0
  19. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/finvasia_utils/__init__.py +0 -0
  20. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/finvasia_utils/fa_noren.py +0 -0
  21. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/five_paisa.py +0 -0
  22. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/flattrade.py +0 -0
  23. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/ft_utils/__init__.py +0 -0
  24. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/ft_utils/flattrade_utils.py +0 -0
  25. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/ft_utils/ft_noren.py +0 -0
  26. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/generics/__init__.py +0 -0
  27. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/generics/broker.py +0 -0
  28. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/iifl_xts.py +0 -0
  29. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/jainam_xts.py +0 -0
  30. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/kite_utils.py +0 -0
  31. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/motilal.py +0 -0
  32. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/shoonya.py +0 -0
  33. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/uplink/__init__.py +0 -0
  34. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/uplink/uplink_utils.py +0 -0
  35. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/upstox.py +0 -0
  36. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/xts.py +0 -0
  37. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/xts_utils/Connect.py +0 -0
  38. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/xts_utils/Exception.py +0 -0
  39. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/xts_utils/InteractiveSocketClient.py +0 -0
  40. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/xts_utils/__init__.py +0 -0
  41. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/broker/zerodha.py +0 -0
  42. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/exception/__init__.py +0 -0
  43. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/exception/exceptions.py +0 -0
  44. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/model/__init__.py +0 -0
  45. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/model/broker.py +0 -0
  46. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/model/broker_response.py +0 -0
  47. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/model/generics.py +0 -0
  48. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/model/instrument_data.py +0 -0
  49. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/model/order_event.py +0 -0
  50. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/py.typed +0 -0
  51. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/utils/__init__.py +0 -0
  52. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/utils/caching.py +0 -0
  53. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/utils/constant.py +0 -0
  54. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/utils/exchange.py +0 -0
  55. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/utils/number_utils.py +0 -0
  56. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/utils/pickle_utils.py +0 -0
  57. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/utils/selenium_utils.py +0 -0
  58. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/wrapper/__init__.py +0 -0
  59. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/wrapper/aws/__init__.py +0 -0
  60. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay/wrapper/aws/s3.py +0 -0
  61. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay.egg-info/SOURCES.txt +0 -0
  62. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay.egg-info/dependency_links.txt +0 -0
  63. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay.egg-info/requires.txt +0 -0
  64. {quantplay-2.0.145 → quantplay-2.0.148}/quantplay.egg-info/top_level.txt +0 -0
  65. {quantplay-2.0.145 → quantplay-2.0.148}/setup.cfg +0 -0
  66. {quantplay-2.0.145 → quantplay-2.0.148}/tests/__init__.py +0 -0
  67. {quantplay-2.0.145 → quantplay-2.0.148}/tests/conftest.py +0 -0
  68. {quantplay-2.0.145 → quantplay-2.0.148}/tests/wrapper/__init__.py +0 -0
  69. {quantplay-2.0.145 → quantplay-2.0.148}/tests/wrapper/aws/__init__.py +0 -0
  70. {quantplay-2.0.145 → quantplay-2.0.148}/tests/wrapper/aws/s3_test.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: quantplay
3
- Version: 2.0.145
3
+ Version: 2.0.148
4
4
  Summary: This python package will be stored in AWS CodeArtifact
5
5
  Home-page:
6
6
  Author:
@@ -233,19 +233,13 @@ class ICICI(Broker):
233
233
  return orders_df
234
234
 
235
235
  def positions(self, drop_cnc: bool = True) -> pl.DataFrame:
236
- to_date = datetime.now().isoformat()[:19] + ".000Z"
237
- from_date = (datetime.now() - timedelta(hours=10)).isoformat()[:19] + ".000Z"
238
- positions: Dict[str, Any] = self.wrapper.get_portfolio_holdings( # type:ignore
239
- exchange_code="NFO",
240
- from_date=from_date,
241
- to_date=to_date,
242
- stock_code="",
243
- portfolio_type="",
244
- )
236
+ positions: Dict[str, Any] = self.wrapper.get_portfolio_positions() # type:ignore
245
237
  if "Success" in positions and positions["Success"] is None:
246
238
  return pl.DataFrame(schema=self.positions_schema)
247
239
  positions_df = pl.DataFrame(positions["Success"])
248
-
240
+ if "realized_profit" not in positions_df:
241
+ positions_df = positions_df.with_columns(pl.lit(0.0).alias("realized_profit"))
242
+ positions_df = positions_df.filter(pl.col("exchange_code").is_in(["NFO", "BFO"]))
249
243
  positions_df = positions_df.rename(
250
244
  {
251
245
  "exchange_code": "exchange",
@@ -254,6 +248,9 @@ class ICICI(Broker):
254
248
  "product_type": "product",
255
249
  }
256
250
  )
251
+ positions_df = positions_df.with_columns(
252
+ pl.col("quantity").cast(pl.Int32).alias("quantity")
253
+ )
257
254
  positions_df = positions_df.with_columns(
258
255
  pl.col("strike").cast(pl.Float32).alias("strike"),
259
256
  pl.col("expiry").str.strptime(pl.Date, format="%d-%b-%Y").alias("expiry"),
@@ -262,11 +259,11 @@ class ICICI(Broker):
262
259
  .when(pl.col("right") == "Put")
263
260
  .then(pl.lit("PE"))
264
261
  .alias("instrument_type"),
265
- (
266
- pl.col("unrealized_profit").cast(pl.Float32)
267
- + pl.col("realized_profit").cast(pl.Float32)
268
- ).alias("pnl"),
269
- pl.col("quantity").cast(pl.Int32).alias("quantity"),
262
+ pl.when(pl.col("action") == "Sell")
263
+ .then(abs(pl.col("quantity").cast(pl.Float32)) * -1)
264
+ .otherwise(abs(pl.col("quantity").cast(pl.Float32)))
265
+ .alias("quantity"),
266
+ pl.lit(0).alias("pnl"),
270
267
  pl.col("average_price").cast(pl.Float32).alias("average_price"),
271
268
  )
272
269
 
@@ -343,9 +340,14 @@ class ICICI(Broker):
343
340
  if tag is None:
344
341
  tag = ""
345
342
  icici_tradingsymbol = self.get_symbol(tradingsymbol)
346
- symbol_data: Dict[str, Any] = self.symbol_data[ # type:ignore
347
- f"{exchange}:{icici_tradingsymbol}"
348
- ]
343
+ try:
344
+ symbol_data: Dict[str, Any] = self.symbol_data[ # type:ignore
345
+ f"{exchange}:{icici_tradingsymbol}"
346
+ ]
347
+ except KeyError:
348
+ raise QuantplayOrderPlacementException(
349
+ f"Failed to find tradingsymbol {tradingsymbol}"
350
+ )
349
351
  icici_product = "cash"
350
352
  if exchange in ["NFO", "BFO"]:
351
353
  icici_product = "futures"
@@ -367,7 +369,7 @@ class ICICI(Broker):
367
369
  else:
368
370
  response: Dict[str, Any] = self.wrapper.place_order( # type:ignore
369
371
  stock_code=symbol_data["symbol_code"],
370
- exchange_code="NFO",
372
+ exchange_code=exchange,
371
373
  product=icici_product,
372
374
  action=transaction_type.lower(),
373
375
  order_type=order_type.lower(),
@@ -382,6 +384,8 @@ class ICICI(Broker):
382
384
  )
383
385
  if "Success" in response and "order_id" in response["Success"]:
384
386
  return response["Success"]["order_id"]
387
+ elif "Error" in response:
388
+ raise QuantplayOrderPlacementException(response["Error"])
385
389
  else:
386
390
  raise QuantplayOrderPlacementException(
387
391
  f"ICICI: order placement failed {response}"
@@ -26,6 +26,7 @@ SESSION_PROD_BASE_URL = "https://napi.kotaksecurities.com/"
26
26
 
27
27
 
28
28
  class Kotak(Broker):
29
+
29
30
  def __init__(
30
31
  self,
31
32
  order_updates: Queue[OrderUpdateEvent] | None = None,
@@ -154,8 +155,77 @@ class Kotak(Broker):
154
155
 
155
156
  if orders_resp["stat"] == "Not_Ok" and orders_resp["errMsg"] == "No Data":
156
157
  return pl.DataFrame(schema=self.orders_schema)
158
+ orders_df = pl.DataFrame(orders_resp["data"])
159
+ if "rejRsn" not in orders_df.columns:
160
+ orders_df = orders_df.with_columns(pl.lit("").alias("rejRsn"))
161
+ orders_df = orders_df.rename(
162
+ {
163
+ "actId": "user_id",
164
+ "nOrdNo": "order_id",
165
+ "exSeg": "exchange",
166
+ "prod": "product",
167
+ "trdSym": "tradingsymbol",
168
+ "ordSt": "status",
169
+ "prcTp": "order_type",
170
+ "trnsTp": "transaction_type",
171
+ "prc": "price",
172
+ "avgPrc": "average_price",
173
+ "trgPrc": "trigger_price",
174
+ "ordDtTm": "order_timestamp",
175
+ "tok": "token",
176
+ "qty": "quantity",
177
+ "fldQty": "filled_quantity",
178
+ "rejRsn": "status_message",
179
+ }
180
+ )
181
+
182
+ orders_df = orders_df.with_columns(
183
+ pl.lit("regular").alias("variety"),
184
+ pl.lit("").alias("tag"),
185
+ pl.lit(None).alias("ltp"),
186
+ pl.col("status_message").alias("status_message_raw"),
187
+ pl.col("order_timestamp")
188
+ .str.strptime(pl.Datetime(time_unit="ms"), format="%d-%b-%Y %H:%M:%S")
189
+ .alias("order_timestamp"),
190
+ )
191
+ orders_df = orders_df.with_columns(
192
+ pl.col("order_timestamp").alias("update_timestamp"),
193
+ (pl.col("quantity") - pl.col("filled_quantity")).alias("pending_quantity"),
194
+ )
195
+ orders_df = orders_df[list(self.orders_schema.keys())].cast(self.orders_schema)
196
+
197
+ orders_df = orders_df.with_columns(
198
+ pl.when(pl.col("exchange") == "nse_cm")
199
+ .then(pl.lit("NSE"))
200
+ .when(pl.col("exchange") == "bse_cm")
201
+ .then(pl.lit("BSE"))
202
+ .when(pl.col("exchange") == "nse_fo")
203
+ .then(pl.lit("NFO"))
204
+ .when(pl.col("exchange") == "bse_fo")
205
+ .then(pl.lit("BFO"))
206
+ .when(pl.col("exchange") == "cde_fo")
207
+ .then(pl.lit("CDS"))
208
+ .when(pl.col("exchange") == "bcs-fo")
209
+ .then(pl.lit("BCD"))
210
+ .when(pl.col("exchange") == "mcx")
211
+ .then(pl.lit("MCX"))
212
+ .otherwise(pl.col("exchange"))
213
+ .alias("exchange"),
214
+ pl.when(pl.col("order_type") == "L")
215
+ .then(pl.lit("LIMIT"))
216
+ .when(pl.col("order_type") == "MKT")
217
+ .then(pl.lit("MARKET"))
218
+ .otherwise(pl.col("order_type"))
219
+ .alias("order_type"),
220
+ pl.when(pl.col("transaction_type") == "B")
221
+ .then(pl.lit("BUY"))
222
+ .when(pl.col("transaction_type") == "S")
223
+ .then(pl.lit("SELL"))
224
+ .otherwise(pl.col("transaction_type"))
225
+ .alias("transaction_type"),
226
+ )
157
227
 
158
- return pl.DataFrame(schema=self.orders_schema)
228
+ return orders_df
159
229
 
160
230
  def positions(self, drop_cnc: bool = True) -> pl.DataFrame:
161
231
  positions_resp = self.request("order_book")
@@ -335,6 +405,9 @@ class Kotak(Broker):
335
405
  }
336
406
 
337
407
  query_params = {"sId": self.configuration["serverId"]}
408
+ if item == "place_order":
409
+ query_params["sId"] = "server4"
410
+ request_headers["neo-fin-key"] = "neotradeapi"
338
411
 
339
412
  request_body = None
340
413
  request_params = None
@@ -270,7 +270,7 @@ class Noren(Broker):
270
270
  if quote is None:
271
271
  raise BrokerException("Invaid LTP Response from Broker")
272
272
 
273
- return float(quote["lp"])
273
+ return float(quote.get("lp", 0))
274
274
 
275
275
  def live_data(
276
276
  self, exchange: ExchangeType, tradingsymbol: str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: quantplay
3
- Version: 2.0.145
3
+ Version: 2.0.148
4
4
  Summary: This python package will be stored in AWS CodeArtifact
5
5
  Home-page:
6
6
  Author:
@@ -21,7 +21,7 @@ requirements = [
21
21
  setup(
22
22
  name="quantplay",
23
23
  long_description=Path("README.md").read_text(),
24
- version="2.0.145",
24
+ version="2.0.148",
25
25
  setup_requires=["pytest-runner"],
26
26
  install_requires=requirements,
27
27
  tests_require=[],
File without changes
File without changes
File without changes