Exemple #1
0
 private static void OnTradeHistoryChanged(object sender, TradeHistoryChangedEventArgs e)
 {
     if (e.NewItem != null)
     {
         Console.WriteLine(string.Format("{4} new th {0}:{1} {2} {3}", e.Ticker.Exchange.Name, e.Ticker.Name, e.NewItem.RateString, e.NewItem.AmountString, e.NewItem.TimeString));
     }
     else
     {
         foreach (TradeInfoItem item in e.NewItems)
         {
             Console.WriteLine(string.Format("{4} new th {0}:{1} {2} {3}", e.Ticker.Exchange.Name, e.Ticker.Name, item.RateString, item.AmountString, item.TimeString));
         }
     }
 }
        protected internal override void OnTradeHistorySocketMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            LastWebSocketRecvTime = DateTime.Now;
            SocketConnectionInfo info = TradeHistorySockets.FirstOrDefault(c => c.Key == sender);

            if (info == null)
            {
                return;
            }
            Ticker t = info.Ticker;

            if (t.IsUpdatingTrades)
            {
                return;
            }

            if (t.CaptureData)
            {
                t.CaptureDataCore(CaptureStreamType.TradeHistory, CaptureMessageType.Incremental, e.Message);
            }

            JObject obj   = JsonConvert.DeserializeObject <JObject>(e.Message);
            JArray  items = obj.Value <JArray>("data");

            if (items == null)
            {
                return;
            }
            foreach (JObject item in items)
            {
                TradeInfoItem ti = new TradeInfoItem(null, t);
                ti.TimeString   = item.Value <string>("timestamp");
                ti.Type         = String2TradeType(item.Value <string>("side"));
                ti.AmountString = item.Value <string>("size");
                ti.RateString   = item.Value <string>("price");
                t.AddTradeHistoryItem(ti); //.InsertTradeHistoryItem(ti);
            }

            if (t.HasTradeHistorySubscribers)
            {
                TradeHistoryChangedEventArgs ee = new TradeHistoryChangedEventArgs()
                {
                    NewItem = t.TradeHistory.First()
                };
                t.RaiseTradeHistoryChanged(ee);
            }
        }
        void OnTradeHistoryItemRecv(Ticker ticker, string[] str)
        {
            TradeInfoItem item = new TradeInfoItem(null, ticker);

            item.Id           = FastValueConverter.ConvertPositiveInteger(str[3]);
            item.RateString   = str[4];
            item.AmountString = str[5];
            item.Time         = FromUnixTime(FastValueConverter.ConvertPositiveLong(str[8]));
            item.Type         = str[9][0] == 't' ? TradeType.Sell : TradeType.Buy;

            ticker.TradeHistory.Insert(0, item);
            if (ticker.HasTradeHistorySubscribers)
            {
                TradeHistoryChangedEventArgs e = new TradeHistoryChangedEventArgs()
                {
                    NewItem = item
                };
                ticker.RaiseTradeHistoryChanged(e);
            }
        }