private void AddAllocationToHistory(Allocation alloc, FXMarket fx)
        {
            Allocation newAlloc = (Allocation)alloc.Clone();

            newAlloc.CancelFee();
            newAlloc.Update(fx);
            if (History.ContainsKey(fx.Date))
            {
                History[fx.Date] = newAlloc;
            }
            else
            {
                History.Add(fx.Date, newAlloc);
            }
        }
Example #2
0
        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);
        }