quantplay 2.0.35__tar.gz → 2.0.37__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.
- {quantplay-2.0.35 → quantplay-2.0.37}/PKG-INFO +1 -1
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/five_paisa.py +1 -2
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/xts.py +25 -18
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/xts_utils/Connect.py +118 -72
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/xts_utils/InteractiveSocketClient.py +27 -27
- quantplay-2.0.37/quantplay/model/xts.py +24 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay.egg-info/PKG-INFO +1 -1
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay.egg-info/SOURCES.txt +1 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/setup.py +1 -1
- {quantplay-2.0.35 → quantplay-2.0.37}/README.md +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/pyproject.toml +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/aliceblue.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/angelone.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/auto_login/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/auto_login/aliceblue.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/finvasia_utils/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/finvasia_utils/fa_noren.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/flattrade.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/ft_utils/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/ft_utils/flattrade_utils.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/ft_utils/ft_noren.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/generics/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/generics/broker.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/iifl_xts.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/kite_utils.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/motilal.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/noren.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/shoonya.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/uplink/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/uplink/uplink_utils.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/upstox.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/xts_utils/Exception.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/xts_utils/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/broker/zerodha.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/exception/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/exception/exceptions.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/model/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/model/broker.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/model/generics.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/model/instrument_data.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/model/order_event.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/py.typed +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/utils/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/utils/constant.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/utils/exchange.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/utils/number_utils.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/utils/pickle_utils.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/utils/selenium_utils.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/wrapper/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/wrapper/aws/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay/wrapper/aws/s3.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay.egg-info/dependency_links.txt +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay.egg-info/requires.txt +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/quantplay.egg-info/top_level.txt +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/setup.cfg +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/tests/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/tests/conftest.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/tests/wrapper/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/tests/wrapper/aws/__init__.py +0 -0
- {quantplay-2.0.35 → quantplay-2.0.37}/tests/wrapper/aws/s3_test.py +0 -0
|
@@ -147,9 +147,8 @@ class FivePaisa(Broker):
|
|
|
147
147
|
return self.client.fetch_market_feed_scrip(req_list_)["Data"][0]["LastRate"] # type: ignore
|
|
148
148
|
|
|
149
149
|
def add_exchange(self, data: pl.DataFrame):
|
|
150
|
-
data["exchange"] = None
|
|
151
|
-
|
|
152
150
|
return data.with_columns(
|
|
151
|
+
pl.lit(None).alias("exchange"),
|
|
153
152
|
pl.when((pl.col("Exch").eq("N")) & (pl.col("ExchType").eq("D")))
|
|
154
153
|
.then(pl.lit("NFO"))
|
|
155
154
|
.alias("exchange"),
|
|
@@ -4,7 +4,7 @@ import pickle
|
|
|
4
4
|
import traceback
|
|
5
5
|
from datetime import datetime
|
|
6
6
|
from queue import Queue
|
|
7
|
-
from typing import Dict
|
|
7
|
+
from typing import Any, Dict, List
|
|
8
8
|
|
|
9
9
|
import pandas as pd
|
|
10
10
|
import polars as pl
|
|
@@ -27,6 +27,7 @@ from quantplay.model.broker import (
|
|
|
27
27
|
)
|
|
28
28
|
from quantplay.model.generics import OrderTypeType, ProductType, TransactionType
|
|
29
29
|
from quantplay.model.order_event import OrderUpdateEvent
|
|
30
|
+
from quantplay.model.xts import XTSTypes
|
|
30
31
|
from quantplay.utils.constant import Constants, OrderType
|
|
31
32
|
from quantplay.utils.pickle_utils import InstrumentData, PickleUtils
|
|
32
33
|
|
|
@@ -151,7 +152,7 @@ class XTS(Broker):
|
|
|
151
152
|
except Exception:
|
|
152
153
|
raise InvalidArgumentException("Invalid api key/secret")
|
|
153
154
|
|
|
154
|
-
def handle_exception(self, response):
|
|
155
|
+
def handle_exception(self, response: Dict[str, Any]):
|
|
155
156
|
if "data" in response and "description" in response["data"]:
|
|
156
157
|
data = response["data"]
|
|
157
158
|
if "max limit" in data["description"].lower():
|
|
@@ -164,7 +165,7 @@ class XTS(Broker):
|
|
|
164
165
|
):
|
|
165
166
|
raise TokenException(response["description"])
|
|
166
167
|
if "type" in response and response["type"] == "error":
|
|
167
|
-
raise Exception(f"[XTS_Error]: {response[
|
|
168
|
+
raise Exception(f"[XTS_Error]: {response['description']}")
|
|
168
169
|
|
|
169
170
|
@retry(
|
|
170
171
|
wait_exponential_multiplier=3000,
|
|
@@ -463,15 +464,15 @@ class XTS(Broker):
|
|
|
463
464
|
|
|
464
465
|
return positions_df
|
|
465
466
|
|
|
466
|
-
def get_quantplay_symbol(self, symbol):
|
|
467
|
+
def get_quantplay_symbol(self, symbol: str):
|
|
467
468
|
if symbol in self.broker_symbol_map:
|
|
468
469
|
return self.broker_symbol_map[symbol]
|
|
469
470
|
return symbol
|
|
470
471
|
|
|
471
|
-
def get_ltps(self, symbols):
|
|
472
|
-
instruments = [
|
|
472
|
+
def get_ltps(self, symbols: List[str]):
|
|
473
|
+
instruments: List[XTSTypes.InstrumentType] = [
|
|
473
474
|
{
|
|
474
|
-
"exchangeSegment":
|
|
475
|
+
"exchangeSegment": self.get_exchange_code(x.split(":")[0]),
|
|
475
476
|
"exchangeInstrumentID": int(x.split(":")[1]),
|
|
476
477
|
}
|
|
477
478
|
for x in symbols
|
|
@@ -493,8 +494,8 @@ class XTS(Broker):
|
|
|
493
494
|
ltp = {x["ExchangeInstrumentID"]: float(x["LastTradedPrice"]) for x in ltp}
|
|
494
495
|
return ltp
|
|
495
496
|
|
|
496
|
-
def get_exchange_code(self, exchange):
|
|
497
|
-
exchange_code_map = {
|
|
497
|
+
def get_exchange_code(self, exchange) -> XTSTypes.ExchangeSegmentType:
|
|
498
|
+
exchange_code_map: Dict[str, XTSTypes.ExchangeSegmentType] = {
|
|
498
499
|
"NSE": 1,
|
|
499
500
|
"NFO": 2,
|
|
500
501
|
"BFO": 12,
|
|
@@ -513,8 +514,8 @@ class XTS(Broker):
|
|
|
513
514
|
|
|
514
515
|
return exchange_code_map[exchange]
|
|
515
516
|
|
|
516
|
-
def get_exchange_name(self, exchange):
|
|
517
|
-
exchange_code_map = {
|
|
517
|
+
def get_exchange_name(self, exchange) -> XTSTypes.ExchangeType:
|
|
518
|
+
exchange_code_map: Dict[str, XTSTypes.ExchangeType] = {
|
|
518
519
|
"NSE": "NSECM",
|
|
519
520
|
"NFO": "NSEFO",
|
|
520
521
|
"BFO": "BSEFO",
|
|
@@ -530,10 +531,11 @@ class XTS(Broker):
|
|
|
530
531
|
|
|
531
532
|
return exchange_code_map[exchange]
|
|
532
533
|
|
|
533
|
-
def ltp(self, exchange
|
|
534
|
+
def ltp(self, exchange, tradingsymbol: str) -> float:
|
|
534
535
|
exchange_code = self.get_exchange_code(exchange)
|
|
535
536
|
exchange_token = self.symbol_data[f"{exchange}:{tradingsymbol}"].get(
|
|
536
|
-
"exchange_token"
|
|
537
|
+
"exchange_token",
|
|
538
|
+
"", # TODO
|
|
537
539
|
)
|
|
538
540
|
|
|
539
541
|
api_response = self.md_wrapper.get_quote(
|
|
@@ -580,11 +582,14 @@ class XTS(Broker):
|
|
|
580
582
|
xts_order_type = self.get_order_type(order_type)
|
|
581
583
|
|
|
582
584
|
exchange_token = self.symbol_data[f"{exchange}:{tradingsymbol}"].get(
|
|
583
|
-
"exchange_token"
|
|
585
|
+
"exchange_token", ""
|
|
584
586
|
)
|
|
585
587
|
if trigger_price is None:
|
|
586
588
|
trigger_price = 0
|
|
587
589
|
|
|
590
|
+
if tag is None:
|
|
591
|
+
tag = ""
|
|
592
|
+
|
|
588
593
|
api_response = self.wrapper.place_order(
|
|
589
594
|
exchangeSegment=exchange_name,
|
|
590
595
|
exchangeInstrumentID=exchange_token,
|
|
@@ -608,7 +613,7 @@ class XTS(Broker):
|
|
|
608
613
|
|
|
609
614
|
return api_response["result"]["AppOrderID"]
|
|
610
615
|
|
|
611
|
-
def cancel_order(self, order_id, variety=None):
|
|
616
|
+
def cancel_order(self, order_id, variety: str | None = None):
|
|
612
617
|
orders = self.orders()
|
|
613
618
|
|
|
614
619
|
order_data = orders.filter(pl.col("order_id").eq(str(order_id)))
|
|
@@ -631,7 +636,7 @@ class XTS(Broker):
|
|
|
631
636
|
|
|
632
637
|
return api_response["result"]["AppOrderID"]
|
|
633
638
|
|
|
634
|
-
def get_order_type(self, order_type: OrderTypeType)
|
|
639
|
+
def get_order_type(self, order_type: OrderTypeType):
|
|
635
640
|
if order_type == OrderType.market:
|
|
636
641
|
return "Market"
|
|
637
642
|
elif order_type == OrderType.sl:
|
|
@@ -668,7 +673,7 @@ class XTS(Broker):
|
|
|
668
673
|
disclosed_quantity = 0
|
|
669
674
|
|
|
670
675
|
api_response = self.wrapper.modify_order(
|
|
671
|
-
appOrderID=order_id,
|
|
676
|
+
appOrderID=int(order_id),
|
|
672
677
|
modifiedTimeInForce=time_in_force,
|
|
673
678
|
modifiedDisclosedQuantity=disclosed_quantity,
|
|
674
679
|
modifiedLimitPrice=price,
|
|
@@ -687,7 +692,9 @@ class XTS(Broker):
|
|
|
687
692
|
|
|
688
693
|
return api_response["result"]["AppOrderID"]
|
|
689
694
|
|
|
690
|
-
def modify_price(
|
|
695
|
+
def modify_price(
|
|
696
|
+
self, order_id, price: float, trigger_price: float | None = None, order_type=None
|
|
697
|
+
):
|
|
691
698
|
self.modify_order(
|
|
692
699
|
{
|
|
693
700
|
"order_id": str(order_id),
|
|
@@ -9,7 +9,7 @@ import json
|
|
|
9
9
|
import logging
|
|
10
10
|
import os
|
|
11
11
|
import traceback
|
|
12
|
-
from typing import Any, Dict, Literal
|
|
12
|
+
from typing import Any, Dict, List, Literal
|
|
13
13
|
|
|
14
14
|
import requests
|
|
15
15
|
import urllib3
|
|
@@ -20,6 +20,9 @@ from six.moves.urllib.parse import urljoin # type:ignore
|
|
|
20
20
|
from quantplay.broker.xts_utils import Exception as ex
|
|
21
21
|
from quantplay.broker.xts_utils.Exception import XTSDataException
|
|
22
22
|
from quantplay.exception.exceptions import BrokerException
|
|
23
|
+
from quantplay.model.xts import (
|
|
24
|
+
XTSTypes,
|
|
25
|
+
)
|
|
23
26
|
|
|
24
27
|
log = logging.getLogger(__name__)
|
|
25
28
|
|
|
@@ -239,17 +242,17 @@ class XTSConnect(XTSCommon):
|
|
|
239
242
|
|
|
240
243
|
def place_order(
|
|
241
244
|
self,
|
|
242
|
-
exchangeSegment,
|
|
243
|
-
exchangeInstrumentID,
|
|
244
|
-
productType,
|
|
245
|
-
orderType,
|
|
246
|
-
orderSide,
|
|
247
|
-
timeInForce,
|
|
248
|
-
disclosedQuantity,
|
|
249
|
-
orderQuantity,
|
|
250
|
-
limitPrice,
|
|
251
|
-
stopPrice,
|
|
252
|
-
orderUniqueIdentifier,
|
|
245
|
+
exchangeSegment: XTSTypes.ExchangeType,
|
|
246
|
+
exchangeInstrumentID: int | str,
|
|
247
|
+
productType: XTSTypes.ProductType,
|
|
248
|
+
orderType: XTSTypes.OrderType,
|
|
249
|
+
orderSide: XTSTypes.OrderSide,
|
|
250
|
+
timeInForce: XTSTypes.DayOrNetType,
|
|
251
|
+
disclosedQuantity: int,
|
|
252
|
+
orderQuantity: int,
|
|
253
|
+
limitPrice: float,
|
|
254
|
+
stopPrice: float,
|
|
255
|
+
orderUniqueIdentifier: str,
|
|
253
256
|
clientID: str | None = None,
|
|
254
257
|
):
|
|
255
258
|
"""To place an order"""
|
|
@@ -279,18 +282,18 @@ class XTSConnect(XTSCommon):
|
|
|
279
282
|
|
|
280
283
|
def place_bracketorder(
|
|
281
284
|
self,
|
|
282
|
-
exchangeSegment,
|
|
283
|
-
exchangeInstrumentID,
|
|
284
|
-
orderType,
|
|
285
|
-
orderSide,
|
|
286
|
-
disclosedQuantity,
|
|
287
|
-
orderQuantity,
|
|
288
|
-
limitPrice,
|
|
289
|
-
squarOff,
|
|
290
|
-
stopLossPrice,
|
|
291
|
-
trailingStoploss,
|
|
292
|
-
isProOrder,
|
|
293
|
-
orderUniqueIdentifier,
|
|
285
|
+
exchangeSegment: XTSTypes.ExchangeType,
|
|
286
|
+
exchangeInstrumentID: int,
|
|
287
|
+
orderType: XTSTypes.OrderType,
|
|
288
|
+
orderSide: XTSTypes.OrderSide,
|
|
289
|
+
disclosedQuantity: int,
|
|
290
|
+
orderQuantity: int,
|
|
291
|
+
limitPrice: float,
|
|
292
|
+
squarOff: int,
|
|
293
|
+
stopLossPrice: float,
|
|
294
|
+
trailingStoploss: float,
|
|
295
|
+
isProOrder: bool,
|
|
296
|
+
orderUniqueIdentifier: str,
|
|
294
297
|
):
|
|
295
298
|
"""To place a bracketorder"""
|
|
296
299
|
try:
|
|
@@ -346,15 +349,15 @@ class XTSConnect(XTSCommon):
|
|
|
346
349
|
|
|
347
350
|
def modify_order(
|
|
348
351
|
self,
|
|
349
|
-
appOrderID,
|
|
350
|
-
modifiedProductType,
|
|
351
|
-
modifiedOrderType,
|
|
352
|
-
modifiedOrderQuantity,
|
|
353
|
-
modifiedDisclosedQuantity,
|
|
354
|
-
modifiedLimitPrice,
|
|
355
|
-
modifiedStopPrice,
|
|
356
|
-
modifiedTimeInForce,
|
|
357
|
-
orderUniqueIdentifier,
|
|
352
|
+
appOrderID: int,
|
|
353
|
+
modifiedProductType: XTSTypes.ProductType,
|
|
354
|
+
modifiedOrderType: XTSTypes.OrderType,
|
|
355
|
+
modifiedOrderQuantity: int,
|
|
356
|
+
modifiedDisclosedQuantity: int,
|
|
357
|
+
modifiedLimitPrice: float,
|
|
358
|
+
modifiedStopPrice: float,
|
|
359
|
+
modifiedTimeInForce: XTSTypes.DayOrNetType,
|
|
360
|
+
orderUniqueIdentifier: str,
|
|
358
361
|
clientID: str | None = None,
|
|
359
362
|
):
|
|
360
363
|
"""The facility to modify your open orders by allowing you to change limit order to market or vice versa,
|
|
@@ -439,12 +442,12 @@ class XTSConnect(XTSCommon):
|
|
|
439
442
|
|
|
440
443
|
def convert_position(
|
|
441
444
|
self,
|
|
442
|
-
exchangeSegment,
|
|
443
|
-
exchangeInstrumentID,
|
|
444
|
-
targetQty,
|
|
445
|
-
isDayWise,
|
|
446
|
-
oldProductType,
|
|
447
|
-
newProductType,
|
|
445
|
+
exchangeSegment: XTSTypes.ExchangeType,
|
|
446
|
+
exchangeInstrumentID: int,
|
|
447
|
+
targetQty: int,
|
|
448
|
+
isDayWise: bool,
|
|
449
|
+
oldProductType: XTSTypes.ProductType,
|
|
450
|
+
newProductType: XTSTypes.ProductType,
|
|
448
451
|
clientID: str | None = None,
|
|
449
452
|
):
|
|
450
453
|
"""Convert position API, enable users to convert their open positions from NRML intra-day to Short term MIS or
|
|
@@ -468,7 +471,7 @@ class XTSConnect(XTSCommon):
|
|
|
468
471
|
raise BrokerException("convert_position Failed for XTS")
|
|
469
472
|
|
|
470
473
|
def cancel_order(
|
|
471
|
-
self, appOrderID, orderUniqueIdentifier, clientID: str | None = None
|
|
474
|
+
self, appOrderID: int, orderUniqueIdentifier: str, clientID: str | None = None
|
|
472
475
|
):
|
|
473
476
|
"""This API can be called to cancel any open order of the user by providing correct appOrderID matching with
|
|
474
477
|
the chosen open order to cancel."""
|
|
@@ -485,7 +488,9 @@ class XTSConnect(XTSCommon):
|
|
|
485
488
|
traceback.print_exc()
|
|
486
489
|
raise BrokerException("cancel_order Failed for XTS")
|
|
487
490
|
|
|
488
|
-
def cancelall_order(
|
|
491
|
+
def cancelall_order(
|
|
492
|
+
self, exchangeSegment: XTSTypes.ExchangeSegmentType, exchangeInstrumentID: int
|
|
493
|
+
):
|
|
489
494
|
"""This API can be called to cancel all open order of the user by providing exchange segment and exchange instrument ID"""
|
|
490
495
|
try:
|
|
491
496
|
params: Dict[str, Any] = {
|
|
@@ -502,15 +507,15 @@ class XTSConnect(XTSCommon):
|
|
|
502
507
|
|
|
503
508
|
def place_cover_order(
|
|
504
509
|
self,
|
|
505
|
-
exchangeSegment,
|
|
506
|
-
exchangeInstrumentID,
|
|
507
|
-
orderSide,
|
|
508
|
-
orderType,
|
|
509
|
-
orderQuantity,
|
|
510
|
-
disclosedQuantity,
|
|
511
|
-
limitPrice,
|
|
512
|
-
stopPrice,
|
|
513
|
-
orderUniqueIdentifier,
|
|
510
|
+
exchangeSegment: XTSTypes.ExchangeType,
|
|
511
|
+
exchangeInstrumentID: int,
|
|
512
|
+
orderSide: XTSTypes.OrderSide,
|
|
513
|
+
orderType: XTSTypes.OrderType,
|
|
514
|
+
orderQuantity: int,
|
|
515
|
+
disclosedQuantity: int,
|
|
516
|
+
limitPrice: float,
|
|
517
|
+
stopPrice: float,
|
|
518
|
+
orderUniqueIdentifier: str,
|
|
514
519
|
clientID: str | None = None,
|
|
515
520
|
):
|
|
516
521
|
"""A Cover Order is an advance intraday order that is accompanied by a compulsory Stop Loss Order. This helps
|
|
@@ -537,7 +542,7 @@ class XTSConnect(XTSCommon):
|
|
|
537
542
|
traceback.print_exc()
|
|
538
543
|
raise BrokerException("place_cover_order Failed for XTS")
|
|
539
544
|
|
|
540
|
-
def exit_cover_order(self, appOrderID, clientID: str | None = None):
|
|
545
|
+
def exit_cover_order(self, appOrderID: int, clientID: str | None = None):
|
|
541
546
|
"""Exit Cover API is a functionality to enable user to easily exit an open stoploss order by converting it
|
|
542
547
|
into Exit order."""
|
|
543
548
|
try:
|
|
@@ -552,9 +557,9 @@ class XTSConnect(XTSCommon):
|
|
|
552
557
|
|
|
553
558
|
def squareoff_position(
|
|
554
559
|
self,
|
|
555
|
-
exchangeSegment,
|
|
556
|
-
exchangeInstrumentID,
|
|
557
|
-
productType,
|
|
560
|
+
exchangeSegment: XTSTypes.ExchangeType,
|
|
561
|
+
exchangeInstrumentID: int,
|
|
562
|
+
productType: XTSTypes.ProductType,
|
|
558
563
|
squareoffMode,
|
|
559
564
|
positionSquareOffQuantityType,
|
|
560
565
|
squareOffQtyValue,
|
|
@@ -583,7 +588,7 @@ class XTSConnect(XTSCommon):
|
|
|
583
588
|
traceback.print_exc()
|
|
584
589
|
raise BrokerException("squareoff_position Failed for XTS")
|
|
585
590
|
|
|
586
|
-
def get_order_history(self, appOrderID, clientID: str | None = None):
|
|
591
|
+
def get_order_history(self, appOrderID: int, clientID: str | None = None):
|
|
587
592
|
"""Order history will provide particular order trail chain. This indicate the particular order & its state
|
|
588
593
|
changes. i.e.Pending New to New, New to PartiallyFilled, PartiallyFilled, PartiallyFilled & PartiallyFilled
|
|
589
594
|
to Filled etc"""
|
|
@@ -641,7 +646,12 @@ class XTSConnect(XTSCommon):
|
|
|
641
646
|
traceback.print_exc()
|
|
642
647
|
raise BrokerException("get_config Failed for XTS")
|
|
643
648
|
|
|
644
|
-
def get_quote(
|
|
649
|
+
def get_quote(
|
|
650
|
+
self,
|
|
651
|
+
Instruments: List[XTSTypes.InstrumentType],
|
|
652
|
+
xtsMessageCode: XTSTypes.XTSMessageCodeType,
|
|
653
|
+
publishFormat: XTSTypes.PublishFormatType,
|
|
654
|
+
):
|
|
645
655
|
try:
|
|
646
656
|
params: Dict[str, Any] = {
|
|
647
657
|
"instruments": Instruments,
|
|
@@ -653,7 +663,11 @@ class XTSConnect(XTSCommon):
|
|
|
653
663
|
except Exception as e:
|
|
654
664
|
raise e
|
|
655
665
|
|
|
656
|
-
def send_subscription(
|
|
666
|
+
def send_subscription(
|
|
667
|
+
self,
|
|
668
|
+
Instruments: List[XTSTypes.InstrumentType],
|
|
669
|
+
xtsMessageCode: XTSTypes.XTSMessageCodeType,
|
|
670
|
+
):
|
|
657
671
|
try:
|
|
658
672
|
params: Dict[str, Any] = {
|
|
659
673
|
"instruments": Instruments,
|
|
@@ -665,7 +679,11 @@ class XTSConnect(XTSCommon):
|
|
|
665
679
|
traceback.print_exc()
|
|
666
680
|
raise BrokerException("send_subscription Failed for XTS")
|
|
667
681
|
|
|
668
|
-
def send_unsubscription(
|
|
682
|
+
def send_unsubscription(
|
|
683
|
+
self,
|
|
684
|
+
Instruments: List[XTSTypes.InstrumentType],
|
|
685
|
+
xtsMessageCode: XTSTypes.XTSMessageCodeType,
|
|
686
|
+
):
|
|
669
687
|
try:
|
|
670
688
|
params: Dict[str, Any] = {
|
|
671
689
|
"instruments": Instruments,
|
|
@@ -677,7 +695,7 @@ class XTSConnect(XTSCommon):
|
|
|
677
695
|
traceback.print_exc()
|
|
678
696
|
raise BrokerException("send_unsubscription Failed for XTS")
|
|
679
697
|
|
|
680
|
-
def get_master(self, exchangeSegmentList):
|
|
698
|
+
def get_master(self, exchangeSegmentList: List[XTSTypes.ExchangeType]):
|
|
681
699
|
try:
|
|
682
700
|
params: Dict[str, Any] = {"exchangeSegmentList": exchangeSegmentList}
|
|
683
701
|
response = self._post("market.instruments.master", json.dumps(params))
|
|
@@ -688,11 +706,11 @@ class XTSConnect(XTSCommon):
|
|
|
688
706
|
|
|
689
707
|
def get_ohlc(
|
|
690
708
|
self,
|
|
691
|
-
exchangeSegment,
|
|
692
|
-
exchangeInstrumentID,
|
|
693
|
-
startTime,
|
|
694
|
-
endTime,
|
|
695
|
-
compressionValue,
|
|
709
|
+
exchangeSegment: XTSTypes.ExchangeSegmentType,
|
|
710
|
+
exchangeInstrumentID: str | int,
|
|
711
|
+
startTime: str,
|
|
712
|
+
endTime: str,
|
|
713
|
+
compressionValue: Literal[1, 60, 120, 180, 300, 600, 900, 1800, 3600],
|
|
696
714
|
):
|
|
697
715
|
try:
|
|
698
716
|
params: Dict[str, Any] = {
|
|
@@ -708,7 +726,7 @@ class XTSConnect(XTSCommon):
|
|
|
708
726
|
traceback.print_exc()
|
|
709
727
|
raise BrokerException("get_ohlc Failed for XTS")
|
|
710
728
|
|
|
711
|
-
def get_series(self, exchangeSegment):
|
|
729
|
+
def get_series(self, exchangeSegment: XTSTypes.ExchangeSegmentType):
|
|
712
730
|
try:
|
|
713
731
|
params: Dict[str, Any] = {"exchangeSegment": exchangeSegment}
|
|
714
732
|
response = self._get("market.instruments.instrument.series", params)
|
|
@@ -717,7 +735,12 @@ class XTSConnect(XTSCommon):
|
|
|
717
735
|
traceback.print_exc()
|
|
718
736
|
raise BrokerException("get_series Failed for XTS")
|
|
719
737
|
|
|
720
|
-
def get_equity_symbol(
|
|
738
|
+
def get_equity_symbol(
|
|
739
|
+
self,
|
|
740
|
+
exchangeSegment: XTSTypes.ExchangeSegmentType,
|
|
741
|
+
series: XTSTypes.SeriesType,
|
|
742
|
+
symbol: str,
|
|
743
|
+
):
|
|
721
744
|
try:
|
|
722
745
|
params: Dict[str, Any] = {
|
|
723
746
|
"exchangeSegment": exchangeSegment,
|
|
@@ -730,7 +753,12 @@ class XTSConnect(XTSCommon):
|
|
|
730
753
|
traceback.print_exc()
|
|
731
754
|
raise BrokerException("get_equity_symbol Failed for XTS")
|
|
732
755
|
|
|
733
|
-
def get_expiry_date(
|
|
756
|
+
def get_expiry_date(
|
|
757
|
+
self,
|
|
758
|
+
exchangeSegment: XTSTypes.ExchangeSegmentType,
|
|
759
|
+
series: XTSTypes.SeriesType,
|
|
760
|
+
symbol: str,
|
|
761
|
+
):
|
|
734
762
|
try:
|
|
735
763
|
params: Dict[str, Any] = {
|
|
736
764
|
"exchangeSegment": exchangeSegment,
|
|
@@ -743,7 +771,13 @@ class XTSConnect(XTSCommon):
|
|
|
743
771
|
traceback.print_exc()
|
|
744
772
|
raise BrokerException("get_expiry_date Failed for XTS")
|
|
745
773
|
|
|
746
|
-
def get_future_symbol(
|
|
774
|
+
def get_future_symbol(
|
|
775
|
+
self,
|
|
776
|
+
exchangeSegment: XTSTypes.ExchangeSegmentType,
|
|
777
|
+
series: XTSTypes.SeriesType,
|
|
778
|
+
symbol: str,
|
|
779
|
+
expiryDate: str,
|
|
780
|
+
):
|
|
747
781
|
try:
|
|
748
782
|
params: Dict[str, Any] = {
|
|
749
783
|
"exchangeSegment": exchangeSegment,
|
|
@@ -758,7 +792,13 @@ class XTSConnect(XTSCommon):
|
|
|
758
792
|
raise BrokerException("get_future_symbol Failed for XTS")
|
|
759
793
|
|
|
760
794
|
def get_option_symbol(
|
|
761
|
-
self,
|
|
795
|
+
self,
|
|
796
|
+
exchangeSegment: XTSTypes.ExchangeSegmentType,
|
|
797
|
+
series: XTSTypes.SeriesType,
|
|
798
|
+
symbol: str,
|
|
799
|
+
expiryDate: str,
|
|
800
|
+
optionType: Literal["CE", "PE"],
|
|
801
|
+
strikePrice: int,
|
|
762
802
|
):
|
|
763
803
|
try:
|
|
764
804
|
params: Dict[str, Any] = {
|
|
@@ -775,7 +815,13 @@ class XTSConnect(XTSCommon):
|
|
|
775
815
|
traceback.print_exc()
|
|
776
816
|
raise BrokerException("get_option_symbol Failed for XTS")
|
|
777
817
|
|
|
778
|
-
def get_option_type(
|
|
818
|
+
def get_option_type(
|
|
819
|
+
self,
|
|
820
|
+
exchangeSegment: XTSTypes.ExchangeSegmentType,
|
|
821
|
+
series: XTSTypes.SeriesType,
|
|
822
|
+
symbol: str,
|
|
823
|
+
expiryDate: str,
|
|
824
|
+
):
|
|
779
825
|
try:
|
|
780
826
|
params: Dict[str, Any] = {
|
|
781
827
|
"exchangeSegment": exchangeSegment,
|
|
@@ -789,7 +835,7 @@ class XTSConnect(XTSCommon):
|
|
|
789
835
|
traceback.print_exc()
|
|
790
836
|
raise BrokerException("get_option_type Failed for XTS")
|
|
791
837
|
|
|
792
|
-
def get_index_list(self, exchangeSegment):
|
|
838
|
+
def get_index_list(self, exchangeSegment: XTSTypes.ExchangeSegmentType):
|
|
793
839
|
try:
|
|
794
840
|
params: Dict[str, Any] = {"exchangeSegment": exchangeSegment}
|
|
795
841
|
response = self._get("market.instruments.indexlist", params)
|
|
@@ -798,7 +844,7 @@ class XTSConnect(XTSCommon):
|
|
|
798
844
|
traceback.print_exc()
|
|
799
845
|
raise BrokerException("get_index_list Failed for XTS")
|
|
800
846
|
|
|
801
|
-
def search_by_instrumentid(self, Instruments):
|
|
847
|
+
def search_by_instrumentid(self, Instruments: List[XTSTypes.InstrumentType]):
|
|
802
848
|
try:
|
|
803
849
|
params: Dict[str, Any] = {"source": self.source, "instruments": Instruments}
|
|
804
850
|
response = self._post("market.search.instrumentsbyid", json.dumps(params))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
from typing import Dict, List, Literal
|
|
2
|
-
import socketio
|
|
1
|
+
from typing import Any, Dict, List, Literal
|
|
2
|
+
import socketio # type: ignore
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
class OrderSocket_io(socketio.Client):
|
|
@@ -48,8 +48,8 @@ class OrderSocket_io(socketio.Client):
|
|
|
48
48
|
randomization_factor: float = 0.5,
|
|
49
49
|
logger: bool = False,
|
|
50
50
|
binary: bool = False,
|
|
51
|
-
json=None,
|
|
52
|
-
**kwargs,
|
|
51
|
+
json: Any | None = None,
|
|
52
|
+
**kwargs: Any,
|
|
53
53
|
):
|
|
54
54
|
self.sid = socketio.Client(logger=False, engineio_logger=False)
|
|
55
55
|
self.eventlistener = self.sid
|
|
@@ -65,17 +65,17 @@ class OrderSocket_io(socketio.Client):
|
|
|
65
65
|
port + self.token + "&userID=" + self.userID + "&apiType=INTERACTIVE"
|
|
66
66
|
)
|
|
67
67
|
|
|
68
|
-
def setup_event_listners(self, on_order):
|
|
69
|
-
self.sid.on("order", on_order)
|
|
68
|
+
def setup_event_listners(self, on_order: Any):
|
|
69
|
+
self.sid.on("order", on_order) # type: ignore
|
|
70
70
|
|
|
71
71
|
# self.sid.on("connect", self.on_connect)
|
|
72
|
-
self.sid.on("message", self.on_message)
|
|
72
|
+
self.sid.on("message", self.on_message) # type: ignore
|
|
73
73
|
# self.sid.on("joined", self.on_joined)
|
|
74
|
-
self.sid.on("error", self.on_error)
|
|
75
|
-
self.sid.on("trade", self.on_trade)
|
|
76
|
-
self.sid.on("position", self.on_position)
|
|
77
|
-
self.sid.on("tradeConversion", self.on_tradeconversion)
|
|
78
|
-
self.sid.on("logout", self.on_messagelogout)
|
|
74
|
+
self.sid.on("error", self.on_error) # type: ignore
|
|
75
|
+
self.sid.on("trade", self.on_trade) # type: ignore
|
|
76
|
+
self.sid.on("position", self.on_position) # type: ignore
|
|
77
|
+
self.sid.on("tradeConversion", self.on_tradeconversion) # type: ignore
|
|
78
|
+
self.sid.on("logout", self.on_messagelogout) # type: ignore
|
|
79
79
|
# self.sid.on("disconnect", self.on_disconnect)
|
|
80
80
|
|
|
81
81
|
def connect( # type: ignore
|
|
@@ -108,7 +108,7 @@ class OrderSocket_io(socketio.Client):
|
|
|
108
108
|
url = self.connection_url
|
|
109
109
|
|
|
110
110
|
"""Connected to the socket."""
|
|
111
|
-
self.sid.connect(url, headers, transports, namespaces, socketio_path)
|
|
111
|
+
self.sid.connect(url, headers, transports, namespaces, socketio_path) # type: ignore
|
|
112
112
|
self.sid.wait()
|
|
113
113
|
"""Disconnect from the socket."""
|
|
114
114
|
# self.sid.disconnect()
|
|
@@ -121,33 +121,33 @@ class OrderSocket_io(socketio.Client):
|
|
|
121
121
|
"""On message from socket"""
|
|
122
122
|
print("I received a message!")
|
|
123
123
|
|
|
124
|
-
def on_joined(self, data):
|
|
124
|
+
def on_joined(self, data: Any):
|
|
125
125
|
"""On socket joined"""
|
|
126
|
-
print("Interactive socket joined successfully!"
|
|
126
|
+
print(f"Interactive socket joined successfully!{data}")
|
|
127
127
|
|
|
128
|
-
def on_error(self, data):
|
|
128
|
+
def on_error(self, data: Any):
|
|
129
129
|
"""On receiving error from socket"""
|
|
130
|
-
print("Interactive socket error!"
|
|
130
|
+
print(f"Interactive socket error!{data}")
|
|
131
131
|
|
|
132
|
-
def on_order(self, data):
|
|
132
|
+
def on_order(self, data: Any):
|
|
133
133
|
"""On receiving order placed data from socket"""
|
|
134
|
-
print("Order placed!"
|
|
134
|
+
print(f"Order placed!{data}")
|
|
135
135
|
|
|
136
|
-
def on_trade(self, data):
|
|
136
|
+
def on_trade(self, data: Any):
|
|
137
137
|
"""On receiving trade data from socket"""
|
|
138
|
-
print("Trade Received!"
|
|
138
|
+
print(f"Trade Received!{data}")
|
|
139
139
|
|
|
140
|
-
def on_position(self, data):
|
|
140
|
+
def on_position(self, data: Any):
|
|
141
141
|
"""On receiving position data from socket"""
|
|
142
|
-
print("Position Retrieved!"
|
|
142
|
+
print(f"Position Retrieved!{data}")
|
|
143
143
|
|
|
144
|
-
def on_tradeconversion(self, data):
|
|
144
|
+
def on_tradeconversion(self, data: Any):
|
|
145
145
|
"""On receiving trade conversion data from socket"""
|
|
146
|
-
print("Trade Conversion Received!"
|
|
146
|
+
print(f"Trade Conversion Received!{data}")
|
|
147
147
|
|
|
148
|
-
def on_messagelogout(self, data):
|
|
148
|
+
def on_messagelogout(self, data: Any):
|
|
149
149
|
"""On receiving user logout message"""
|
|
150
|
-
print("User logged out!"
|
|
150
|
+
print(f"User logged out!{data}")
|
|
151
151
|
|
|
152
152
|
def on_disconnect(self):
|
|
153
153
|
"""On receiving disconnection from socket"""
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from typing import Literal, TypedDict
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
XTSExchangeSegmentType = Literal[1, 2, 3, 11, 12]
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class XTSInstrumentType(TypedDict):
|
|
8
|
+
exchangeSegment: XTSExchangeSegmentType
|
|
9
|
+
exchangeInstrumentID: str | int
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class XTSTypes:
|
|
13
|
+
ExchangeSegmentType = XTSExchangeSegmentType
|
|
14
|
+
XTSMessageCodeType = Literal[1501, 1502, 1505, 1507, 1510, 1512, 1105]
|
|
15
|
+
PublishFormatType = Literal["JSON", "Binary"]
|
|
16
|
+
ExchangeType = Literal["NSECM", "NSEFO", "NSECD", "BSECM", "BSEFO"]
|
|
17
|
+
InstrumentType = XTSInstrumentType
|
|
18
|
+
SeriesType = str
|
|
19
|
+
OrderSide = Literal["BUY", "SELL"]
|
|
20
|
+
OrderType = Literal["Market", "StopLimit", "StopMarket", "Limit"]
|
|
21
|
+
ProductType = Literal["CO", "CNC", "MIS", "NRML"]
|
|
22
|
+
PositionSqureOffModeType = Literal["DayWise", "NetWise"]
|
|
23
|
+
PositionSquareOffQuantityTypeType = Literal["Percentage", "ExactQty"]
|
|
24
|
+
DayOrNetType = Literal["DAY", "NET"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|