Ejemplo n.º 1
0
        /// <summary>
        /// Gets all holdings for the account
        /// </summary>
        /// <returns>The current holdings from the account</returns>
        public override List <Holding> GetAccountHoldings()
        {
            var holdings = GetPositions(_accountId).Select(ConvertHolding).Where(x => x.Quantity != 0).ToList();

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

            if (oandaSymbols.Count > 0)
            {
                var quotes = GetRates(oandaSymbols).ToDictionary(x => x.instrument);
                foreach (var holding in holdings)
                {
                    var   oandaSymbol = _symbolMapper.GetBrokerageSymbol(holding.Symbol);
                    Price quote;
                    if (quotes.TryGetValue(oandaSymbol, out quote))
                    {
                        holding.MarketPrice = Convert.ToDecimal((quote.bid + quote.ask) / 2);
                    }
                }
            }

            return(holdings);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all holdings for the account
        /// </summary>
        /// <returns>The current holdings from the account</returns>
        public override List <Holding> GetAccountHoldings()
        {
            var holdings = _api.GetAccountHoldings();

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

            if (oandaSymbols.Count > 0)
            {
                var quotes = _api.GetRates(oandaSymbols);
                foreach (var holding in holdings)
                {
                    var  oandaSymbol = _symbolMapper.GetBrokerageSymbol(holding.Symbol);
                    Tick tick;
                    if (quotes.TryGetValue(oandaSymbol, out tick))
                    {
                        holding.MarketPrice = (tick.BidPrice + tick.AskPrice) / 2;
                    }
                }
            }

            return(holdings);
        }
Ejemplo n.º 3
0
        public void ReturnsCorrectBrokerageSymbol()
        {
            var mapper = new OandaSymbolMapper();

            var symbol = Symbol.Create("EURUSD", SecurityType.Forex, Market.Oanda);
            var brokerageSymbol = mapper.GetBrokerageSymbol(symbol);
            Assert.AreEqual("EUR_USD", brokerageSymbol);

            symbol = Symbol.Create("DE30EUR", SecurityType.Cfd, Market.Oanda);
            brokerageSymbol = mapper.GetBrokerageSymbol(symbol);
            Assert.AreEqual("DE30_EUR", brokerageSymbol);
        }
Ejemplo n.º 4
0
        public void ThrowsOnNullOrEmptySymbol()
        {
            var mapper = new OandaSymbolMapper();

            Assert.Throws<ArgumentException>(() => mapper.GetLeanSymbol(null, SecurityType.Forex, Market.Oanda));

            Assert.Throws<ArgumentException>(() => mapper.GetLeanSymbol("", SecurityType.Forex, Market.Oanda));

            var symbol = Symbol.Empty;
            Assert.Throws<ArgumentException>(() => mapper.GetBrokerageSymbol(symbol));

            symbol = null;
            Assert.Throws<ArgumentException>(() => mapper.GetBrokerageSymbol(symbol));

            symbol = Symbol.Create("", SecurityType.Forex, Market.Oanda);
            Assert.Throws<ArgumentException>(() => mapper.GetBrokerageSymbol(symbol));
        }
Ejemplo n.º 5
0
        public void ThrowsOnUnknownSymbol()
        {
            var mapper = new OandaSymbolMapper();

            Assert.Throws<ArgumentException>(() => mapper.GetLeanSymbol("ABC_USD", SecurityType.Forex, Market.Oanda));

            var symbol = Symbol.Create("ABCUSD", SecurityType.Forex, Market.Oanda);
            Assert.Throws<ArgumentException>(() => mapper.GetBrokerageSymbol(symbol));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Subscribes to the requested symbols (using a single streaming session)
        /// </summary>
        /// <param name="symbolsToSubscribe">The list of symbols to subscribe</param>
        protected void SubscribeSymbols(List <Symbol> symbolsToSubscribe)
        {
            var instruments = symbolsToSubscribe
                              .Select(symbol => SymbolMapper.GetBrokerageSymbol(symbol))
                              .ToList();

            StopPricingStream();

            if (instruments.Count > 0)
            {
                StartPricingStream(instruments);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Subscribes to the requested symbols (using a single streaming session)
        /// </summary>
        /// <param name="symbolsToSubscribe">The list of symbols to subscribe</param>
        protected void SubscribeSymbols(List <Symbol> symbolsToSubscribe)
        {
            var instruments = symbolsToSubscribe
                              .Select(symbol => SymbolMapper.GetBrokerageSymbol(symbol))
                              .ToList();

            PricingConnectionHandler.EnableMonitoring(false);

            StopPricingStream();

            if (instruments.Count > 0)
            {
                StartPricingStream(instruments);

                PricingConnectionHandler.EnableMonitoring(true);
            }
        }
Ejemplo n.º 8
0
        public void ThrowsOnInvalidSecurityType()
        {
            var mapper = new OandaSymbolMapper();

            Assert.Throws<ArgumentException>(() => mapper.GetLeanSymbol("AAPL", SecurityType.Equity, Market.Oanda));

            var symbol = Symbol.Create("AAPL", SecurityType.Equity, Market.Oanda);
            Assert.Throws<ArgumentException>(() => mapper.GetBrokerageSymbol(symbol));
        }