Пример #1
0
        /// <summary>
        /// Handle portfolio changed events from IB
        /// </summary>
        private void HandlePortfolioUpdates(object sender, IB.UpdatePortfolioEventArgs e)
        {
            _accountHoldingsResetEvent.Reset();
            var holding = CreateHolding(e);

            _accountHoldings[holding.Symbol] = holding;
            OnPortfolioChanged(new SecurityEvent(holding.Symbol, e.Position, e.AverageCost));
        }
Пример #2
0
        /// <summary>
        /// Handle portfolio changed events from IB
        /// </summary>
        private void HandlePortfolioUpdates(object sender, IB.UpdatePortfolioEventArgs e)
        {
            Log.Trace("InteractiveBrokersBrokerage.HandlePortfolioUpdates(): Resetting account holdings reset event.");
            _accountHoldingsResetEvent.Reset();
            var holding = CreateHolding(e);

            _accountHoldings[holding.Symbol] = holding;
            OnPortfolioChanged(new SecurityEvent(holding.Symbol, e.Position, e.AverageCost));
        }
Пример #3
0
 /// <summary>
 /// Creates a holding object from te UpdatePortfolioEventArgs
 /// </summary>
 private Holding CreateHolding(IB.UpdatePortfolioEventArgs e)
 {
     return(new Holding
     {
         Symbol = MapSymbol(e.Contract),
         Type = ConvertSecurityType(e.Contract.SecurityType),
         Quantity = e.Position,
         AveragePrice = e.AverageCost,
         MarketPrice = e.MarketPrice
     });
 }
Пример #4
0
        /// <summary>
        /// Creates a holding object from te UpdatePortfolioEventArgs
        /// </summary>
        private Holding CreateHolding(IB.UpdatePortfolioEventArgs e)
        {
            string currencySymbol;

            if (!Forex.CurrencySymbols.TryGetValue(e.Contract.Currency, out currencySymbol))
            {
                currencySymbol = "$";
            }

            return(new Holding
            {
                Symbol = MapSymbol(e.Contract),
                Type = ConvertSecurityType(e.Contract.SecurityType),
                Quantity = e.Position,
                AveragePrice = e.AverageCost,
                MarketPrice = e.MarketPrice,
                ConversionRate = 1m, // this will be overwritten when GetAccountHoldings is called to ensure fresh values
                CurrencySymbol = currencySymbol
            });
        }
Пример #5
0
 /// <summary>
 /// Handle portfolio changed events from IB
 /// </summary>
 private void HandlePortfolioUpdates(object sender, IB.UpdatePortfolioEventArgs e)
 {
     OnPortfolioChanged(new PortfolioEvent(e.Contract.Symbol, e.Position));
 }
Пример #6
0
        //get all the orders in the tws protfolio
        static void ClientUpdatePortfolio(object sender, UpdatePortfolioEventArgs e)
        {
            if (Mode.Equals("exit") && !fPlaceOrders)
            {
                if (e.Contract.SecurityType.Equals(SecurityType.Stock))
                {
                    OrderInfo order = new OrderInfo();
                    order.Symbol = e.Contract.Symbol;
                    order.Direction = e.Position < 0 ? "Buy" : "Sell";
                    order.Amount = Math.Abs(e.Position);

                    Logger.WriteToLog(DateTime.Now,string.Format("ClientManager.client_UpdatePortfolio: {0}). found symbol: {1,-4} whith amount: {2,-4}",
                                          portfolioOedersCounter, e.Contract.Symbol, e.Position), Program.UserId);
                    orders.Add(order);
                    portfolioOedersCounter++;

                }
            }
        }
Пример #7
0
 void client_UpdatePortfolio(object sender, UpdatePortfolioEventArgs e)
 {
     PositionAvailableDelegate del;
     Symbol symbol;
     lock (_lockObject)
     {
         symbol = TWSAssetArgs.SymbolFromContract(e.Contract);
         openShares[symbol] = e.Position;
         del = PositionAvailable;
     }
     if (del != null)
     {
         del(symbol, e.Position);
     }
 }