public void ReturnsCorrectBrokerageSymbol() { var mapper = new FxcmSymbolMapper(); var symbol = Symbol.Create("EURUSD", SecurityType.Forex, Market.FXCM); var brokerageSymbol = mapper.GetBrokerageSymbol(symbol); Assert.AreEqual("EUR/USD", brokerageSymbol); symbol = Symbol.Create("DE30EUR", SecurityType.Cfd, Market.FXCM); brokerageSymbol = mapper.GetBrokerageSymbol(symbol); Assert.AreEqual("GER30", brokerageSymbol); }
public void ThrowsOnNullOrEmptySymbol() { var mapper = new FxcmSymbolMapper(); Assert.Throws<ArgumentException>(() => mapper.GetLeanSymbol(null, SecurityType.Forex, Market.FXCM)); Assert.Throws<ArgumentException>(() => mapper.GetLeanSymbol("", SecurityType.Forex, Market.FXCM)); var symbol = Symbol.Empty; Assert.Throws<ArgumentException>(() => mapper.GetBrokerageSymbol(symbol)); symbol = null; Assert.Throws<ArgumentException>(() => mapper.GetBrokerageSymbol(symbol)); symbol = Symbol.Create("", SecurityType.Forex, Market.FXCM); Assert.Throws<ArgumentException>(() => mapper.GetBrokerageSymbol(symbol)); }
public void ThrowsOnUnknownSymbol() { var mapper = new FxcmSymbolMapper(); Assert.Throws<ArgumentException>(() => mapper.GetLeanSymbol("ABC/USD", SecurityType.Forex, Market.FXCM)); var symbol = Symbol.Create("ABCUSD", SecurityType.Forex, Market.FXCM); Assert.Throws<ArgumentException>(() => mapper.GetBrokerageSymbol(symbol)); }
public void ThrowsOnNullOrEmptySymbol() { var mapper = new FxcmSymbolMapper(); Assert.Throws <ArgumentException>(() => mapper.GetLeanSymbol(null, SecurityType.Forex, Market.FXCM)); Assert.Throws <ArgumentException>(() => mapper.GetLeanSymbol("", SecurityType.Forex, Market.FXCM)); var symbol = Symbol.Empty; Assert.Throws <ArgumentException>(() => mapper.GetBrokerageSymbol(symbol)); symbol = null; Assert.Throws <ArgumentException>(() => mapper.GetBrokerageSymbol(symbol)); symbol = Symbol.Create("", SecurityType.Forex, Market.FXCM); Assert.Throws <ArgumentException>(() => mapper.GetBrokerageSymbol(symbol)); }
public void ThrowsOnInvalidSecurityType() { var mapper = new FxcmSymbolMapper(); Assert.Throws <ArgumentException>(() => mapper.GetLeanSymbol("AAPL", SecurityType.Equity, Market.FXCM)); var symbol = Symbol.Create("AAPL", SecurityType.Equity, Market.FXCM); Assert.Throws <ArgumentException>(() => mapper.GetBrokerageSymbol(symbol)); }
public void ThrowsOnUnknownSymbol() { var mapper = new FxcmSymbolMapper(); Assert.Throws <ArgumentException>(() => mapper.GetLeanSymbol("ABC/USD", SecurityType.Forex, Market.FXCM)); var symbol = Symbol.Create("ABCUSD", SecurityType.Forex, Market.FXCM); Assert.Throws <ArgumentException>(() => mapper.GetBrokerageSymbol(symbol)); }
public void ThrowsOnInvalidSecurityType() { var mapper = new FxcmSymbolMapper(); Assert.Throws<ArgumentException>(() => mapper.GetLeanSymbol("AAPL", SecurityType.Equity, Market.FXCM)); var symbol = Symbol.Create("AAPL", SecurityType.Equity, Market.FXCM); Assert.Throws<ArgumentException>(() => mapper.GetBrokerageSymbol(symbol)); }
/// <summary> /// Get historical data enumerable for a single symbol, type and resolution given this start and end time (in UTC). /// </summary> /// <param name="symbol">Symbol for the data we're looking for.</param> /// <param name="resolution">Resolution of the data request</param> /// <param name="startUtc">Start time of the data in UTC</param> /// <param name="endUtc">End time of the data in UTC</param> /// <returns>Enumerable of base data for this symbol</returns> public IEnumerable <BaseData> Get(Symbol symbol, Resolution resolution, DateTime startUtc, DateTime endUtc) { if (!_symbolMapper.IsKnownLeanSymbol(symbol)) { throw new ArgumentException("Invalid symbol requested: " + symbol.Value); } if (symbol.ID.SecurityType != SecurityType.Forex && symbol.ID.SecurityType != SecurityType.Cfd) { throw new NotSupportedException("SecurityType not available: " + symbol.ID.SecurityType); } if (endUtc <= startUtc) { throw new ArgumentException("The end date must be greater than the start date."); } Console.WriteLine("Logging in..."); // create the gateway _gateway = GatewayFactory.createGateway(); // register the message listeners with the gateway _gateway.registerGenericMessageListener(this); _gateway.registerStatusMessageListener(this); // create local login properties var loginProperties = new FXCMLoginProperties(_userName, _password, _terminal, _server); // log in _gateway.login(loginProperties); // initialize session RequestTradingSessionStatus(); Console.WriteLine("Downloading {0} data from {1} to {2}...", resolution, startUtc.ToString("yyyyMMdd HH:mm:ss"), endUtc.ToString("yyyyMMdd HH:mm:ss")); // Find best FXCM parameters var interval = FxcmBrokerage.ToFxcmInterval(resolution); var totalTicks = (endUtc - startUtc).Ticks; // download data var totalBaseData = new List <BaseData>(); var end = endUtc; do // { //show progress progressBar(Math.Abs((end - endUtc).Ticks), totalTicks, Console.WindowWidth / 2, '█'); _currentBaseData.Clear(); var mdr = new MarketDataRequest(); mdr.setSubscriptionRequestType(SubscriptionRequestTypeFactory.SNAPSHOT); mdr.setResponseFormat(IFixMsgTypeDefs.__Fields.MSGTYPE_FXCMRESPONSE); mdr.setFXCMTimingInterval(interval); mdr.setMDEntryTypeSet(MarketDataRequest.MDENTRYTYPESET_ALL); mdr.setFXCMStartDate(new UTCDate(FxcmBrokerage.ToJavaDateUtc(startUtc))); mdr.setFXCMStartTime(new UTCTimeOnly(FxcmBrokerage.ToJavaDateUtc(startUtc))); mdr.setFXCMEndDate(new UTCDate(FxcmBrokerage.ToJavaDateUtc(end))); mdr.setFXCMEndTime(new UTCTimeOnly(FxcmBrokerage.ToJavaDateUtc(end))); mdr.addRelatedSymbol(_fxcmInstruments[_symbolMapper.GetBrokerageSymbol(symbol)]); AutoResetEvent autoResetEvent; lock (_locker) { _currentRequest = _gateway.sendMessage(mdr); autoResetEvent = new AutoResetEvent(false); _mapRequestsToAutoResetEvents[_currentRequest] = autoResetEvent; } if (!autoResetEvent.WaitOne(1000 * 5)) { // no response, exit break; } // Add data totalBaseData.InsertRange(0, _currentBaseData.Where(x => x.Time.Date >= startUtc.Date)); if (end != _currentBaseData[0].Time) { // new end date = first datapoint date. end = _currentBaseData[0].Time; } else { break; } } while (end > startUtc); Console.WriteLine("\nLogging out..."); // log out _gateway.logout(); // remove the message listeners _gateway.removeGenericMessageListener(this); _gateway.removeStatusMessageListener(this); return(totalBaseData.ToList()); }