diff --git a/py5paisa/py5paisa.py b/py5paisa/py5paisa.py index 8cda7b70..82c24cc4 100644 --- a/py5paisa/py5paisa.py +++ b/py5paisa/py5paisa.py @@ -36,6 +36,7 @@ def __init__(self, cred=None): self.PASSWORD = cred["PASSWORD"] self.USER_KEY = cred["USER_KEY"] self.ENCRYPTION_KEY = cred["ENCRYPTION_KEY"] + self.APIUID = APIUID self.create_payload() self.set_url() @@ -69,6 +70,7 @@ def positions(self): def _login_request(self, route): try: requests.packages.urllib3.disable_warnings(InsecureRequestWarning) + HEADERS["5Paisa-API-Uid"] = self.APIUID res = self.session.post( route, json=self.login_payload, headers=HEADERS) resp = res.json() @@ -90,6 +92,7 @@ def _user_info_request(self, data_type): payload["body"]["ClientCode"] = self.client_code payload["head"]["key"] = self.USER_KEY HEADERS["Authorization"] = f'Bearer {self.access_token}' + HEADERS["5Paisa-API-Uid"] = self.APIUID return_type = "" if data_type == "MARGIN": url = self.MARGIN_ROUTE @@ -124,6 +127,7 @@ def order_request(self, req_type) -> None: self.payload["body"]["ClientCode"] = self.client_code self.payload["head"]["key"] = self.USER_KEY HEADERS["Authorization"] = f'Bearer {self.access_token}' + HEADERS["5Paisa-API-Uid"] = self.APIUID if req_type == "OP": url = self.ORDER_PLACEMENT_ROUTE # self.payload["head"]["requestCode"] = "5PPlaceOrdReq" @@ -511,6 +515,7 @@ def Login_check(self): self.login_check_payload["head"]["appName"] = self.APP_NAME self.login_check_payload["head"]["LoginId"] = self.client_code self.login_check_payload["body"]["RegistrationID"] = self.Jwt_token + HEADERS["5Paisa-API-Uid"] = self.APIUID url = self.LOGIN_CHECK_ROUTE resl = requests.post( url, json=self.login_check_payload, headers=HEADERS) @@ -525,6 +530,7 @@ def jwt_validate(self): try: self.jwt_payload['ClientCode'] = self.client_code self.jwt_payload['JwtCode'] = self.Jwt_token + HEADERS["5Paisa-API-Uid"] = self.APIUID url = self.JWT_VALIDATION_ROUTE response = self.session.post( url, json=self.jwt_payload, headers=HEADERS).json() @@ -537,6 +543,7 @@ def historical_data(self, Exch: str, ExchangeSegment: str, ScripCode: int, time: try: self.jwt_headers['x-clientcode'] = self.client_code self.jwt_headers['x-auth-token'] = self.Jwt_token + self.jwt_headers["5Paisa-API-Uid"] = self.APIUID url = f'{self.HISTORICAL_DATA_ROUTE}{Exch}/{ExchangeSegment}/{ScripCode}/{time}?from={From}&end={To}' timeList = ['1m', '3m', '5m', '10m', '15m', '30m', '60m', '1d'] if time not in timeList: diff --git a/py5paisa/urlconst.py b/py5paisa/urlconst.py index 3c714f8a..5cee6a28 100644 --- a/py5paisa/urlconst.py +++ b/py5paisa/urlconst.py @@ -55,3 +55,4 @@ SQUAREOFF_ROUTE = f'{BaseUrl}SquareOffAll' POSITION_CONVERSION_ROUTE = f'{BaseUrl}PositionConversion' MARKET_DEPTH_ROUTE_20 = "https://openapi.5paisa.com/marketfeed-token/token" +APIUID = 'ka7SFqAU6SC'