-
Notifications
You must be signed in to change notification settings - Fork 0
Implement SELL flow for crypto-trading test app with comprehensive tests and fix BigDecimal serialization #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dc8d0fe
Initial plan
Copilot 5fbd77d
Add SELL flow: commands, events, process manager, DTOs, and query models
Copilot e585487
Rename 'amount' parameter to 'quantity' in SELL flow and OrderProcess…
Copilot 245527c
Revert BuyOrderProcess to use 'amount', keep SellOrderProcess with 's…
Copilot 98bab9f
Add 'amount' field to SellOrderProcess, set to null in constructor
Copilot 1fbdfde
Merge branch 'main' into copilot/add-sell-flow-logic
jwijgerd a8588f2
Add comprehensive tests for SELL order flow across all modules
Copilot 9e85604
Fix invalid UUID formats in test file
Copilot 42539d6
Serialize BigDecimal as String in API to avoid float precision issues
Copilot be5ccb2
Use framework's BigDecimalSerializer instead of ToStringSerializer
Copilot f886b87
refactor: streamline test initialization and enhance sell order flow …
jwijgerd ba7113d
Merge branch 'main' into copilot/add-sell-flow-logic
jwijgerd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...s/src/main/java/org/elasticsoftware/cryptotrading/aggregates/orders/SellOrderProcess.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright 2022 - 2025 The Original Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.elasticsoftware.cryptotrading.aggregates.orders; | ||
|
|
||
| import org.elasticsoftware.cryptotrading.aggregates.orders.commands.RejectOrderCommand; | ||
| import org.elasticsoftware.cryptotrading.aggregates.orders.data.CryptoMarket; | ||
| import org.elasticsoftware.cryptotrading.aggregates.orders.events.SellOrderRejectedEvent; | ||
| import org.elasticsoftware.cryptotrading.aggregates.wallet.events.InsufficientFundsErrorEvent; | ||
| import org.elasticsoftware.cryptotrading.aggregates.wallet.events.InvalidCryptoCurrencyErrorEvent; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public record SellOrderProcess( | ||
| String orderId, | ||
| CryptoMarket market, | ||
| BigDecimal size, | ||
| BigDecimal amount, | ||
| String clientReference, | ||
| OrderProcessState state | ||
| ) implements OrderProcess { | ||
| public SellOrderProcess(String orderId, | ||
| CryptoMarket market, | ||
| BigDecimal quantity, | ||
| String clientReference) { | ||
| this(orderId, market, quantity, null, clientReference, OrderProcessState.CREATED); | ||
| } | ||
|
|
||
| @Override | ||
| public String getProcessId() { | ||
| return orderId(); | ||
| } | ||
|
|
||
| @Override | ||
| public SellOrderRejectedEvent handle(InsufficientFundsErrorEvent error) { | ||
| return new SellOrderRejectedEvent(error.walletId(), orderId(), clientReference()); | ||
| } | ||
|
|
||
| @Override | ||
| public SellOrderRejectedEvent handle(InvalidCryptoCurrencyErrorEvent error) { | ||
| return new SellOrderRejectedEvent(error.walletId(), orderId(), clientReference()); | ||
| } | ||
|
|
||
| @Override | ||
| public SellOrderRejectedEvent handle(RejectOrderCommand command) { | ||
| return new SellOrderRejectedEvent(command.userId(), orderId(), clientReference()); | ||
| } | ||
|
|
||
| @Override | ||
| public OrderProcess withState(OrderProcessState state) { | ||
| return new SellOrderProcess(orderId(), market, size(), amount(), clientReference(), state); | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
...va/org/elasticsoftware/cryptotrading/aggregates/orders/commands/FillSellOrderCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright 2022 - 2025 The Original Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.elasticsoftware.cryptotrading.aggregates.orders.commands; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
| import org.elasticsoftware.akces.annotations.AggregateIdentifier; | ||
| import org.elasticsoftware.akces.annotations.CommandInfo; | ||
| import org.elasticsoftware.akces.commands.Command; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| @CommandInfo(type = "FillSellOrder", version = 1) | ||
| public record FillSellOrderCommand( | ||
| @NotNull @AggregateIdentifier String userId, | ||
| @NotNull String orderId, | ||
| @NotNull String counterpartyId, | ||
| @NotNull BigDecimal price, | ||
| @NotNull BigDecimal quantity, | ||
| @NotNull String baseCurrency, | ||
| @NotNull String quoteCurrency | ||
| ) implements Command { | ||
| @Override | ||
| public String getAggregateId() { | ||
| return userId(); | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
...a/org/elasticsoftware/cryptotrading/aggregates/orders/commands/PlaceSellOrderCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright 2022 - 2025 The Original Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.elasticsoftware.cryptotrading.aggregates.orders.commands; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
| import org.elasticsoftware.akces.annotations.AggregateIdentifier; | ||
| import org.elasticsoftware.akces.annotations.CommandInfo; | ||
| import org.elasticsoftware.akces.commands.Command; | ||
| import org.elasticsoftware.cryptotrading.aggregates.orders.data.CryptoMarket; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| @CommandInfo(type = "PlaceSellOrder", version = 1) | ||
| public record PlaceSellOrderCommand( | ||
| @NotNull @AggregateIdentifier String userId, | ||
| @NotNull CryptoMarket market, | ||
| @NotNull BigDecimal quantity, | ||
| @NotNull String clientReference | ||
| ) implements Command { | ||
| @Override | ||
| @NotNull | ||
| public String getAggregateId() { | ||
| return userId(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep size and amount properties like in the BuyOrderProcess but set the amount to null in the constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
amountfield to SellOrderProcess record. Constructor now setssizeto quantity andamountto null, matching BuyOrderProcess structure. Changes in commit 98bab9f.