Example #1
0
        private void IndexDataMain()
        {
            string msg;

            while (true)
            {
                if (IndexAdapter.MessageQueue != null && IndexAdapter.MessageQueue.Count > 0 && IndexAdapter.MessageQueue.TryDequeue(out msg))
                {
                    if (OKCoinConfig.IsChannelData(msg))
                    {
                        try
                        {
                            var dataStr   = OKCoinConfig.GetChannelData(msg);
                            var IndexItem = Newtonsoft.Json.JsonConvert.DeserializeObject <Model.IndexModel>(dataStr);
                            if (IndexItem != null)
                            {
                                LatestIndex = IndexItem;
                                UpdateBindDataByIndexData(IndexItem);
                            }
                        }
                        catch (Exception ex)
                        {
                            App.Log.LogInfoFormat("TradeIndexModel.IndexDataMain Exception:{0}", ex.Message);
                        }
                    }
                }
                else
                {
                    Thread.Sleep(100);
                }
            }
        }
Example #2
0
        private void TradeDataMain(object obj)
        {
            var adapter = obj as OKCoinAdapter;

            if (adapter != null)
            {
                DateTime latestTime = DateTime.MinValue;
                string   msg        = null;

                while (true)
                {
                    if (adapter.MessageQueue != null && adapter.MessageQueue.Count > 0 && adapter.MessageQueue.TryDequeue(out msg) && OKCoinConfig.IsChannelData(msg))
                    {
                        try
                        {
                            var dataStr = OKCoinConfig.GetChannelData(msg);
                            var data    = Newtonsoft.Json.JsonConvert.DeserializeObject <string[][]>(dataStr);
                            if (data != null && data.Length > 0)
                            {
                                var item = data.Last();
                                Model.TradeModel tradeItem = new Model.TradeModel();
                                tradeItem.TradeID  = item[0];
                                tradeItem.Price    = item[1];
                                tradeItem.TradeQty = item[2];
                                tradeItem.Time     = item[3];
                                tradeItem.BSFlag   = item[4];
                                UpdateBindDataBuyTradeData(adapter.Channel, tradeItem);
                            }
                        }
                        catch (Exception ex)
                        {
                            App.Log.LogInfoFormat("TradeIndexModel.TradeDataMain Exception:{0}", ex.Message);
                        }
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }
                }
            }
        }