User
This page describes the user-related endpoints of the Trading API, including authentication, profile, margins, and logout.
Login Flow
To start the login process, navigate the user to:
https://api.blinkx.in/connect/login?v=3&api_key=YOUR_API_KEY
Authentication and token exchange
curl https://api.blinkx.in/SmartApi/session/token \
-H "X-Version: 3" \
-d "api_key=xxx" \
-d "request_token=yyy" \
-d "checksum=zzz"
{
"status": "success",
"data": {
"user_type": "individual",
"email": "XXXXXX",
"user_name": "Trading API",
"user_shortname": "Trading",
"broker": "JM Financial",
"exchanges": [
"NSE",
"NFO",
"BFO",
"CDS",
"BSE",
"MCX",
"BCD",
"MF"
],
"products": [
"CNC",
"NRML",
"MIS",
"BO",
"CO"
],
"order_types": [
"LIMIT",
"SL"
],
"avatar_url": "abc",
"user_id": "XX0000",
"api_key": "XXXXXX",
"access_token": "XXXXXX",
"public_token": "XXXXXXXX",
"enctoken": "XXXXXX",
"refresh_token": '',
"silo": '',
"login_time": "2021-01-01 16:15:14",
"meta": {
"demat_consent": "physical"
}
}
}
Request parameters
| Parameter | Description |
|---|---|
api_key | The public API key |
request_token | The one-time token obtained after the login flow. This token's lifetime is only a few minutes and it is meant to be exchanged for an access_token immediately after being obtained |
checksum | SHA-256 hash of (api_key + request_token + api_secret) |
Response attributes
| Attribute | Type | Description |
|---|---|---|
user_id | string | The unique, permanent user id registered with the broker and the exchanges |
user_name | string | User's real name |
user_shortname | string | Shortened version of the user's real name |
email | string | User's email |
user_type | string | User's registered role at the broker. This will be individual for all retail users |
broker | string | The broker ID |
exchanges | string[] | Exchanges enabled for trading on the user's account |
products | string[] | Margin product types enabled for the user |
order_types | string[] | Order types enabled for the user |
api_key | string | The API key for which the authentication was performed |
access_token | string | The authentication token that's used with every subsequent request. Unless this is invalidated using the API, or invalidated by a master-logout from the BlinkX Web trading terminal, it'll expire at 6 AM on the next day (regulatory requirement) |
public_token | string | A token for public session validation where requests may be exposed to the public |
refresh_token | string | A token for getting long-standing read permissions. This is only available to certain approved platforms |
login_time | string | User's last login time |
meta | map | demat_consent: empty, consent or physical |
avatar_url | string | Full URL to the user's avatar (PNG image) if there's one |
Signing requests
Once the authentication is complete, all requests should be signed with the HTTP Authorization header with token as the authorisation scheme, followed by a space, and then the api_key:access_token combination. For example:
User profile
While a successful token exchange returns the full user profile, it's possible to retrieve it any point of time with the /user/profile API. Do note that the profile API does not return any of the tokens.
curl https://api.blinkx.in/SmartApi/user/profile \
-H "X-Version: 3" \
-H "Authorization: token api_key:access_token"
{
"status": "success",
"data": {
"user_id": "AB1234",
"user_type": "individual",
"email": "xxxyyy@gmail.com",
"user_name": "AxAx Bxx",
"user_shortname": "AxAx",
"broker": "JM Financial",
"exchanges": [
"BFO",
"MCX",
"NSE",
"CDS",
"BSE",
"BCD",
"MF",
"NFO"
],
"products": [
"CNC",
"NRML",
"MIS",
"BO",
"CO"
],
"order_types": [
"LIMIT",
"SL"
],
"avatar_url": null,
"meta": {
"demat_consent": "physical"
}
}
}
Response attributes
| Attribute | Type | Description |
|---|---|---|
user_id | string | The unique, permanent user id registered with the broker and the exchanges |
user_name | string | User's real name |
user_shortname | string | Shortened version of the user's real name |
email | string | User's email |
user_type | string | User's registered role at the broker. This will be individual for all retail users |
broker | string | The broker ID |
exchanges | string[] | Exchanges enabled for trading on the user's account |
products | string[] | Margin product types enabled for the user |
order_types | string[] | Order types enabled for the user |
meta | map | demat_consent: empty, consent or physical |
avatar_url | string | Full URL to the user's avatar (PNG image) if there's one |
Funds and margins
A GET request to /user/margins returns funds, cash, and margin information for the user for equity and commodity segments.
A GET request to /user/margins/:segment returns funds, cash, and margin information for the user. segment in the URI can be either equity or commodity.
curl "https://api.blinkx.in/SmartApi/user/margins" \
-H "X-Version: 3" \
-H "Authorization: token api_key:access_token"
{
"status": "success",
"data": {
"equity": {
"enabled": true,
"net": 99725.05000000002,
"available": {
"adhoc_margin": 0,
"cash": 245431.6,
"opening_balance": 245431.6,
"live_balance": 99725.05000000002,
"collateral": 0,
"intraday_payin": 0
},
"utilised": {
"debits": 145706.55,
"exposure": 38981.25,
"m2m_realised": 761.7,
"m2m_unrealised": 0,
"option_premium": 0,
"payout": 0,
"span": 101989,
"holding_sales": 0,
"turnover": 0,
"liquid_collateral": 0,
"stock_collateral": 0,
"delivery": 0
}
},
"commodity": {
"enabled": true,
"net": 100661.7,
"available": {
"adhoc_margin": 0,
"cash": 100661.7,
"opening_balance": 100661.7,
"live_balance": 100661.7,
"collateral": 0,
"intraday_payin": 0
},
"utilised": {
"debits": 0,
"exposure": 0,
"m2m_realised": 0,
"m2m_unrealised": 0,
"option_premium": 0,
"payout": 0,
"span": 0,
"holding_sales": 0,
"turnover": 0,
"liquid_collateral": 0,
"stock_collateral": 0,
"delivery": 0
}
}
}
}
Response attributes
| Attribute | Type | Description |
|---|---|---|
m2m_unrealised | float64 | Un-booked (open) intraday profits and losses |
m2m_realised | float64 | Booked intraday profits and losses |
debits | float64 | Sum of all utilised margins (unrealised M2M + realised M2M + SPAN + Exposure + Premium + Holding sales) |
span | float64 | SPAN margin blocked for all open F&O positions |
option_premium | float64 | Value of options premium received by shorting |
holding_sales | float64 | Value of holdings sold during the day |
exposure | float64 | Exposure margin blocked for all open F&O positions |
liquid_collateral | float64 | Margin utilised against pledged liquidbees ETFs and liquid mutual funds |
delivery | float64 | Margin blocked when you sell securities (20% of the value of stocks sold) from your demat or T1 holdings |
stock_collateral | float64 | Margin utilised against pledged stocks/ETFs |
turnover | float64 | Utilised portion of the maximum turnover limit (only applicable to certain clients) |
payout | float64 | Funds paid out or withdrawn to bank account during the day |
Logout
This call invalidates the access_token and destroys the API session. After this, the user should be sent through a new login flow before further interactions. This does not log the user out of the official BlinkX web or mobile applications.
curl --request DELETE \
-H "X-Version: 3" \
"https://api.blinkx.in/SmartApi/session/token?api_key=xxx&access_token=yyy"
{
"status": "success",
"data": true
}