Summary
The ExecuteOrder service is missing validation for:
- Canceling buy orders when user has insufficient funds
- Canceling sell orders when user has insufficient shares
What's Needed
-
Add validation logic to ExecuteOrder service to check:
- For buy orders: user has enough cash balance to cover the purchase
- For sell orders: user owns enough shares to sell
-
Cancel orders that fail validation instead of executing them
-
Add tests in test/services/execute_order_test.rb for:
- Buy order with insufficient funds → order should be canceled
- Sell order with insufficient shares → order should be canceled