internal double GetImpliedXChangeRate(CurrencyPair cp) { if (cp.IsIdentity) { return(1.0); } if (Total.Ccy != cp.Ccy2) { throw new NotImplementedException(); } AllocationElement ae = GetElement(cp.Ccy1); if (ae.Price.Amount == 0) { return(0); } double rate = Total.Amount * ae.Share / ae.Price.Amount; return(rate); }
public Allocation(Currency ccyRef, List <AllocationElement> data = null, AllocationElement fees = null) { CcyRef = ccyRef; if (data == null) { Data = new List <AllocationElement>(); } else { Data = data; } if (fees == null) { Fees = new AllocationElement(0, Currency.None); } else { Fees = fees; } Total = new Price(0, Currency.None); }
public void CancelFee() { Fees = new AllocationElement(0, Currency.None); }
public Allocation AddTransaction(Transaction tx)//, FXMarket fxMarket) { Allocation res = (Allocation)Clone(); res.CancelFee(); //// Changing the Amounts // Received if ((tx.Type == TransactionType.Deposit && tx.Received.Ccy.IsFiat()) || tx.Type == TransactionType.Trade || tx.Type == TransactionType.Transfer) { AllocationElement RecElement = res.GetElement(tx.Received.Ccy); if (RecElement != null) { //AllocationElement allocIn = res.Dictionary[tx.Received.Ccy]; RecElement.Price.Amount += tx.Received.Amount; } else { res.Data.Add(new AllocationElement(tx.Received.Amount, tx.Received.Ccy)); } } if (tx.Type == TransactionType.Deposit && !tx.Received.Ccy.IsFiat()) { //Console.WriteLine(""); } //TODO: Find Transaction fees if (tx.Type == TransactionType.WithDrawal && tx.Paid.Ccy.IsFiat()) { AllocationElement PaidElmt = res.GetElement(tx.Paid.Ccy); if (PaidElmt != null) { PaidElmt.Price.Amount -= tx.Paid.Amount; } else { throw new Exception("Paid in unavailable currency"); } if (PaidElmt.Price.Amount < 0) { throw new Exception("Paid more than available"); } } // Paid if (tx.Type == TransactionType.Trade && tx.Paid.Ccy != Currency.None) { AllocationElement PaidElement = res.GetElement(tx.Paid.Ccy); if (PaidElement != null) { //AllocationElement alloc = res.Dictionary[tx.Paid.Ccy]; PaidElement.Price.Amount -= tx.Paid.Amount; } else { throw new Exception("Paid in unavailable currency"); } if (PaidElement.Price.Amount < 0) { throw new Exception("Paid more than available"); } } // Fees if (!tx.Fees.IsNull) { AllocationElement FeesElement = res.GetElement(tx.Fees.Ccy); if (FeesElement != null) { //AllocationElement fAlloc = res.Dictionary[tx.Fees.Ccy]; FeesElement.Price.Amount -= tx.Fees.Amount; if (FeesElement.Price.Amount < 0) { throw new Exception("Paid more than available (fees)"); } res.Fees = new AllocationElement(tx.Fees.Amount, tx.Fees.Ccy); } else { throw new Exception("Paid in unavailable currency (fees)"); } } else { res.Fees = new AllocationElement(0, Currency.None); } //res.Update(fxMarket); return(res); }