/// <summary> /// 新增交易信息 /// </summary> /// <param name="symbol"></param> /// <param name="t"></param> public void AddTrade(string symbol, CommonLab.Trade t) { DateTime timeStamp = CommonLab.TimerHelper.ConvertStringToDateTime(t.ExchangeTimeStamp); string key = ""; if (timeStamp.Year < 2018) { return; } int count = 0; try { foreach (CommonLab.TimePeriodType type in Enum.GetValues(typeof(CommonLab.TimePeriodType))) { key = CommonLab.RedisKeyConvert.GetRedisKey(CommonLab.RedisKeyType.Trade, type, CommonLab.ExchangeNameConvert.GetShortExchangeName("binance"), symbol, timeStamp); //if (DateTime.Now.Hour == 0 && DateTime.Now.Minute < 5) //{ // log.log("key:" + key + " TradeData:"+ TradeData.Count); //} //count++; lock (TradeData) { count++; if (TradeData.ContainsKey(key)) { count++; TradeData[key].Update(t, GetLegalCurrency(symbol)); } else { count++; CommonLab.TradePeriod tpm = new CommonLab.TradePeriod(symbol, t, GetLegalCurrency(symbol)); count++; TradeData.TryAdd(key, tpm); } } } } catch (IndexOutOfRangeException e) { string json = Newtonsoft.Json.JsonConvert.SerializeObject(TradeData); log.log(count + "key:" + key + "\r\nORE" + e.Message + e.StackTrace + e.Source + "\r\n" + json); Console.WriteLine("key:" + key + "\r\nORE" + e.Message + e.StackTrace + e.Source + "\r\n" + json); //Console.ReadKey(); } }
static void Main(string[] args) { if (!Directory.Exists(DataPath)) //如果不存在就创建file文件夹 { Directory.CreateDirectory(DataPath); //创建该文件夹 } tradeDataManage = new DataManage(log); Symbols = new List <string>(); Console.Write("Monitoring:"); log.log("Start"); using (System.IO.TextReader tr = new System.IO.StreamReader("Symbols.txt")) { string line = tr.ReadLine(); while (!string.IsNullOrEmpty(line)) { Symbols.Add(line); Console.Write(line + " "); line = tr.ReadLine(); } } Console.WriteLine(); BinacneETF.Config.Exchange = new ExchangeInfo(); CommonLab.HiPerfTimer hitime = new CommonLab.HiPerfTimer(); hitime.Start(); Config.Exchange.GetExchangeInfo(); hitime.Stop(); Console.WriteLine("获取服务器信息延时:" + hitime.Duration.ToString() + "秒"); Console.WriteLine("当前时间:" + DateTime.UtcNow.ToString() + ""); Console.WriteLine("Serv时间:" + Config.Exchange.ServerTime.ToString() + ""); Console.WriteLine("修正系统时间......."); if ((DateTime.UtcNow - Config.Exchange.ServerTime).TotalMilliseconds > 0) { CommonLab.TimerHelper.setSystemTime(Config.Exchange.ServerTime.AddSeconds(-hitime.Duration / 2)); } else { CommonLab.TimerHelper.setSystemTime(Config.Exchange.ServerTime.AddSeconds(hitime.Duration / 2)); } Console.WriteLine("当前时间:" + DateTime.UtcNow.ToString() + ""); Console.ReadKey(); GetCnyPrice = new Thread(new ThreadStart(GetCNY)); GetCnyPrice.IsBackground = true; GetCnyPrice.Start(); BinacneETF.Config.UpdateTradeEvent += Config_UpdateTradeEvent; BinacneETF.Config.UpdateTickerEvent += Config_UpdateTickerEvent; BinacneETF.Config.Exchange.Start();//收集ticker Thread.Sleep(3000); LastConnectTimeHour = DateTime.Now; BinacneETF.Config.Exchange.StartCollectTrade(Symbols);//收集交易信息 tradeDataManage.Start(); //插入中间线程 Thread midThread = new Thread(midThreadMethod); midThread.IsBackground = true; midThread.Start(); while (!(Console.ReadKey().KeyChar.ToString() == "q")) { } return; }