public void AddTicker(string symbol, BinacneETF.BATicker t) { DateTime timeStamp = CommonLab.TimerHelper.ConvertStringToDateTime(t.ExchangeTimeStamp); if (timeStamp.Year < 2018) { return; } foreach (CommonLab.TimePeriodType type in Enum.GetValues(typeof(CommonLab.TimePeriodType))) { string key = CommonLab.RedisKeyConvert.GetRedisKey(CommonLab.RedisKeyType.Ticker, type, CommonLab.ExchangeNameConvert.GetShortExchangeName("binance"), symbol, timeStamp); lock (LockTickObject) { if (TickerData.ContainsKey(key)) { TickerData[key].UpdateTickerByTicker(t); } else { // CommonLab.Ticker ticker = new CommonLab.TradePeriod(symbol, t, GetLegalCurrency(symbol)); TickerData.Add(key, t); } } } }
public void StartListen() { wsticker = new WebSocket(spotwssurl + "/ws/!ticker@arr"); if (Config.Proxy != null) { wsticker.SetProxy("http://" + Config.Proxy.IP + ":" + Config.Proxy.Port, "", ""); } wsticker.OnMessage += (sender, e) => { if (e.IsText) { LastCommTimeStamp = DateTime.Now; JArray JaTickers = JArray.Parse(e.Data); try { for (int i = 0; i < JaTickers.Count; i++) { JObject ticker = JObject.Parse(JaTickers[i].ToString()); var tvar = Config.Exchange.Symbols.Where(baticker => baticker.Symbol == ticker["s"].ToString() ); if (tvar != null) { BATicker t = tvar.ToArray()[0].Ticker; t.High = Convert.ToDouble(ticker["h"].ToString()); t.Low = Convert.ToDouble(ticker["l"].ToString()); t.Last = Convert.ToDouble(ticker["c"].ToString()); t.Sell = Convert.ToDouble(ticker["a"].ToString()); t.Buy = Convert.ToDouble(ticker["b"].ToString()); t.SellQuantity = Convert.ToDouble(ticker["A"].ToString()); t.BuyQuantity = Convert.ToDouble(ticker["B"].ToString()); t.Volume = Convert.ToDouble(ticker["q"].ToString()); t.VolumeBase = Convert.ToDouble(ticker["v"].ToString()); t.PriceChange = Convert.ToDouble(ticker["p"].ToString()); t.PriceChangePct = Convert.ToDouble(ticker["P"].ToString()); t.Open = Convert.ToDouble(ticker["o"].ToString()); t.ExchangeTimeStamp = Convert.ToDouble(ticker["E"].ToString()) / 1000; t.LocalServerTimeStamp = CommonLab.TimerHelper.GetTimeStampMilliSeconds(DateTime.Now); if (tvar.ToArray()[0].HisTicker == null) { tvar.ToArray()[0].HisTicker = t.Clone(); } } } Config.RaiseUpdateTickerEvent(); //UpdateTicker(tradingpair, t); } catch (Exception err) { Console.WriteLine("ticker err:" + err.Message + e.Data); } } }; wsticker.Connect(); }
public void LoadHisData(DateTime t) { string json = ""; using (StreamReader sr = new StreamReader(@"HisData\" + Symbol + ".config")) { json = sr.ReadToEnd(); } List <CommonLab.Ticker> tickers = Newtonsoft.Json.JsonConvert.DeserializeObject <List <CommonLab.Ticker> >(json); CommonLab.Ticker ticker = tickers.Where(item => item.ExchangeTimeStamp > CommonLab.TimerHelper.GetTimeStampMilliSeconds(t)).OrderBy(i => i.ExchangeTimeStamp).ToArray()[0]; HisTicker = new BATicker(ticker); }
public void UpdateTickerByTicker(BATicker t) { if (t.High > High) { High = t.High; } if (t.Low < Low) { Low = t.Low; } Sell = t.Sell; Buy = t.Buy; Last = t.Last; Volume = t.Volume;//存疑 ExchangeTimeStamp = t.ExchangeTimeStamp; }
public BATicker Clone() { BATicker t = new BATicker(); //Info :交易所返回的原始结构 t.High = High; // :最高价 t.Low = Low; // :最低价 t.Sell = Sell; // :卖一价 t.SellQuantity = SellQuantity; t.BuyQuantity = BuyQuantity; t.PriceChange = PriceChange; t.PriceChangePct = PriceChangePct; t.VolumeBase = VolumeBase; t.Buy = Buy; // :买一价 t.Last = Last; // :最后成交价 t.Volume = Volume; // :最近成交量 t.Open = Open; //开盘价 t.ExchangeTimeStamp = ExchangeTimeStamp; //时间戳 交易所返回的 t.LocalServerTimeStamp = LocalServerTimeStamp; //本地时间戳 t.Delay = Delay; return(t); }