public Transaction(long orderId, Instrument instrument, Position position, TypeTransaction typeTransaction, DateTime dateOpen, string info) { DateOpen = dateOpen; OrderId = orderId; Instrument = instrument ?? throw new DomainException("Instrument cannot be null."); Position = position ?? throw new DomainException("Instrument cannot be null.");; TypeTransaction = typeTransaction ?? throw new DomainException("Instrument cannot be null.");; Info = info; }
public decimal ComputeProfitInPips(double closePrice) { if (closePrice <= 0) { return(0); } var openPriceToPrecision = Position.OpenPrice * Math.Pow(10, Instrument.Precision); var closePriceToPrecision = closePrice * Math.Pow(10, Instrument.Precision); var profitInPips = TypeTransaction.Equals(TypeTransaction.Buy) ? ((closePriceToPrecision - openPriceToPrecision) / 10) : (TypeTransaction.Equals(TypeTransaction.Sell) ? ((openPriceToPrecision - closePriceToPrecision) / 10) : throw new DomainException("Transaction type is not set.")); //change it to domain return(Math.Round((decimal)profitInPips, 2)); }
public void AddTransaction(long orderId, Instrument instrument, double openPrice, double?stopLoss, double?takeProfit, decimal volumen, TypeTransaction typeTransaction, DateTime dateOpen, string info) { var position = new Position(openPrice, volumen); if (orderId <= 0) { orderId = GetMaxOrderId(); } var transaction = new Transaction(orderId, instrument, position, typeTransaction, dateOpen, info); if (stopLoss != null && stopLoss > 0) { transaction.Position.SetStopLoss(stopLoss ?? 0); } if (takeProfit != null && takeProfit > 0) { transaction.Position.SetTakeProfit(takeProfit ?? 0); } Transactions.Add(transaction); AddDomainEvent(new AccountAddedNewTransactionDomainEvent(transaction, this)); }