public void ConvertsAccountCurrencyAsIdentity()
        {
            var converter  = new IdentityCurrencyConverter("ABC");
            var cashAmount = new CashAmount(1m, "ABC");

            Assert.AreEqual(cashAmount, converter.ConvertToAccountCurrency(cashAmount));
        }
예제 #2
0
        public void InitializesProperlyUsingAccountCurrency()
        {
            var cashAmount = new CashAmount(1000m, CashBook.AccountCurrency);

            Assert.AreEqual(1000m, cashAmount.Amount);
            Assert.AreEqual(CashBook.AccountCurrency, cashAmount.Currency);
        }
        public void ThrowsArgumentExceptionOnCashAmountNotInAccountCurrency()
        {
            var converter  = new IdentityCurrencyConverter(Currencies.USD);
            var cashAmount = new CashAmount(1m, "EUR");

            Assert.Throws <ArgumentException>(() => converter.ConvertToAccountCurrency(cashAmount));
        }
예제 #4
0
        public void InitializesProperlyUsingNonAccountCurrency()
        {
            var cashAmount = new CashAmount(1000m, "EUR");

            Assert.AreEqual(1000m, cashAmount.Amount);
            Assert.AreEqual("EUR", cashAmount.Currency);
        }
예제 #5
0
        public void RoundTripSerialization()
        {
            var cashAmount = new CashAmount(1000m, "EUR");

            var serialized  = JsonConvert.SerializeObject(cashAmount);
            var deserialize = JsonConvert.DeserializeObject <CashAmount>(serialized);

            Assert.AreEqual(cashAmount, deserialize);
        }
예제 #6
0
        private bool LoadCashBalance(LiveNodePacket liveJob, IBrokerage brokerage, IAlgorithm algorithm)
        {
            Log.Trace("BrokerageSetupHandler.Setup(): Fetching cash balance from brokerage...");
            try
            {
                // set the algorithm's cash balance for each currency
                var    cashBalance = brokerage.GetCashBalance();
                string maxCashLimitStr;
                if (liveJob.BrokerageData.TryGetValue("max-cash-limit", out maxCashLimitStr))
                {
                    var maxCashLimit = JsonConvert.DeserializeObject <HashSet <CashAmount> >(maxCashLimitStr);

                    brokerage.DisableCashSync();

                    Log.Trace("BrokerageSetupHandler.Setup(): will use job packet max cash limit. Disabled cash sync.");
                    foreach (var cash in maxCashLimit)
                    {
                        var brokerageCash = cashBalance.FirstOrDefault(
                            brokerageCashAmount => string.Equals(brokerageCashAmount.Currency, cash.Currency, StringComparison.InvariantCultureIgnoreCase));
                        // we use the min amount between the brokerage and the job packet, if any
                        if (brokerageCash != default(CashAmount))
                        {
                            Log.Trace($"BrokerageSetupHandler.Setup(): Job packet amount {cash.Currency} {cash.Amount}. Brokerage amount {brokerageCash.Amount}.");
                            var cashToUse = new CashAmount(Math.Min(cash.Amount, brokerageCash.Amount), cash.Currency);

                            algorithm.Debug($"Live deployment has been allocation limited to {cashToUse.Amount:C} {cashToUse.Currency}");

                            algorithm.Portfolio.SetCash(cashToUse.Currency, cashToUse.Amount, 0);
                        }
                        else
                        {
                            Log.Trace($"BrokerageSetupHandler.Setup(): Skip setting {cash.Currency} brokerage does not have it.");
                        }
                    }
                }
                else
                {
                    foreach (var cash in cashBalance)
                    {
                        Log.Trace($"BrokerageSetupHandler.Setup(): Setting {cash.Currency} cash to {cash.Amount}");

                        algorithm.Portfolio.SetCash(cash.Currency, cash.Amount, 0);
                    }
                }
            }
            catch (Exception err)
            {
                Log.Error(err);
                AddInitializationError("Error getting cash balance from brokerage: " + err.Message, err);
                return(false);
            }

            return(true);
        }
예제 #7
0
        public void InitializesProperlyUsingNonAccountCurrency()
        {
            var cashBook = new CashBook {
                { "EUR", new Cash("EUR", 0, 1.17m) }
            };
            var cashAmount = new CashAmount(1000m, "EUR", cashBook);

            Assert.AreEqual(1000m, cashAmount.Amount);
            Assert.AreEqual("EUR", cashAmount.Currency);

            Assert.AreEqual(1170m, cashAmount.ValueInAccountCurrency.Amount);
            Assert.AreEqual(CashBook.AccountCurrency, cashAmount.ValueInAccountCurrency.Currency);
        }
