public Order(BinanceOrder order) { this.Uuid = order.orderId.ToString(); this.Exchange = "Binance"; this.Symbol = order.symbol; this.Quantity = order.origQty; this.QuantityFilled = order.executedQty; this.CostProceeds = order.executedQty * order.price - ((order.executedQty * order.price) * 0.001m); this.AvgRate = order.price; this.Fees = 0m; this.Side = order.side.ToLowerInvariant(); this.IsFilled = order.status == "FILLED"; this.IsClosed = order.status == "FILLED" || order.status == "CANCELED" || order.status == "REJECTED" || order.status == "EXPIRED"; }
public Order(BinanceOrder order, IEnumerable <BinanceTrade> trades, ITicker bnbTicker) { if (!trades.Any()) { throw new Exception("NO TRADES REMOVE ME MAYBE"); } this.Uuid = order.orderId.ToString(); this.Exchange = "Binance"; this.Symbol = order.symbol; this.Quantity = order.origQty; this.QuantityFilled = order.executedQty; this.CostProceeds = order.executedQty * order.price; this.AvgRate = order.price; this.Fees = 0m; this.Side = order.side.ToLowerInvariant(); if (trades.Any()) { this.Quantity = trades.Sum(t => t.qty); this.AvgRate = trades.Average(t => t.price); this.Fees = trades.Sum(t => t.commission); if (trades.FirstOrDefault().commissionAsset == "BNB") { this.Fees *= bnbTicker.Last; } else if (trades.FirstOrDefault().commissionAsset != "BTC" && trades.FirstOrDefault().commissionAsset != "ETH") { this.Fees *= this.AvgRate; } decimal rawCost = this.QuantityFilled * this.AvgRate; if (this.Side == OrderSide.Buy) { this.CostProceeds = rawCost + Fees; } else { this.CostProceeds = rawCost - Fees; } } this.IsFilled = order.status == "FILLED"; this.IsClosed = order.status == "FILLED" || order.status == "CANCELED" || order.status == "REJECTED" || order.status == "EXPIRED"; }