Skip to content

Commit

Permalink
Merge pull request #271 from OpenApi-5p/users/jenish/vtt
Browse files Browse the repository at this point in the history
VTT code merge
  • Loading branch information
5paisa authored Jan 8, 2024
2 parents 4d29b90 + 03a0bf0 commit d571730
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions py5paisa/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Contains reusable payloads across requests
"""
import datetime
from enum import Enum

HEADERS = {'Content-Type': 'application/json'}

Expand Down Expand Up @@ -70,6 +71,13 @@
"method":"",
"instruments":""}

class VTT_TYPE(Enum):
P = 'VTT'
M = 'MVTT'
C = 'CVTT'
G = 'GVTT'
H = 'HVTT'

SUBSCRIPTION_KEY="c89fab8d895a426d9e00db380b433027"
TODAY_TIMESTAMP = int(datetime.datetime.today().timestamp())
NEXT_DAY_TIMESTAMP = int(
Expand Down
28 changes: 28 additions & 0 deletions py5paisa/py5paisa.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, cred=None):
self.USER_KEY = cred["USER_KEY"]
self.ENCRYPTION_KEY = cred["ENCRYPTION_KEY"]
self.APIUID = APIUID
self.VTT_TYPE = VTT_TYPE
self.create_payload()
self.set_url()

Expand Down Expand Up @@ -221,6 +222,16 @@ def order_request(self, req_type) -> None:
url = self.ORDERMARGIN_ROUTE
if self.access_token != "":
HEADERS["Authorization"] = f'Bearer {self.Jwt_token}'
elif req_type == "VTT":
url = self.ADDVTTORDER_ROUTE
elif req_type == "MVTT":
url = self.MODVTTORDER_ROUTE
elif req_type == "CVTT":
url = self.CALVTTORDER_ROUTE
elif req_type == "GVTT":
url = self.GETVTTORDER_ROUTE
elif req_type == "HVTT":
url = self.HISVTTORDER_ROUTE
else:
raise Exception("Invalid request type!")
res = self.session.post(url, json=self.payload,
Expand Down Expand Up @@ -647,6 +658,11 @@ def set_url(self):
self.POSITION_CONVERSION_ROUTE = POSITION_CONVERSION_ROUTE
self.MARKET_DEPTH_BY_SYMBOL_ROUTE = MARKET_DEPTH_BY_SYMBOL_ROUTE
self.MARKET_DEPTH_BY_SCRIP = MARKET_DEPTH_BY_SCRIP
self.ADDVTTORDER_ROUTE = ADDVTTORDER_ROUTE
self.CALVTTORDER_ROUTE = CALVTTORDER_ROUTE
self.MODVTTORDER_ROUTE = MODVTTORDER_ROUTE
self.GETVTTORDER_ROUTE = GETVTTORDER_ROUTE
self.HISVTTORDER_ROUTE = HISVTTORDER_ROUTE
except Exception as e:
log_response(e)

Expand Down Expand Up @@ -892,3 +908,15 @@ def Order_margin(self,**order):
return self.order_request("OMC")
except Exception as e:
log_response(e)

def vtt_order(self, order_type, **order):
try:
self.set_payload(order)
order_type_str = self.VTT_TYPE[order_type].value
print(order_type_str)
return self.order_request(order_type_str)
except KeyError:
# Handle unknown order_type if needed
pass
except Exception as e:
log_response(e)
5 changes: 5 additions & 0 deletions py5paisa/urlconst.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@
MARKET_DEPTH_ROUTE_20 = "https://openapi.5paisa.com/marketfeed-token/token"
APIUID = 'ka7SFqAU6SC'
ORDERMARGIN_ROUTE='https://Swarajtrade.5paisa.com/5P_PreOrderMargin/Service1.svc/V1/PreOrdMarginCalculationVendor'
ADDVTTORDER_ROUTE=f'{BaseUrl}AddVTTOrder'
CALVTTORDER_ROUTE=f'{BaseUrl}CancelVTTOrder'
MODVTTORDER_ROUTE=f'{BaseUrl}ModifyVTTOrder'
GETVTTORDER_ROUTE=f'{BaseUrl}GetVTTOrder'
HISVTTORDER_ROUTE=f'{BaseUrl}GetHistoryVTTOrder'
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"loguru>=0.5.1",
"websocket-client>=0.58.0",
"pandas>=1.2.4",
"Enum"
]

setup_requirements = []
Expand Down

0 comments on commit d571730

Please sign in to comment.