예제 #8
0
        public void NotEqualOperator()
        {
            var cashAmount     = new CashAmount(1000m, "EUR");
            var cashAmount2    = new CashAmount(1000m, "EUR");
            var uglyDuckling   = new CashAmount(10m, "EUR");
            var uglyDuckling2  = new CashAmount(10m, "USD");
            var zeroCashAmount = new CashAmount(0, "USD");

            Assert.IsFalse(cashAmount2 != cashAmount);
            Assert.IsTrue(uglyDuckling != cashAmount);
            Assert.IsTrue(uglyDuckling != cashAmount2);
            Assert.IsTrue(uglyDuckling2 != cashAmount2);
            Assert.IsTrue(uglyDuckling2 != cashAmount);
            Assert.IsTrue(uglyDuckling2 != uglyDuckling);
            Assert.IsTrue(uglyDuckling2 != default(CashAmount));
            Assert.IsTrue(zeroCashAmount != default(CashAmount));
        }
예제 #9
0
        public void EqualsOperator()
        {
            var cashAmount     = new CashAmount(1000m, "EUR");
            var cashAmount2    = new CashAmount(1000m, "EUR");
            var uglyDuckling   = new CashAmount(10m, "EUR");
            var uglyDuckling2  = new CashAmount(10m, "USD");
            var zeroCashAmount = new CashAmount(0, "USD");

            Assert.IsTrue(cashAmount2.Equals(cashAmount));
            Assert.IsFalse(uglyDuckling.Equals(cashAmount));
            Assert.IsFalse(uglyDuckling.Equals(cashAmount2));
            Assert.IsFalse(uglyDuckling2.Equals(cashAmount2));
            Assert.IsFalse(uglyDuckling2.Equals(cashAmount));
            Assert.IsFalse(uglyDuckling2.Equals(uglyDuckling));
            Assert.IsFalse(uglyDuckling2.Equals(default(CashAmount)));
            Assert.IsFalse(zeroCashAmount.Equals(default(CashAmount)));
        }
예제 #10
0
        public void AddCash(Cash cash)
        {
            CashAmount.Add(cash);

            long cashAmont = cash.Amount;
            long gemAmount = CalculateCurrentGemAmount();

            if (cashAmont > gemAmount)
            {
                CashAmount.Remove(cash);
            }
            else if (CalculateCurrentCashAmount() > gemAmount)
            {
                CashAmount.Remove(cash);
            }
            else if (CalculateTotallAmount() > maxCapacity)
            {
                CashAmount.Remove(cash);
            }
        }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OrderFee"/> class
 /// </summary>
 /// <param name="orderFee">The order fee</param>
 public OrderFee(CashAmount orderFee)
 {
     Value = orderFee;
 }
예제 #12
0
 public override int GetHashCode()
 {
     return(CashAmount.GetHashCode());
 }
예제 #13
0
 /// <summary>
 /// Helper function to convert a <see cref="CashAmount"/> to the account currency
 /// </summary>
 protected virtual decimal ToAccountCurrency(SecurityPortfolioManager portfolio, CashAmount cash)
 {
     return(portfolio.CashBook.ConvertToAccountCurrency(cash).Amount);
 }
예제 #14
0
 public BalanceViewModel(CashAmount cash)
 {
     Update(cash);
 }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModifiedFillQuantityOrderFee"/> class
 /// </summary>
 /// <param name="orderFee">The order fee</param>
 /// <param name="quoteCurrency">The associated security quote currency</param>
 /// <param name="contractMultiplier">The associated security contract multiplier</param>
 public ModifiedFillQuantityOrderFee(CashAmount orderFee, string quoteCurrency, decimal contractMultiplier)
     : base(orderFee)
 {
     _quoteCurrency      = quoteCurrency;
     _contractMultiplier = contractMultiplier;
 }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OrderFee"/> class
 /// </summary>
 /// <param name="orderFee">The order fee</param>
 public OrderFee(CashAmount orderFee)
 {
     Value = new CashAmount(
         orderFee.Amount.Normalize(),
         orderFee.Currency);
 }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModifiedFillQuantityOrderFee"/> class
 /// </summary>
 /// <param name="orderFee">The order fee</param>
 public ModifiedFillQuantityOrderFee(CashAmount orderFee)
     : base(orderFee)
 {
 }
예제 #18
0
 public long CalculateCurrentCashAmount()
 {
     return(CashAmount.Select(x => x.Amount).Sum());
 }