Portfolio

List All Portfolios

  • The GET request requires the access_key and the time-sensitive secret_key generated using the generate_token API request.
  • The API returns a list of all the portfolios. To query the portfolio details or delete portfolios, the respective APIs use the portfolio_id rather than the portfolio name as the identifier. The listPortfolios API gives the portfolio_id for all the portfolios for the user.

RESPONSE BODY SCHEMA:

status
Boolean
response_code
String
response
List
RESPONSE CODES
s01
Success
err01
Error message
a-err01
Authentication Error
Get /user/portfolio/listPortfolios

Default server

https://api.qfinr.com/api/user/portfolio/listPortfolios

Request Samples

php
python

Copy
<?php

$curl 
curl_init();

curl_setopt_array($curl, array(
  
CURLOPT_URL => 'https://api.qfinr.com/api/user/portfolio/listPortfolios',
  
CURLOPT_RETURNTRANSFER => true,
  
CURLOPT_ENCODING => '',
  
CURLOPT_MAXREDIRS => 10,
  
CURLOPT_TIMEOUT => 0,
  
CURLOPT_FOLLOWLOCATION => true,
  
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  
CURLOPT_CUSTOMREQUEST => 'GET',
  
CURLOPT_USERPWD => ($username ":" $password),
));

$response curl_exec($curl);

curl_close($curl);
echo 
$response
1
import requests
from base64 import b64encode
url = "https://api.qfinr.com/api/user/portfolio/listPortfolios"

payload={}
userAndPass = b64encode(b"username:password").decode("ascii")
headers = {
  'Authorization': 'Basic %s' %  userAndPass
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)
1

Portfolio Details

  • The details API returns the individual holdings with the portfolio_id portfolio. The portfolio_id is available from the listPortfolios API. If no portfolio_id is sent, the details API returns the respective holdings of all portfolios for the account.

RESPONSE BODY SCHEMA:

status
Boolean
response_code
String
response
List
RESPONSE CODES
s01
Success
err01
Error message
err02
Unauthorized access
a-err01
Authentication Error
Get /user/portfolio/details/{portfolio_id}

Default server

https://api.qfinr.com/api/user/portfolio/details/{portfolio_id}

Request Samples

php
python
<?php

$curl 
curl_init();

curl_setopt_array($curl, array(
  
CURLOPT_URL => 'https://api.qfinr.com/api/user/portfolio/details/{{portfolio_id}}',
  
CURLOPT_RETURNTRANSFER => true,
  
CURLOPT_ENCODING => '',
  
CURLOPT_MAXREDIRS => 10,
  
CURLOPT_TIMEOUT => 0,
  
CURLOPT_FOLLOWLOCATION => true,
  
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  
CURLOPT_CUSTOMREQUEST => 'GET',
  
CURLOPT_USERPWD => ($username ":" $password),
));

$response curl_exec($curl);

curl_close($curl);
echo 
$response;
1
import requests
from base64 import b64encode 
url = "https://api.qfinr.com/api/user/portfolio/details/{{portfolio_id}}"

payload={}
userAndPass = b64encode(b"username:password").decode("ascii")
headers = { 'Authorization': 'Basic %s' % userAndPass }

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)
1

