Client Portfolio Position

In this section we will look at how to retrieve the client's portfolio position.

Portfolios list

For this operation, the call must have the authorization HTTP header set with the token with CLIENT or ADMIN role.

  
  // Assuming this is our client ID
  var clientId = 226;

  var clientPortfolios = await httpClient.GetFromJsonAsync<IList<PortfolioOutputModel>>($"api/v1/user-portfolios/user-id/{clientId}");		

Portfolio details

We will now retrieve information about the portfolio, such as its composition, market value, and performance.


  // Assuming this is the portfolio ID we want to display
  var portfolioId = 165;

  var clientPortfolio = await httpClient.GetFromJsonAsync<PortfolioOutputModel>($"api/v1/user-portfolios/portfolio-id/{portfolioId}?portfolio-view-as=Snapshot");
  var portfolioPerformances = await httpClient.GetFromJsonAsync<PortfolioValuesOutputModel>($"api/v1/user-portfolios/portfolio-id/{portfolioId}/performances");

With the information received above, we can create a first portfolio view:

Portfolio values

Historical portfolio performance, market values, total assets, profit and loss, and cash amounts can be retrieved using the performance API endpoint. This allows you to get multiple values in one call, with the ability to create multiple charts.

Performances
Market values


  // Assuming this is the portfolio ID we want to display
  var portfolioId = 165;

  var portfolioValues = await httpClient.GetFromJsonAsync<PortfolioValuesOutputModel>($"api/v1/user-portfolios/portfolio-id/{portfolioId}/performances");

Portfolio cash amount

Each plan has its own IBAN number. This IBAN corresponds to the cash account used by the client to make payments, for example, the annual payment for plan 3A. After a payment, if the money has not yet been invested, it will be displayed in the cash account. The following code snippet shows how to retrieve the balance in the reserved cash account:


  // Get bank account types: Cash account/Custody account
  var bankAccountTypes = await httpClient.GetFromJsonAsync<List<BankAccountTypeOutputModel>>($"api/v1/cash-account-types");
  var casAccountType = bankAccountTypes.First(x => x.Code == "CASH-ACCOUNT");

  // Get portfolio's bank accounts
  var bankAccounts = await httpClient.GetFromJsonAsync<List<CashAccountOutputModel>>($"api/v1/user-cash-accounts/portfolio-id/{portfolioId}");
  var cashAccount = bankAccounts.First(x => x.AccountTypeId == casAccountType.Id);

The "CashAccountOutputModel" payload contains the IBAN number, accounting date and cash amount.

In addition, the cash account provides a list of movements. For example, any buy/sell transaction made on the client's portfolio is recorded as a cash movement. The following code snippet shows how to retrieve cash account movements:

									 
  var bankAccountMovements = await httpClient.GetFromJsonAsync<List<CashAccountMovementOutputModel>>($"api/v1/user-cash-accounts/cash-account-id/{cashAccount.Id}/movements");
	

Note that the payload of "CashAccountMovementOutputModel" has a property called "BookingCodeId" that can be decoded to retrieve the description of the movement type:

									   
  foreach (var bankAccountMovement in bankAccountMovements)
  {
	var bookingCode = await httpClient.GetFromJsonAsync<BookingCodeOutputModel>($"api/v1/booking-codes/id/{bankAccountMovement.BookingCodeId}");

	var bookingCode = bookingCode.Code,
	var bookingCodeDescription = bookingCode.Description
	...
  }
	

Portfolio bank documents

PDF documents issued/provided by the Bank are available for download by the client.


  var url = $"api/v1/user-bank-documents/user-id/{clientId}/list?starting-from=20000101";
  var bankDocumentsForAllPortfolios = await httpClient.GetFromJsonAsync<IList<UserBankDocumentInfoOutputModel>>(url);

  var bankDocumentTypes = await httpClient.GetFromJsonAsync<IList<BankDocumentTypeOutputModel>>("api/v1/bank-document-types");

The bank document metadata, together with creation date and document description, contains the document Reference used to download the PDF.

 
  // Assuming this is the document reference selected by the user
  var reference = "2023112504255700000089500100000001";

  var url = $"api/v1/user-bank-documents/user-id/{clientId}/portfolio-id/{portfolioId}/download-bank-document/reference/{reference}";
  var byteArray = await httpClient.GetByteArrayAsync(url);

Below is an example of a bank document: