Exemplo n.º 1
0
        /// <summary>
        /// MarketDataSnapshot message handler
        /// </summary>
        private void OnMarketDataSnapshot(MarketDataSnapshot message)
        {
            if (message.getRequestID() == _currentRequest)
            {
                // create new TradeBar from FXCM response message
                var instrument   = message.getInstrument();
                var securityType = instrument.getFXCMProductID() == IFixValueDefs.__Fields.FXCMPRODUCTID_FOREX
                    ? SecurityType.Forex
                    : SecurityType.Cfd;
                var symbol = ConvertFxcmSymbolToLeanSymbol(instrument.getSymbol(), securityType);
                var time   = FromJavaDateUtc(message.getDate().toDate());
                var open   = Convert.ToDecimal((message.getBidOpen() + message.getAskOpen()) / 2);
                var high   = Convert.ToDecimal((message.getBidHigh() + message.getAskHigh()) / 2);
                var low    = Convert.ToDecimal((message.getBidLow() + message.getAskLow()) / 2);
                var close  = Convert.ToDecimal((message.getBidClose() + message.getAskClose()) / 2);
                var bar    = new TradeBar(time, symbol, open, high, low, close, 0);

                // add bar to list
                _currentBars.Add(bar);

                if (message.getFXCMContinuousFlag() == IFixValueDefs.__Fields.FXCMCONTINUOUS_END)
                {
                    _mapRequestsToAutoResetEvents[_currentRequest].Set();
                    _mapRequestsToAutoResetEvents.Remove(_currentRequest);
                }
            }
        }
        /// <summary>
        /// MarketDataSnapshot message handler
        /// </summary>
        private void OnMarketDataSnapshot(MarketDataSnapshot message)
        {
            if (message.getRequestID() == _currentRequest)
            {
                var securityType = _symbolMapper.GetBrokerageSecurityType(message.getInstrument().getSymbol());
                var symbol       = _symbolMapper.GetLeanSymbol(message.getInstrument().getSymbol(), securityType, Market.FXCM);
                var time         = FromJavaDateUtc(message.getDate().toDate());


                if (message.getFXCMTimingInterval() == FXCMTimingIntervalFactory.TICK)
                {
                    var bid = Convert.ToDecimal(message.getBidClose());
                    var ask = Convert.ToDecimal(message.getAskClose());

                    var tick = new Tick(time, symbol, bid, ask);

                    //Add tick
                    _currentBaseData.Add(tick);
                }
                else // it bars
                {
                    var open  = Convert.ToDecimal((message.getBidOpen() + message.getAskOpen()) / 2);
                    var high  = Convert.ToDecimal((message.getBidHigh() + message.getAskHigh()) / 2);
                    var low   = Convert.ToDecimal((message.getBidLow() + message.getAskLow()) / 2);
                    var close = Convert.ToDecimal((message.getBidClose() + message.getAskClose()) / 2);

                    var bar = new TradeBar(time, symbol, open, high, low, close, 0);

                    // add bar to list
                    _currentBaseData.Add(bar);
                }

                if (message.getFXCMContinuousFlag() == IFixValueDefs.__Fields.FXCMCONTINUOUS_END)
                {
                    _mapRequestsToAutoResetEvents[_currentRequest].Set();
                    _mapRequestsToAutoResetEvents.Remove(_currentRequest);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// MarketDataSnapshot message handler
        /// </summary>
        private void OnMarketDataSnapshot(MarketDataSnapshot message)
        {
            var instrument   = message.getInstrument();
            var securityType = _symbolMapper.GetBrokerageSecurityType(instrument.getSymbol());
            var symbol       = _symbolMapper.GetLeanSymbol(instrument.getSymbol(), securityType, Market.FXCM);

            var isHistoryResponse = _pendingHistoryRequests.Contains(message.getRequestID());

            if (isHistoryResponse)
            {
                var time = FromJavaDate(message.getDate().toDate());

                // history timestamps must be in exchange time zone
                DateTimeZone exchangeTimeZone;
                if (_symbolExchangeTimeZones.TryGetValue(symbol, out exchangeTimeZone))
                {
                    time = time.ConvertFromUtc(exchangeTimeZone);
                }

                // append ticks/bars to history
                if (message.getFXCMTimingInterval() == FXCMTimingIntervalFactory.TICK)
                {
                    var bidPrice = Convert.ToDecimal(message.getBidClose());
                    var askPrice = Convert.ToDecimal(message.getAskClose());
                    var tick     = new Tick(time, symbol, bidPrice, askPrice);

                    _lastHistoryChunk.Add(tick);
                }
                else
                {
                    var bar = new QuoteBar(
                        time,
                        symbol,
                        new Bar(
                            Convert.ToDecimal(message.getBidOpen()),
                            Convert.ToDecimal(message.getBidHigh()),
                            Convert.ToDecimal(message.getBidLow()),
                            Convert.ToDecimal(message.getBidClose())
                            ),
                        0,
                        new Bar(
                            Convert.ToDecimal(message.getAskOpen()),
                            Convert.ToDecimal(message.getAskHigh()),
                            Convert.ToDecimal(message.getAskLow()),
                            Convert.ToDecimal(message.getAskClose())
                            ),
                        0);

                    _lastHistoryChunk.Add(bar);
                }
            }
            else
            {
                // update the current prices for the instrument
                _rates[instrument.getSymbol()] = message;

                // if instrument is subscribed, add ticks to list
                if (_subscriptionManager.IsSubscribed(symbol, TickType.Quote))
                {
                    // For some unknown reason, messages returned by SubscriptionRequestTypeFactory.SUBSCRIBE
                    // have message.getDate() rounded to the second, so we use message.getMakingTime() instead
                    var time = FromJavaDate(new java.util.Date(message.getMakingTime()));

                    // live ticks timestamps must be in exchange time zone
                    DateTimeZone exchangeTimeZone;
                    if (_symbolExchangeTimeZones.TryGetValue(symbol, out exchangeTimeZone))
                    {
                        time = time.ConvertFromUtc(exchangeTimeZone);
                    }

                    var bidPrice = Convert.ToDecimal(message.getBidClose());
                    var askPrice = Convert.ToDecimal(message.getAskClose());
                    var tick     = new Tick(time, symbol, bidPrice, askPrice);

                    _aggregator.Update(tick);
                }
            }

            if (message.getRequestID() == _currentRequest)
            {
                if (message.getFXCMContinuousFlag() == IFixValueDefs.__Fields.FXCMCONTINUOUS_END)
                {
                    _mapRequestsToAutoResetEvents[_currentRequest].Set();
                    _mapRequestsToAutoResetEvents.Remove(_currentRequest);

                    if (isHistoryResponse)
                    {
                        _pendingHistoryRequests.Remove(_currentRequest);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// MarketDataSnapshot message handler
        /// </summary>
        private void OnMarketDataSnapshot(MarketDataSnapshot message)
        {
            var time         = FromJavaDate(message.getDate().toDate());
            var instrument   = message.getInstrument();
            var securityType = _symbolMapper.GetBrokerageSecurityType(instrument.getSymbol());
            var symbol       = _symbolMapper.GetLeanSymbol(instrument.getSymbol(), securityType, Market.FXCM);

            var isHistoryResponse = _pendingHistoryRequests.Contains(message.getRequestID());

            if (isHistoryResponse)
            {
                // append ticks/bars to history
                if (message.getFXCMTimingInterval() == FXCMTimingIntervalFactory.TICK)
                {
                    var bidPrice = Convert.ToDecimal(message.getBidClose());
                    var askPrice = Convert.ToDecimal(message.getAskClose());
                    var tick     = new Tick(time, symbol, bidPrice, askPrice);

                    _lastHistoryChunk.Add(tick);
                }
                else
                {
                    var open  = Convert.ToDecimal((message.getBidOpen() + message.getAskOpen()) / 2);
                    var high  = Convert.ToDecimal((message.getBidHigh() + message.getAskHigh()) / 2);
                    var low   = Convert.ToDecimal((message.getBidLow() + message.getAskLow()) / 2);
                    var close = Convert.ToDecimal((message.getBidClose() + message.getAskClose()) / 2);
                    var bar   = new TradeBar(time, symbol, open, high, low, close, 0);

                    _lastHistoryChunk.Add(bar);
                }
            }
            else
            {
                // update the current prices for the instrument
                _rates[instrument.getSymbol()] = message;

                // if instrument is subscribed, add ticks to list
                if (_subscribedSymbols.Contains(symbol))
                {
                    var bidPrice = Convert.ToDecimal(message.getBidClose());
                    var askPrice = Convert.ToDecimal(message.getAskClose());
                    var tick     = new Tick(time, symbol, bidPrice, askPrice);

                    lock (_ticks)
                    {
                        _ticks.Add(tick);
                    }
                }
            }

            if (message.getRequestID() == _currentRequest)
            {
                if (message.getFXCMContinuousFlag() == IFixValueDefs.__Fields.FXCMCONTINUOUS_END)
                {
                    _mapRequestsToAutoResetEvents[_currentRequest].Set();
                    _mapRequestsToAutoResetEvents.Remove(_currentRequest);

                    if (isHistoryResponse)
                    {
                        _pendingHistoryRequests.Remove(_currentRequest);
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// MarketDataSnapshot message handler
        /// </summary>
        private void OnMarketDataSnapshot(MarketDataSnapshot message)
        {
            if (message.getRequestID() == _currentRequest)
            {
                var securityType = _symbolMapper.GetBrokerageSecurityType(message.getInstrument().getSymbol());
                var symbol = _symbolMapper.GetLeanSymbol(message.getInstrument().getSymbol(), securityType, Market.FXCM);
                var time = FromJavaDateUtc(message.getDate().toDate());


                if (message.getFXCMTimingInterval() == FXCMTimingIntervalFactory.TICK)
                {
                    var bid = Convert.ToDecimal(message.getBidClose());
                    var ask = Convert.ToDecimal(message.getAskClose());

                    var tick = new Tick(time, symbol, bid, ask);

                    //Add tick
                    _currentBaseData.Add(tick);

                }
                else // it bars
                {
                    var open = Convert.ToDecimal((message.getBidOpen() + message.getAskOpen()) / 2);
                    var high = Convert.ToDecimal((message.getBidHigh() + message.getAskHigh()) / 2);
                    var low = Convert.ToDecimal((message.getBidLow() + message.getAskLow()) / 2);
                    var close = Convert.ToDecimal((message.getBidClose() + message.getAskClose()) / 2);

                    var bar = new TradeBar(time, symbol, open, high, low, close, 0);

                    // add bar to list
                    _currentBaseData.Add(bar);
                }

                if (message.getFXCMContinuousFlag() == IFixValueDefs.__Fields.FXCMCONTINUOUS_END)
                {
                    _mapRequestsToAutoResetEvents[_currentRequest].Set();
                    _mapRequestsToAutoResetEvents.Remove(_currentRequest);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// MarketDataSnapshot message handler
        /// </summary>
        private void OnMarketDataSnapshot(MarketDataSnapshot message)
        {
            if (message.getRequestID() == _currentRequest)
            {
                // create new TradeBar from FXCM response message
                var securityType = _symbolMapper.GetBrokerageSecurityType(message.getInstrument().getSymbol());
                var symbol = _symbolMapper.GetLeanSymbol(message.getInstrument().getSymbol(), securityType, Market.FXCM);
                var time = FromJavaDateUtc(message.getDate().toDate());
                var open = Convert.ToDecimal((message.getBidOpen() + message.getAskOpen()) / 2);
                var high = Convert.ToDecimal((message.getBidHigh() + message.getAskHigh()) / 2);
                var low = Convert.ToDecimal((message.getBidLow() + message.getAskLow()) / 2);
                var close = Convert.ToDecimal((message.getBidClose() + message.getAskClose()) / 2);
                var bar = new TradeBar(time, symbol, open, high, low, close, 0);

                // add bar to list
                _currentBars.Add(bar);

                if (message.getFXCMContinuousFlag() == IFixValueDefs.__Fields.FXCMCONTINUOUS_END)
                {
                    _mapRequestsToAutoResetEvents[_currentRequest].Set();
                    _mapRequestsToAutoResetEvents.Remove(_currentRequest);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// MarketDataSnapshot message handler
        /// </summary>
        private void OnMarketDataSnapshot(MarketDataSnapshot message)
        {
            var instrument = message.getInstrument();
            var securityType = _symbolMapper.GetBrokerageSecurityType(instrument.getSymbol());
            var symbol = _symbolMapper.GetLeanSymbol(instrument.getSymbol(), securityType, Market.FXCM);

            var isHistoryResponse = _pendingHistoryRequests.Contains(message.getRequestID());
            if (isHistoryResponse)
            {
                var time = FromJavaDate(message.getDate().toDate());

                // append ticks/bars to history
                if (message.getFXCMTimingInterval() == FXCMTimingIntervalFactory.TICK)
                {
                    var bidPrice = Convert.ToDecimal(message.getBidClose());
                    var askPrice = Convert.ToDecimal(message.getAskClose());
                    var tick = new Tick(time, symbol, bidPrice, askPrice);

                    _lastHistoryChunk.Add(tick);
                }
                else
                {
                    var open = Convert.ToDecimal((message.getBidOpen() + message.getAskOpen()) / 2);
                    var high = Convert.ToDecimal((message.getBidHigh() + message.getAskHigh()) / 2);
                    var low = Convert.ToDecimal((message.getBidLow() + message.getAskLow()) / 2);
                    var close = Convert.ToDecimal((message.getBidClose() + message.getAskClose()) / 2);
                    var bar = new TradeBar(time, symbol, open, high, low, close, 0);

                    _lastHistoryChunk.Add(bar);
                }
            }
            else
            {
                // update the current prices for the instrument
                _rates[instrument.getSymbol()] = message;

                // if instrument is subscribed, add ticks to list
                if (_subscribedSymbols.Contains(symbol))
                {
                    // For some unknown reason, messages returned by SubscriptionRequestTypeFactory.SUBSCRIBE
                    // have message.getDate() rounded to the second, so we use message.getMakingTime() instead
                    var time = FromJavaDate(new java.util.Date(message.getMakingTime()));

                    var bidPrice = Convert.ToDecimal(message.getBidClose());
                    var askPrice = Convert.ToDecimal(message.getAskClose());
                    var tick = new Tick(time, symbol, bidPrice, askPrice);

                    lock (_ticks)
                    {
                        _ticks.Add(tick);
                    }
                }
            }

            if (message.getRequestID() == _currentRequest)
            {
                if (message.getFXCMContinuousFlag() == IFixValueDefs.__Fields.FXCMCONTINUOUS_END)
                {
                    _mapRequestsToAutoResetEvents[_currentRequest].Set();
                    _mapRequestsToAutoResetEvents.Remove(_currentRequest);

                    if (isHistoryResponse) _pendingHistoryRequests.Remove(_currentRequest);
                }
            }
        }