Skip to content

Commit

Permalink
Feature: Validate FillPrice and FillQuantity in `class BrokerageT…
Browse files Browse the repository at this point in the history
…est` (#8483)

* test:feat: validate FillPrice and FillQuantity in Base Brokerage Test

* test:refactor: use Exception instead of Log
  • Loading branch information
Romazes authored Dec 26, 2024
1 parent eca4f5b commit 9175b86
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Tests/Brokerages/BrokerageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,25 @@ private void HandleFillEvents(object sender, List<OrderEvent> ordeEvents)
OrderFillEvent.Set();
}

var eventFillPrice = orderEvent.FillPrice;
var eventFillQuantity = orderEvent.FillQuantity;

Assert.Greater(eventFillPrice, 0m);

switch (orderEvent.Direction)
{
case OrderDirection.Buy:
Assert.Greater(eventFillQuantity, 0m);
break;
case OrderDirection.Sell:
Assert.Less(eventFillQuantity, 0m);
break;
default:
throw new ArgumentException($"{nameof(BrokerageTests)}.{nameof(HandleFillEvents)}: Not Recognize order Event Direction = {orderEvent.Direction}");
}

var holding = SecurityProvider.GetSecurity(orderEvent.Symbol).Holdings;
holding.SetHoldings(orderEvent.FillPrice, holding.Quantity + orderEvent.FillQuantity);
holding.SetHoldings(eventFillPrice, holding.Quantity + eventFillQuantity);

Log.Trace("--HOLDINGS: " + _securityProvider[orderEvent.Symbol].Holdings);

Expand Down

0 comments on commit 9175b86

Please sign in to comment.