Implement SELL flow for crypto-trading test app with comprehensive tests and fix BigDecimal serialization#207
Conversation
Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
| public record PlaceSellOrderCommand( | ||
| @NotNull @AggregateIdentifier String userId, | ||
| @NotNull CryptoMarket market, | ||
| @NotNull BigDecimal amount, |
There was a problem hiding this comment.
this parameter should be named quantity. This change should be reflected in all classes
There was a problem hiding this comment.
Updated all SELL flow classes to use quantity instead of amount. Also updated the OrderProcess interface and BuyOrderProcess to maintain consistency. Changes applied in commit e585487.
… interface Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Change request implemented. Renamed the |
| public BuyOrderProcess(String orderId, | ||
| CryptoMarket market, | ||
| BigDecimal amount, | ||
| BigDecimal quantity, |
There was a problem hiding this comment.
BuyOrderProcess should not be changed, here we should keep using amount. A Buy order is always specified in the monetary value while a Sell order is always specified in the quantity
There was a problem hiding this comment.
Reverted BuyOrderProcess to use amount field for monetary value. SellOrderProcess now uses size field to store quantity and implements amount() method to return size. Changes in commit 245527c.
| @Override | ||
| public OrderProcess withState(OrderProcessState state) { | ||
| return new BuyOrderProcess(orderId(), market, size(), amount(), clientReference(), state); | ||
| return new BuyOrderProcess(orderId(), market, size(), quantity(), clientReference(), state); |
There was a problem hiding this comment.
Fixed in commit 245527c - withState() now uses amount() as before.
| BigDecimal size(); | ||
|
|
||
| BigDecimal amount(); | ||
| BigDecimal quantity(); |
There was a problem hiding this comment.
keep using amount. For the Sell order process use size (which is identical to quantity)
There was a problem hiding this comment.
Reverted to amount() method. SellOrderProcess implements this by returning size field. Changes in commit 245527c.
…ize' implementing amount() Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
| public record SellOrderProcess( | ||
| String orderId, | ||
| CryptoMarket market, | ||
| BigDecimal size, |
There was a problem hiding this comment.
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.
Added amount field to SellOrderProcess record. Constructor now sets size to quantity and amount to null, matching BuyOrderProcess structure. Changes in commit 98bab9f.
Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
|
@copilot the code looks good, now also add tests for the sell order flow in the various modules. Also add a E2E sell order flow test, even though you cannot run it yourself |
Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Added comprehensive tests for SELL order flow in commit a8588f2: Queries Module (
Commands Module (
Aggregates Module (
E2E Tests (
All tests follow the same patterns as existing BUY order tests and compile successfully. |
Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
| .jsonPath("$.openSellOrders.length()").isEqualTo(2) | ||
| .jsonPath("$.openSellOrders[0].orderId").exists() | ||
| .jsonPath("$.openSellOrders[0].market.id").isEqualTo("BTC-EUR") | ||
| .jsonPath("$.openSellOrders[0].quantity").isEqualTo(0.5) |
There was a problem hiding this comment.
the quantity should be a String ("0.5") and not a double. using doubles is dangerous in financial applications. Change to String and fix any code that fails due to this test
There was a problem hiding this comment.
Fixed in commit 42539d6. All BigDecimal fields in DTOs now serialize as Strings using @JsonSerialize(using = ToStringSerializer.class). Updated all tests to expect String values instead of doubles (e.g., "0.5" instead of 0.5).
Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Implemented in commit 42539d6. Added
All tests updated to compare String representations, ensuring financial precision is maintained. |
|
|
||
| public record BalanceOutput(String id, | ||
| String currency, | ||
| @JsonSerialize(using = ToStringSerializer.class) |
There was a problem hiding this comment.
use org.elasticsoftware.akces.serialization.BigDecimalSerializer
There was a problem hiding this comment.
Updated in commit be5ccb2. Replaced ToStringSerializer with org.elasticsoftware.akces.serialization.BigDecimalSerializer across all DTOs and query model states (BalanceOutput, OrderOutput, OrdersQueryModelState, WalletQueryModelState).
Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Implementation Plan: SELL Flow for Crypto Trading
Analysis Complete
Components Created
Aggregates Module
PlaceSellOrderCommand(command) - ✅ UsesquantityparameterFillSellOrderCommand(command)SellOrderCreatedEvent(event) - ✅ UsesquantityfieldSellOrderPlacedEvent(event) - ✅ UsesquantityfieldSellOrderFilledEvent(event)SellOrderRejectedEvent(event)SellOrderProcess(process manager) - ✅ Has bothsizeandamountfieldsOrderProcessinterface - ✅ Keepsamount()methodOrderProcessManagerto handle SELL flowBuyOrderProcesswithamountfieldCommands Module
SellOrderInputDTO - ✅ UsesquantityfieldOrdersCommandControllerto add/sellendpointQueries Module
OrdersQueryModelStateto include SellOrder recordOrdersQueryModelto handle SELL eventsOrdersQueryControllerto query both buy and sell ordersTesting & Validation
API Changes - BigDecimal Serialization
Problem: Using doubles for financial values is dangerous due to floating-point precision issues.
Solution: Use framework's
org.elasticsoftware.akces.serialization.BigDecimalSerializerinstead of Jackson'sToStringSerializer:Files Updated:
BalanceOutput- amount, balance fieldsOrderOutput- size, amount fieldsOrdersQueryModelState.BuyOrder- amount fieldOrdersQueryModelState.SellOrder- quantity fieldWalletQueryModelState.Balance- amount, reservedAmount fieldsBenefits:
toPlainString()for exact decimal representationOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.