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}");


								
		// Assuming this is our client ID
		var clientId = 226;
		  
		HttpRequest portfolioRequest = HttpRequest.newBuilder()
			.timeout(Duration.ofMinutes(1))
			.uri(URI.create(Settings.BASE_URL + "user-portfolios/user-id/" + clientId))
			.header("Accept-Language", "de-DE")
			.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN)
			.header("Content-Type", "application/json")
			.build();
			
		var response = httpClient.send(portfolioRequest, BodyHandlers.ofString());
			
		Type listType = new TypeToken<ArrayList<PortfolioOutputModel>>(){}.getType();
		List<PortfolioOutputModel> portfolioObjs = new Gson().fromJson(response.body().toString(), listType);


Portfolio by Id

We will now retrieve information about the portfolio's performance.


  // Assuming this is the portfolio ID
  var portfolioId = 165;

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


								
		// Assuming this is the portfolio ID
		var portfolioId = 165;
		
		HttpRequest portfolioRequest = HttpRequest.newBuilder()
			.timeout(Duration.ofMinutes(1))
			.uri(URI.create(Settings.BASE_URL + "user-portfolios/portfolio-id/" + portfolioId + "?portfolio-view-as=Snapshot"))
			.header("Accept-Language", "de-DE")
			.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN)
			.header("Content-Type", "application/json")
			.build();
				
		response = httpClient.send(portfolioRequest, BodyHandlers.ofString());
		PortfolioOutputModel portfolioObj = new Gson().fromJson(response.body().toString(), PortfolioOutputModel.class);


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");


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

		HttpRequest portfolioPerformanceRequest = HttpRequest.newBuilder()
			.timeout(Duration.ofMinutes(1))
			.uri(URI.create(Settings.BASE_URL + "user-portfolios/portfolio-id/" + portfolioId + "/performances"))
			.header("Accept-Language", "de-DE")
			.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN)
			.header("Content-Type", "application/json")
			.build();
		
		response = httpClient.send(portfolioPerformanceRequest, BodyHandlers.ofString());
		PortfolioValuesOutputModel portfolioPerformanceObj = new Gson().fromJson(response.body().toString(), PortfolioValuesOutputModel.class);		


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);


								
		// Portfolio cash amount
		
		HttpRequest bankAccountTypesRequest = HttpRequest.newBuilder()
				.timeout(Duration.ofMinutes(1))
				.uri(URI.create(Settings.BASE_URL + "cash-account-types"))
				.header("Accept-Language", "de-DE")
				.header("Authorization", "Bearer " + Settings.GUEST_TOKEN)
				.header("Content-Type", "application/json")
				.build();
		
		// Get bank account types: Cash account/Custody account
		response = httpClient.send(bankAccountTypesRequest, BodyHandlers.ofString());
		Type listBankAccountTypes = new TypeToken<ArrayList<BankAccountTypeOutputModel>>(){}.getType();
		List<BankAccountTypeOutputModel> bankAccountTypes = new Gson().fromJson(response.body().toString(), listBankAccountTypes);
		var bankAccountType = bankAccountTypes.stream().filter(x -> x.Code == "CASH-ACCOUNT").findFirst().get();

		// Get portfolio's bank accounts
		HttpRequest portfolioBankAccountRequest = HttpRequest.newBuilder()
				.timeout(Duration.ofMinutes(1))
				.uri(URI.create(Settings.BASE_URL + "user-cash-accounts/portfolio-id/" + portfolioId))
				.header("Accept-Language", "de-DE")
				.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN)
				.header("Content-Type", "application/json")
				.build();

		response = httpClient.send(portfolioBankAccountRequest, BodyHandlers.ofString());
		Type cashAccountType = new TypeToken<ArrayList<CashAccountOutputModel>>(){}.getType();
		List<CashAccountOutputModel> cashAccountObjs = new Gson().fromJson(response.body().toString(), cashAccountType);
		CashAccountOutputModel cashAccountObj = cashAccountObjs.stream().filter(x -> x.AccountTypeId == bankAccountType.Id).findFirst().get();


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");
  
									
		HttpRequest cashAccountMovementsRequest = HttpRequest.newBuilder()
				.timeout(Duration.ofMinutes(1))
				.uri(URI.create(Settings.BASE_URL + "user-cash-accounts/cash-account-id/" + cashAccountObj.Id + "/movements"))
				.header("Accept-Language", "de-DE")
				.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN)
				.header("Content-Type", "application/json")
				.build();
		
		response = httpClient.send(cashAccountMovementsRequest, BodyHandlers.ofString());
		Type cashAccountMovementType = new TypeToken<ArrayList<CashAccountMovementOutputModel>>(){}.getType();
		List<CashAccountMovementOutputModel> cashAccountMovementObjs = new Gson().fromJson(response.body().toString(), cashAccountMovementType);
		

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;
	...
  }
  

	
									
		HttpRequest bookingCodeRequest = HttpRequest.newBuilder()
				.timeout(Duration.ofMinutes(1))
				.uri(URI.create(Settings.BASE_URL + "booking-codes"))
				.header("Accept-Language", "de-DE")
				.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN)
				.header("Content-Type", "application/json")
				.build();
		
		response = httpClient.send(bookingCodeRequest, BodyHandlers.ofString());
		Type bookingCodeTypes = new TypeToken<ArrayList<BookingCodeOutputModel>>(){}.getType();
		List<BookingCodeOutputModel> bookingCodeTypeObjs = new Gson().fromJson(response.body().toString(), bookingCodeTypes);

		cashAccountMovementObjs.forEach(bankAccountMovement -> {
			BookingCodeOutputModel bookingCodeTypeObj = bookingCodeTypeObjs.stream().filter(x -> x.Id == bankAccountMovement.BookingCodeId).findFirst().orElse(null);

			var bookingCode = bookingCodeTypeObj.Code;
			var bookingCodeDescription = bookingCodeTypeObj.Description;
			...
		});


Portfolio bank documents

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


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


								
		// User bank documents
		HttpRequest userDocumentsMetadataRequest = HttpRequest.newBuilder()
				.timeout(Duration.ofMinutes(1))
				.uri(URI.create(Settings.BASE_WMS_URL + "user-bank-documents/user-id/" + clientId + "/list?starting-from=20000101"))
				.header("Accept-Language", "de-DE")
				.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN)
				.header("Content-Type", "application/json")
				.build();
		
		response = httpClient.send(userDocumentsMetadataRequest, BodyHandlers.ofString());
		Type userBankDocumentInfoType = new TypeToken<ArrayList<UserBankDocumentInfoOutputModel>>(){}.getType();
		List<UserBankDocumentInfoOutputModel> userDocumentsMetadataObjs = new Gson().fromJson(response.body().toString(), userBankDocumentInfoType);	


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 = "2020061713284100000051110100000009";

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


												
		// Assuming this is the document reference selected by the user to download it
		var reference = "2020061713284100000051110100000009";
		
		HttpRequest downloadfRequest = HttpRequest.newBuilder()
				.timeout(Duration.ofMinutes(1))
				.uri(URI.create(Settings.BASE_WMS_URL + "user-bank-documents/user-id/" + clientId + "/portfolio-id/" + portfolioId + "/download-bank-document/reference/" + reference))
				.header("Accept-Language", "de-DE")
				.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN)
				.header("Content-Type", "application/json")
				.build();
		
		HttpResponse<byte[]> byteArrayResponse = httpClient.send(downloadfRequest, BodyHandlers.ofByteArray());		
		// Files.write(Paths.get("C:\\Temp\\BankDocument.pdf"), byteArrayResponse.body());


Below is an example of a bank document: