Beispiel #1
0
        private void _core_OnUpdatePortfolio(object sender, UpdatePortfolioArg e)
        {
            IBPortfolioModel pot = new IBPortfolioModel();

            if (_Portfolios.All(a => a.contractID != e.contract.ConId))
            {
                pot = new IBPortfolioModel(e.contract, e.position, e.marketPrice, e.marketValue, e.averageCost, e.unrealizedPNL, e.realizedPNL, e.accountName);
                _Portfolios.Add(pot);
            }
            else
            {
                pot               = _Portfolios.Where(x => x.contractID == e.contract.ConId).FirstOrDefault();
                pot.position      = e.position;
                pot.marketValue   = e.marketValue;
                pot.averageCost   = e.averageCost;
                pot.unrealizedPNL = e.unrealizedPNL;
                pot.realizedPNL   = e.realizedPNL;
            }
            if (_DailyContractPL.All(x => x.Value.ConId != pot.contract.ConId))
            {
                int reqid = 1;
                if (_DailyContractPL.Count() > 0)
                {
                    reqid = _DailyContractPL.Keys.ToList().Max() + 1;
                }
                _DailyContractPL.Add(reqid, pot.contract);
                _Client.reqPnLSingle(reqid, _AccountName, "", pot.contractID);
            }
            foreach (IBPortfolioModel _port in _Portfolios)
            {
                _port.LastUpdate = DateTime.Now;
            }
        }
Beispiel #2
0
        private void _Core_OnUpdateAccount(object sender, UpdateAccountArg e)
        {
            IBAccountModel acc = new IBAccountModel(e.key, e.value, e.currency, e.accountName);

            if (e.key == "TotalCashValue")
            {
                UpdatePortfolioArg temp = new UpdatePortfolioArg(Convert.ToDouble(e.value), e.accountName);
                _core_OnUpdatePortfolio(null, temp);
            }
            if (!_Account.Any(a => a.key == acc.key))
            {
                _Account.Add(acc);
            }
            else
            {
                _Account.RemoveAll(x => x.key == acc.key);
                _Account.Add(acc);
            }
            foreach (IBAccountModel _acc in _Account)
            {
                _acc.LastUpdate = DateTime.Now;
            }
        }