예제 #1
0
        /// <summary>
        /// Stores all the account values
        /// </summary>
        private void HandleUpdateAccountValue(object sender, IB.UpdateAccountValueEventArgs e)
        {
            //https://www.interactivebrokers.com/en/software/api/apiguide/java/updateaccountvalue.htm

            try
            {
                // not sure if we need to track all the information
                if (_accountProperties.ContainsKey(e.Key))
                {
                    _accountProperties[e.Key] = e.Value;
                }
                else
                {
                    _accountProperties.Add(e.Key, e.Value);
                }

                // we want to capture if the user's cash changes so we can reflect it in the algorithm
                if (e.Key == "CashBalance")
                {
                    OnAccountChanged(new AccountEvent(e.Value.ToDecimal()));
                }
            }
            catch (Exception err)
            {
                Log.Error("InteractiveBrokersBrokerage.HandleUpdateAccountValue(): " + err.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Stores all the account values
        /// </summary>
        private void HandleUpdateAccountValue(object sender, IB.UpdateAccountValueEventArgs e)
        {
            //https://www.interactivebrokers.com/en/software/api/apiguide/activex/updateaccountvalue.htm

            try
            {
                if (e.Key == AccountValueKeys.CashBalance && e.Currency != "USD")
                {
                    // we don't care about cash except USD for now
                    return;
                }

                _accountProperties[e.Key] = e.Value;

                // we want to capture if the user's cash changes so we can reflect it in the algorithm
                if (e.Key == AccountValueKeys.CashBalance && e.Currency == "USD")
                {
                    var cashBalance = e.Value.ToDecimal();
                    OnAccountChanged(new AccountEvent(cashBalance));
                }
            }
            catch (Exception err)
            {
                Log.Error("InteractiveBrokersBrokerage.HandleUpdateAccountValue(): " + err.Message);
            }
        }
예제 #3
0
        /// <summary>
        /// Stores all the account values
        /// </summary>
        private void HandleUpdateAccountValue(object sender, IB.UpdateAccountValueEventArgs e)
        {
            //https://www.interactivebrokers.com/en/software/api/apiguide/activex/updateaccountvalue.htm

            try
            {
                _accountProperties[e.Currency + ":" + e.Key] = e.Value;

                // we want to capture if the user's cash changes so we can reflect it in the algorithm
                if (e.Key == AccountValueKeys.NetLiquidationByCurrency && e.Currency != "BASE")
                {
                    var cashBalance = decimal.Parse(e.Value);
                    _cashBalances.AddOrUpdate(e.Currency, cashBalance);
                    OnAccountChanged(new AccountEvent(e.Currency, cashBalance));
                }
            }
            catch (Exception err)
            {
                Log.Error("InteractiveBrokersBrokerage.HandleUpdateAccountValue(): " + err.Message);
            }
        }
예제 #4
0
 static void ClientUpdateAccountValue(object sender, UpdateAccountValueEventArgs e)
 {
 }
예제 #5
0
 void client_UpdateAccountValue(object sender, UpdateAccountValueEventArgs e)
 {
     lock (_lockObject)
     {
         //	You can use e.Key == "NetLiquidation" instead if preferred
         if (e.Key == "BuyingPower")
         {
             buyingPower = Convert.ToDouble(e.Value, CultureInfo.InvariantCulture);
         }
         else
         {
             //Trace.WriteLine(string.Format("TWS {0}: {1} {2}", e.Key, e.Value, e.Currency));
         }
     }
 }