Skip to content

Commit

Permalink
Fix for alpaca order fees (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero authored Jul 22, 2024
1 parent af84d37 commit 077b6ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions QuantConnect.AlpacaBrokerage.Tests/AlpacaBrokerageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public partial class AlpacaBrokerageTests : BrokerageTests
protected override Symbol Symbol { get; } = Symbols.AAPL;
protected override SecurityType SecurityType { get; }

protected override BrokerageName BrokerageName => BrokerageName.Alpaca;

protected override IBrokerage CreateBrokerage(IOrderProvider orderProvider, ISecurityProvider securityProvider)
{
var (apiKey, apiKeySecret, isPaperTrading, accessToken) = AlpacaBrokerageTestHelpers.GetConfigParameters();
Expand Down
10 changes: 8 additions & 2 deletions QuantConnect.AlpacaBrokerage/AlpacaBrokerage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,14 @@ private void HandleTradeUpdate(ITradeUpdate obj)
_orderIdToFillQuantity.TryRemove(leanOrder.Id, out _);
}

var orderEvent = new OrderEvent(leanOrder, obj.TimestampUtc.HasValue ? obj.TimestampUtc.Value : DateTime.UtcNow,
new OrderFee(new CashAmount(0, Currencies.USD)))
var fee = new OrderFee(new CashAmount(0, Currencies.USD));
if (newLeanOrderStatus == Orders.OrderStatus.Filled)
{
var security = _securityProvider.GetSecurity(leanOrder.Symbol);
fee = security.FeeModel.GetOrderFee(new OrderFeeParameters(security, leanOrder));
}

var orderEvent = new OrderEvent(leanOrder, obj.TimestampUtc.HasValue ? obj.TimestampUtc.Value : DateTime.UtcNow, fee)
{
Status = newLeanOrderStatus,
FillPrice = obj.Price ?? 0m,
Expand Down

0 comments on commit 077b6ee

Please sign in to comment.