Anlagestrategie ändern
So folgen Sie diesem Kapitel
Eingaben: Ein bestehendes, für die Änderung zulässiges Portfolio, sein aktueller Zustand und der neu gewählte Vorschlag.
Schritte und erwartetes Ergebnis: Wählen Sie den Vorschlag und bereiten Sie den Vertrag vor. Bewahren Sie die Änderungsauftrags-ID auf und verfolgen Sie den Auftrag wie im Kapitel Portfolio eröffnen beschrieben.
Alternativen und spätere Aktionen: Prüfen Sie HasPendingOrder und das API-Ergebnis, bevor Sie eine weitere Änderung zulassen. Die API entscheidet verbindlich über die Zulässigkeit.
DTO-Quellcode: PortfolioOrderOutputModel, PortfolioOutputModel, ProposalOutputModel, ReasonToChangeProposalOutputModel
In früheren Codeblöcken zugewiesene Variablen werden später wiederverwendet. Kundeneingaben stammen aus Ihrer Oberfläche. Bewahren Sie IDs und Referenzwerte im Kontext des jeweiligen Kunden auf; legen Sie nicht für jeden Schritt einen neuen Kontext an.
Wichtig
Anlagevorschlag auswählen
Aktion: Ermitteln Sie den zulässigen Vorschlag für die gewünschte Änderung.
Aufbewahren / erwartetes Ergebnis: Bewahren Sie selectedProposalId und die erforderlichen Abweichungsgründe auf.
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var clientPortfolio = await httpClient.GetFromJsonAsync<PortfolioOutputModel>($"api/v1/user-portfolios/portfolio-id/{portfolioId}?portfolio-view-as=Snapshot");
var url = $"api/v1/proposals/investment-category-id/{clientPortfolio.InvestmentCategoryId}";
var proposals = await httpClient.GetFromJsonAsync<List<ProposalOutputModel>>(url);
var alternativeProposals = proposals.Where(x => x.Id != clientPortfolio.ProposalId).ToList();
HttpRequest portfolioRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("user-portfolios/portfolio-id/" + portfolioId + "?portfolio-view-as=Snapshot"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + accessToken)
.header("Content-Type", "application/json")
.build();
var response = httpClient.send(portfolioRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
PortfolioOutputModel clientPortfolio = new Gson().fromJson(response.body(), PortfolioOutputModel.class);
// Alternative proposals list
HttpRequest proposalsRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("proposals/investment-category-id/" + clientPortfolio.InvestmentCategoryId))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + accessToken)
.header("Content-Type", "application/json")
.build();
response = httpClient.send(proposalsRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
Type listType = new TypeToken<ArrayList<ProposalOutputModel>>(){}.getType();
List<ProposalOutputModel> proposalObjs = new Gson().fromJson(response.body(), listType);
var alternativeProposals = proposalObjs.stream().filter(x -> x.Id != clientPortfolio.ProposalId).toList();
// selectedProposalId is chosen by the client from alternativeProposals.
Vertrag vorbereiten
Aktion: Bereiten Sie den Vertrag für den Strategiewechsel vor.
Aufbewahren / erwartetes Ergebnis: Bewahren Sie die PDF-Bytes oder contractPath wie im Kapitel Portfolio eröffnen auf.
Auftrag senden
Aktion: Senden Sie den Änderungsauftrag.
Aufbewahren / erwartetes Ergebnis: Bewahren Sie modificationOrderId auf und verfolgen Sie den Auftrag, bevor Sie die Änderung als abgeschlossen behandeln.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Please note:
// Provide the completed contract required for this modification.
// The client chooses selectedProposalId and selectedReasonIds.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var currentPortfolio = await httpClient.GetFromJsonAsync<PortfolioOutputModel>($"api/v1/user-portfolios/portfolio-id/{portfolioId}?portfolio-view-as=Snapshot");
if (currentPortfolio.HasPendingOrder)
{
throw new InvalidOperationException("A portfolio order is pending");
}
var reasonToChangeProposalUrl = $"api/v1/reason-to-change-proposed-proposal/investment-category-id/{currentPortfolio.InvestmentCategoryId}/active";
var reasonToChangeProposal = await httpClient.GetFromJsonAsync<ReasonToChangeProposalOutputModel>(reasonToChangeProposalUrl);
var orderPortfolioModificationInputModel = new
{
PortfolioId = portfolioId,
// Assume this is the new portfolio model selected by client
ProposalId = selectedProposalId,
// Assume this is reason to change proposal selected by client
ReasonToChangeProposalResponsesIds = selectedReasonIds
};
// contractPath points to the completed contract for this modification.
var byteArray = await File.ReadAllBytesAsync(contractPath);
using var httpContent = GuideHttp.CreateMultipartContent(orderPortfolioModificationInputModel, byteArray);
var httpResponseMessage = await httpClient.PostAsync("api/v1/user-portfolio-orders/modification", httpContent);
httpResponseMessage.EnsureSuccessStatusCode();
var modificationOrder = JsonConvert.DeserializeObject<PortfolioOrderOutputModel>(await httpResponseMessage.Content.ReadAsStringAsync());
var modificationOrderId = modificationOrder.Id;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Please note:
// Provide the completed contract required for this modification.
// The client chooses selectedProposalId and selectedReasonIds.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HttpRequest reasonToChangeRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("reason-to-change-proposed-proposal/investment-category-id/" + clientPortfolio.InvestmentCategoryId + "/active"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + accessToken)
.header("Content-Type", "application/json")
.build();
response = httpClient.send(reasonToChangeRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
ReasonToChangeProposalOutputModel reasonToChangeProposalObj = new Gson().fromJson(response.body(), ReasonToChangeProposalOutputModel.class);
// selectedReasonIds contains the reasons selected by the client.
JsonObject orderPortfolioModificationInputModel = new JsonObject();
orderPortfolioModificationInputModel.addProperty("PortfolioId", portfolioId);
orderPortfolioModificationInputModel.addProperty("ProposalId", selectedProposalId);
orderPortfolioModificationInputModel.add("ReasonToChangeProposalResponsesIds", new Gson().toJsonTree(selectedReasonIds));
// contractPath points to the completed contract for this modification.
var contractBytes = Files.readAllBytes(contractPath);
MultiPartBodyPublisher multipartBody = new MultiPartBodyPublisher()
.addPart("jsonPayload", orderPortfolioModificationInputModel.toString())
.addPart("userContracts", () -> new ByteArrayInputStream(contractBytes), "Contract.pdf", "application/pdf");
HttpRequest planChangeRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("user-portfolio-orders/modification"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + accessToken)
.header("Content-Type", "multipart/form-data; boundary=" + multipartBody.getBoundary())
.POST(multipartBody.build())
.build();
response = httpClient.send(planChangeRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
PortfolioOrderOutputModel modificationOrder = new Gson().fromJson(response.body(), PortfolioOrderOutputModel.class);
var modificationOrderId = modificationOrder.Id;
Ergebnis erkennen
Illustrativer Ausschnitt einer Änderungsauftragsantwort. Bewahren Sie die neue Auftrags-ID auf. HTTP-Erfolg bedeutet noch nicht, dass der Strategiewechsel abgeschlossen ist.
{"id":457,"portfolioId":789,"orderStatusId":1}Weitere Antwortfelder finden Sie im DTO-Katalog. Behandeln Sie fehlgeschlagene Anfragen, bevor Sie fortfahren; siehe Fehlerbehandlung.