private void start()
        {
            byte[]       binary = null;
            MemoryStream stream = null;

            ISubscriber sub  = connection.GetSubscriber();
            Feed        feed = null;

            sub.Subscribe(((Exchange)Enum.Parse(typeof(Exchange), SelectedExchange)).ToString(), (channel, message) =>
            {
                string str         = message;
                binary             = Convert.FromBase64String(message);
                stream             = new MemoryStream(binary);
                feed               = (Feed)ObjectSerialization.DeserializeFromStream(stream);
                double[] stockData = new double[2];
                stockData[0]       = feed.TimeStamp;
                stockData[1]       = feed.LTP;

                if (stockData != null && stockData.Length != 0)
                {
                    Clients.Group(feed.SymbolId.ToString() + "_" + SelectedExchange).updatePoints(stockData[0], stockData[1]);
                }
            });

            sub.Subscribe(Constants.REDIS_MVA_ROOM_PREFIX + SelectedSymbolId, (channel, message) =>
            {
                string str         = message;
                double[] stockData = new double[2];
                stockData[0]       = Convert.ToInt64((DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds);
                stockData[1]       = Convert.ToDouble(message);

                if (stockData != null && stockData.Length != 0)
                {
                    Clients.Group(SelectedSymbolId + "_" + SelectedExchange).updatePointsMVA(stockData[0], stockData[1]);
                }
            });

            while (true)
            {
                Thread.Sleep(600000);
            }
        }
Example #2
0
        private static void SubscribeRedis()
        {
            ConnectionMultiplexer connection = null;

            connection = GetRedisConnection();
            ISubscriber sub = connection.GetSubscriber();

            sub.Subscribe(_exchange, (channel, message) =>
            {
                lock (_lockQueue)
                {
                    byte[] binary       = Convert.FromBase64String(message);
                    MemoryStream stream = new MemoryStream(binary);
                    Feed feed           = (Feed)ObjectSerialization.DeserializeFromStream(stream);

                    //send to NEsper
                    _runtime.SendEvent(feed);
                }
            });
            sender = SenderFactory.GetSender(FeederQueueSystem.REDIS_CACHE);
        }
Example #3
0
        private static void Start()
        {
            _LTPStack = new Dictionary <string, Queue <double> >();
            ISender sender = SenderFactory.GetSender(FeederQueueSystem.REDIS_CACHE);

            _sum = new Dictionary <string, double>();

            ConnectionMultiplexer connection = null;

            connection = GetRedisConnection();

            ISubscriber sub  = connection.GetSubscriber();
            Feed        feed = null;

            byte[]       binary = null;
            MemoryStream stream = null;

            sub.Subscribe(_exchange, (channel, message) =>
            {
                lock (_lockQueue)
                {
                    string str = message;
                    binary     = Convert.FromBase64String(message);
                    stream     = new MemoryStream(binary);
                    feed       = (Feed)ObjectSerialization.DeserializeFromStream(stream);

                    string currentSymbolId = feed.SymbolId.ToString();

                    if (_sum.ContainsKey(currentSymbolId))
                    {
                        _sum[currentSymbolId] += feed.LTP;
                    }
                    else
                    {
                        _sum.Add(currentSymbolId, feed.LTP);
                    }

                    if (_LTPStack.ContainsKey(currentSymbolId))
                    {
                        _LTPStack[currentSymbolId].Enqueue(feed.LTP);
                    }
                    else
                    {
                        Queue <double> q = new Queue <double>();
                        q.Enqueue(feed.LTP);
                        _LTPStack.Add(currentSymbolId, q);
                    }

                    if (_LTPStack[currentSymbolId].Count > n)
                    {
                        _sum[currentSymbolId] -= _LTPStack[currentSymbolId].Dequeue();
                    }

                    //Publish MVA
                    double mva = _sum[currentSymbolId] / _LTPStack[currentSymbolId].Count();
                    sender.SendMVA(mva, _channelName + currentSymbolId);

                    Console.WriteLine("Symbol id {0} published aggregate {1} to channel {2}",
                                      feed.SymbolId, mva, _channelName + currentSymbolId);
                }
            });
        }