/// <summary>
 /// Run when an account value is updated
 /// </summary>
 /// <param name="sender">The sender</param>
 /// <param name="eventArgs">The event arguments</param>
 private void OnUpdateAccountValueEvent(object sender, UpdateAccountValueEventArgs eventArgs)
 {
     this.accountUpdates.AddOrUpdate(eventArgs.Key, eventArgs.Value, (key, value) =>
     {
         return(eventArgs.Value); // Always take the most recent result
     });
 }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public void updateAccountValue(string key, string value, string currency, string accountName)
        {
            var eventArgs = new UpdateAccountValueEventArgs(key, value, currency, accountName);

            this.UpdateAccountValueEvent.Invoke(this, eventArgs);
        }
Ejemplo n.º 3
0
        void ibclient_UpdateAccountValue2(object sender, UpdateAccountValueEventArgs e)
        {
            //tStart("ibclient_UpdateAccountValue(): "
            //       + "Acct: " + e.AccountName
            //       + ", Curr: " + e.Currency
            //       + ", " + e.Key + ": " + e.Value);
            string currency = "";
            if (e.Currency != null) currency = e.Currency;
            lock(private_lock)
            {
                if (!activeAccounts.ContainsKey(e.AccountName))
                {
                    activeAccounts.Add(e.AccountName, 0.0);
                }
                SetAccountDetails(e.AccountName, e.Key, currency, e.Value);
            }
            return;

            string pfsKey = e.Key + ";" + e.AccountName + ";" + e.Currency;
            string pfsValue = e.Value;

            if (!activeAccounts.ContainsKey(e.AccountName))
            {
                activeAccounts.Add(e.AccountName, 0.0);

            }
            BrokerAccount oqAccount = brokerInfo.Accounts[e.AccountName];

            if(!oqAccount.Fields.Contains(e.Key, e.Currency))
            {
                oqAccount.AddField(e.Key, e.Currency, e.Value);
            }
            else
            {
                // oqAccount.Fields.   [e.Key, e.Currency] = e.Value;
                // OQBUG
                // can't set new value ???
            }
            lock (portfolioSettings)
            {
                if (portfolioSettings.ContainsKey(pfsKey))
                {
                    // throw new Exception("duplicate Key: " + pfsKey);
                }
                portfolioSettings[pfsKey] = pfsValue;
            }
            lastPfsUpdate = DateTime.Now;

            // shortcut
            if (e.Key == "BuyingPower")
            {
                tStart("ibclient_UpdateAccountValue(): "
                + "Acct: " + e.AccountName
                + ", Curr: " + e.Currency
                + ", " + e.Key + ": " + e.Value);
                lock (private_lock)
                {
                    double buyingPower;
                    if (!double.TryParse(e.Value, NumberStyles.Any, CultureInfo.InvariantCulture,
                        out buyingPower))
                    {
                        error("can't parse buying Power: " + e.Value);
                    }
                    else
                    {
                        logger.AddLog(LoggerLevel.Detail, "*** received Buying Power: " + buyingPower.ToString());
                        activeAccounts[e.AccountName] = buyingPower;
                        oqAccount.BuyingPower = buyingPower;
                    }
                }
                tEnd("ibclient_UpdateAccountValue()");
            }
            return;
            #if FALSE
            switch (e.Key)
            {
                case "BuyingPower":
                    lock (private_lock)
                    {
                        if (!double.TryParse(e.Value, out buyingPower))
                        {
                            error("can't parse buying Power: " + e.Value);
                        }
                        else
                        {
                            logger.AddLog(LoggerLevel.Detail, "*** received Buying Power: " + buyingPower.ToString());
                        }
                    }
                    break;
                case "TotalCashBalance":
                    if (e.Currency == "BASE")
                    {
                        //info("TotalCashBalance: " + e.Value);
                    }
                    break;
                case "NetLiquidationByCurrency":
                    if (e.Currency == "BASE")
                    {
                        //info("NetLiquidation: " + e.Value);
                    }
                    break;
                case "AccountCode":
                    info("Account: " + e.Value);
                    break;
                default:
                    break;
            }
            tEnd("ibclient_UpdateAccountValue()");
            #endif
        }
Ejemplo n.º 4
0
 private void client_UpdateAccountSize(object sender, UpdateAccountValueEventArgs e)
 {
 }
Ejemplo n.º 5
0
 void ibclient_UpdateAccountValue(object sender, UpdateAccountValueEventArgs e)
 {
     try
     {
         ibclient_UpdateAccountValue2(sender, e);
     }
     catch (Exception ex)
     {
         logger.AddLog(LoggerLevel.Error, "ibclient_UpdateAccountValue2: " + ex.Message);
     }
 }