In order to allow placing orders, we can authenticate our application. This will ensure that the application can be identified, that the user is valid, and that trading is secure.
By using the share trading API, we can make requests to brokerage services. Using the HDFC SKY Open API, applications can be made to place orders, custom applications can be connected, and orders can be placed automatically.
An active trading account is required. Python and Requests should be installed. You should also have an application registered.
What Should You Prepare Before Connecting?
Start with an active trading account and access to the HDFC SKY Developer Portal. You will also need Python, the Requests library and a registered API application.
Register an application within the Developer Portal. Enter the name, registered redirect URL and static IP address where required. Once your application is active, you can view your API Key and API Secret.
Store these securely on your server. Do not include the API Secret in public JS or mobile applications.
If you are new to investing, you may need to open demat account, and complete KYC requirements. In order to place orders using this API, you also need an active trading account.
How Does the Authentication Process Work?
This is a simple process to authenticate users between your application and the broker. Each of these values has a specific role.
-
API Key: Identifies your registered application.
-
API Secret: Helps verify the application during token generation.
-
Request Token: Confirms successful user login and authorisation.
-
Access Token: Allows approved API requests.
Redirect the user to log in within HDFC SKY. The user will enter their trading credentials and complete an OTP verification. Once permissions have been given, the user will be redirected to the registered redirect URL. A temporary Request Token will be provided.
This Request Token is then converted by your server into an Access Token.
What Does Your First Order Request Look Like?
Begin by placing a small order. Ensure that you are familiar with all the parameters.
The following parameters are usually included in an order: Exchange, Symbol, Quantity, Product, Order Type, Validity. If the order type is Limit, it must also include a price.
Ensure that the endpoint, parameter names and values given match those in the most up-to-date Developer Documentation. Also ensure that you are including the correct format of authorisation headers.
What Should You Check After Sending the Order?
Even if you receive a success status code in your HTTP response, it may not mean the order was successfully placed. Check the order ID and status to see if it was placed. The order may still be pending, rejected, or placed at a different price.
Do not place the same request multiple times after a timeout. First check the order book to ensure you are not making duplicate trades.
Once you have tested your application and ensured that your credentials are being kept safe and that each parameter in the order is checked, you have a much stronger base for a reliable trading application.
