Exemple #1
0
        /// <summary>
        /// Gets all holdings for the account
        /// </summary>
        /// <returns>The current holdings from the account</returns>
        public override List <Holding> GetAccountHoldings()
        {
            Log.Trace("FxcmBrokerage.GetAccountHoldings()");

            var holdings = _openPositions.Values.Select(ConvertHolding).Where(x => x.Quantity != 0).ToList();

            // Set MarketPrice in each Holding
            var fxcmSymbols = holdings
                              .Select(x => _symbolMapper.GetBrokerageSymbol(x.Symbol))
                              .ToList();

            if (fxcmSymbols.Count > 0)
            {
                var quotes = GetQuotes(fxcmSymbols).ToDictionary(x => x.getInstrument().getSymbol());
                foreach (var holding in holdings)
                {
                    MarketDataSnapshot quote;
                    if (quotes.TryGetValue(_symbolMapper.GetBrokerageSymbol(holding.Symbol), out quote))
                    {
                        holding.MarketPrice = Convert.ToDecimal((quote.getBidClose() + quote.getAskClose()) / 2);
                    }
                }
            }

            return(holdings);
        }
Exemple #2
0
        /// <summary>
        /// Gets all holdings for the account
        /// </summary>
        /// <returns>The current holdings from the account</returns>
        public override List <Holding> GetAccountHoldings()
        {
            Log.Trace("FxcmBrokerage.GetAccountHoldings()");

            // FXCM maintains multiple positions per symbol, so we aggregate them by symbol.
            // The average price for the aggregated position is the quantity weighted average price.
            var holdings = _openPositions.Values
                           .Select(ConvertHolding)
                           .Where(x => x.Quantity != 0)
                           .GroupBy(x => x.Symbol)
                           .Select(group => new Holding
            {
                Symbol         = group.Key,
                Type           = group.First().Type,
                AveragePrice   = group.Sum(x => x.AveragePrice * x.Quantity) / group.Sum(x => x.Quantity),
                ConversionRate = group.First().ConversionRate,
                CurrencySymbol = group.First().CurrencySymbol,
                Quantity       = group.Sum(x => x.Quantity)
            })
                           .ToList();

            // Set MarketPrice in each Holding
            var fxcmSymbols = holdings
                              .Select(x => _symbolMapper.GetBrokerageSymbol(x.Symbol))
                              .ToList();

            if (fxcmSymbols.Count > 0)
            {
                var quotes = GetQuotes(fxcmSymbols).ToDictionary(x => x.getInstrument().getSymbol());
                foreach (var holding in holdings)
                {
                    MarketDataSnapshot quote;
                    if (quotes.TryGetValue(_symbolMapper.GetBrokerageSymbol(holding.Symbol), out quote))
                    {
                        holding.MarketPrice = Convert.ToDecimal((quote.getBidClose() + quote.getAskClose()) / 2);
                    }
                }
            }

            return(holdings);
        }