Skip to content

Commit

Permalink
Merge pull request #264 from OpenApi-5p/users/jenish/headersChanges
Browse files Browse the repository at this point in the history
Headers Changes
  • Loading branch information
5paisa authored Oct 10, 2023
2 parents ad9ada7 + fa978d3 commit 929036a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions py5paisa/py5paisa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions py5paisa/urlconst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 929036a

Please sign in to comment.