Update Portfolio

  • The updatePortfolio API creates a new portfolio for the user. The API requires portfolio_name, a name for the portfolio and transactions, and a JSON of holdings and transactions for the portfolio.
  • The portfolio_name should be a unique name for the portfolio.
  • The transactions JSON should have
    • instruments: ISIN or Exchange Ticker for the security. A required field.
    • holding: The number of units of the security. A required field
    • type: buy or sell. A required field
    • price: Purchase or sale price. A required field if date is entered; otherwise, optional. If no price is entered, qfinr will take the security price from three years from the upload date, or if no price is available, then, the next earliest available price.
    • date: The transaction date in YYYY-mm-dd format. A required field if price is entered; otherwise, optional.
    • Some examples of valid transactions JSON lists

      transactions = [{"instrument": "ACC","holding": "80","type": "buy","price": "1456","date": "2020-05-07"}]

      transactions = [{"instrument": "INE012A01025","holding": "100","type": "buy","price": "1672.47","date": "2020-05-07"}]

      transactions=[{"instrument": "ACC","holding": "80","type": "buy","price": "1456","date": "2020-05-07"},{"instrument": "INE176A01028","holding": "100","type": "buy","price": "1672.47","date": "2020-05-07"}]

      transactions=[{"instrument": "ACC","holding": "80","type": "buy","price": "","date": ""},{"instrument": "INE176A01028","holding": "100","type": "buy", "price": "","date": ""}]

      Some examples of invalid transactions JSON lists

      transactions = [{"instrument": "BATA INDIA","holding": "80","type": "buy","price": "1456","date": "2020-05-07"}]

      transactions = [{"instrument": "INE012A01025","holding": "100","type": "buy","price": "1672.47","date": ""}

      transactions=[{"instrument": "ACC","holding": "80","type": "buy","price": "","date": "2020-05-07"}

      transactions=[{"instrument": "ACC","holding": "80","type": "","price": "","date": ""]

  • The updatePortfolio response gives details of the creation of the portfolio. The response provides details of securities uploaded and not uploaded. If the security is not in the qfinr database, the security will not get uploaded. Please write to care@qfinr.com giving details of such securities, and the data content team will investigate adding these securities. Usually, the team deals with such inquiries within 24 hours.

REQUEST BODY SCHEMA:

portfolio_name
String
Required
transactions
JSON List
Required

Example: [{"instrument":"ACC.NS","holding":"80","type":"buy","price":"1456","date":"2020-05-07"},{"instrument":"BATA.NS","holding":"100","type":"buy","price":"1672.47","date":"2020-05-07"}]

Use ISIN, TICKER, RIC for instruments
RESPONSE BODY SCHEMA:

status
Boolean
response_code
String
response
Array
portfolio_id
String
portfolio_name
String
total_instruments
String
success_count
String
failed_instruments
List
RESPONSE CODES
s01
Success
err01
Error message
err02
Server Error
a-err01
Authentication Error
Post /user/portfolio/updatePortfolio

Default server

https://api.qfinr.com/api/user/portfolio/updatePortfolio

Request Samples

php
python
<?php

$curl 
curl_init();

curl_setopt_array($curl, array(
  
CURLOPT_URL => 'https://api.qfinr.com/api/user/portfolio/updatePortfolio',
  
CURLOPT_RETURNTRANSFER => true,
  
CURLOPT_ENCODING => '',
  
CURLOPT_MAXREDIRS => 10,
  
CURLOPT_TIMEOUT => 0,
  
CURLOPT_FOLLOWLOCATION => true,
  
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  
CURLOPT_CUSTOMREQUEST => 'POST',
  
CURLOPT_POSTFIELDS => 'portfolio_name={{portfolio_name}}&transactions={{transactions_json}}',
  
CURLOPT_USERPWD => ($username ":" $password),
  
CURLOPT_HTTPHEADER => array(
    
'Content-Type: application/x-www-form-urlencoded',
  ),
));

$response curl_exec($curl);

curl_close($curl);
echo 
$response;
1
import requests
from base64 import b64encode
url = "https://api.qfinr.com/api/user//portfolio/updatePortfolio"

payload='portfolio_name={{portfolio_name}}&transactions={{transactions_json}}'
userAndPass = b64encode(b"username:password").decode("ascii")
headers = { 'Authorization': 'Basic %s' % userAndPass, 'Content-Type': 'application/x-www-form-urlencoded'}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
1

Delete Portfolio

  • The delete request deletes a specific portfolio_id. Once deleted, the user will not be able to recover the portfolio.

REQUEST BODY SCHEMA:

portfolio_id
String
Required
RESPONSE BODY SCHEMA:

status
Boolean
response_code
String
response
String
RESPONSE CODES
s01
Success
err01
Error message
err02
Unable to delete portfolio
a-err01
Authentication Error
Post /user/portfolio/delete

Default server

https://api.qfinr.com/api/user/portfolio/delete

Request Samples

php
python
<?php

$curl 
curl_init();

curl_setopt_array($curl, array(
  
CURLOPT_URL => 'https://api.qfinr.com/api/user/portfolio/delete',
  
CURLOPT_RETURNTRANSFER => true,
  
CURLOPT_ENCODING => '',
  
CURLOPT_MAXREDIRS => 10,
  
CURLOPT_TIMEOUT => 0,
  
CURLOPT_FOLLOWLOCATION => true,
  
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  
CURLOPT_CUSTOMREQUEST => 'POST',
  
CURLOPT_POSTFIELDS => 'portfolio_id={{portfolio_id}}',
  
CURLOPT_USERPWD => ($username ":" $password),
));

$response curl_exec($curl);

curl_close($curl);
echo 
$response;
1
import requests
from base64 import b64encode
url = "https://api.qfinr.com/api/user//portfolio/delete"

payload='portfolio_id={{portfolio_id}}'
userAndPass = b64encode(b"username:password").decode("ascii")
headers = { 'Authorization': 'Basic %s' % userAndPass, 'Content-Type': 'application/x-www-form-urlencoded'}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
1