示例#1
0
 private static void RunHistoryKline(CommonSymbols symbol)
 {
     Task.Run(() =>
     {
         var countSuccess = 0;
         var countError   = 0;
         PlatformApi api  = PlatformApi.GetInstance("xx"); // 下面api和角色无关. 随便指定一个xx
         var begin        = DateTime.Now;
         while (true)
         {
             try
             {
                 var period = "1min";
                 var klines = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period);
                 var key    = HistoryKlinePools.GetKey(symbol, period);
                 HistoryKlinePools.Init(key, klines);
                 countSuccess++;
             }
             catch (Exception ex)
             {
                 countError++;
             }
             if (countSuccess % 20 == 0)
             {
                 Console.WriteLine($"RunHistoryKline -> {symbol.BaseCurrency}, Success:{countSuccess}, Error:{countError}, AvageSecond:{(DateTime.Now - begin).TotalSeconds / (countSuccess + countError)}");
             }
             Thread.Sleep(1000 * 6);
         }
     });
 }
示例#2
0
        public static void InitOneKine(CommonSymbols symbol)
        {
            try
            {
                PlatformApi api    = PlatformApi.GetInstance("xx"); // 下面api和角色无关. 随便指定一个xx
                var         period = "1min";
                var         klines = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period);
                var         key    = HistoryKlinePools.GetKey(symbol, period);
                HistoryKlinePools.Init(key, klines);

                // 记录到数据库
                Record(symbol.BaseCurrency, klines[0]);
            }
            catch (Exception ex)
            {
                logger.Error("InitOneKine --> " + ex.Message, ex);
            }
        }
示例#3
0
        public static void InitKlineInToPool(CommonSymbol symbol)
        {
            try
            {
                var period = "1min";
                var key    = HistoryKlinePools.GetKey(symbol, period);

                var dao        = new KlineDao();
                var lastKlines = dao.List24HourKline(symbol.QuoteCurrency, symbol.BaseCurrency);
                if (lastKlines.Count < 900)
                {
                    logger.Error($"{symbol.BaseCurrency},{symbol.QuoteCurrency}数据量太少{lastKlines.Count},无法分析啊:");
                }
                if (lastKlines.Count > 600)
                {
                    HistoryKlinePools.Init(key, lastKlines);
                }
            }
            catch (Exception ex)
            {
                logger.Error("InitOneKine --> " + ex.Message, ex);
            }
        }
示例#4
0
        /// <summary>
        /// 获取行情数据
        /// </summary>
        /// <param name="symbol"></param>
        public static void InitOneKine(CommonSymbol symbol)
        {
            try
            {
                var         begin  = DateTime.Now;
                PlatformApi api    = PlatformApi.GetInstance("xx"); // 下面api和角色无关. 随便指定一个xx
                var         period = "1min";
                var         klines = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period, 10);
                var         key    = HistoryKlinePools.GetKey(symbol, period);
                //HistoryKlinePools.Init(key, klines);

                var totalMilliseconds = (DateTime.Now - begin).TotalMilliseconds;
                if ((DateTime.Now - begin).TotalSeconds > 5)
                {
                    logger.Error("一次请求时间太长,达到:" + totalMilliseconds);
                }
                // 记录到数据库, 记录最近得数据。
                Record(symbol.BaseCurrency, klines[0]);

                var dao        = new KlineDao();
                var lastKlines = dao.List24HourKline(symbol.QuoteCurrency, symbol.BaseCurrency);
                var findList   = lastKlines.FindAll(it => klines.Find(item => item.Id == it.Id) != null).ToList();
                foreach (var kline in klines)
                {
                    var finds = findList.FindAll(it => it.Id == kline.Id);
                    if (finds.Count > 1)
                    {
                        // 删除,新增
                        new KlineDao().DeleteAndRecordKlines(symbol.BaseCurrency, kline);
                    }
                    else if (finds.Count == 1)
                    {
                        if (finds[0].Low != kline.Low || finds[0].High != kline.High || finds[0].Open != kline.Open || finds[0].Close != kline.Close)
                        {
                            // 删除新增
                            new KlineDao().DeleteAndRecordKlines(symbol.BaseCurrency, kline);
                        }
                    }
                    else
                    {
                        // 直接新增
                        Record(symbol.BaseCurrency, kline);
                    }
                }

                if (lastKlines.Count < 900)
                {
                    logger.Error($"{symbol.BaseCurrency}数据量太少{lastKlines.Count},无法分析啊:" + totalMilliseconds);
                }
                if (lastKlines.Count > 600)
                {
                    HistoryKlinePools.Init(key, lastKlines);
                }

                totalMilliseconds = (DateTime.Now - begin).TotalMilliseconds;
                if ((DateTime.Now - begin).TotalSeconds > 9)
                {
                    logger.Error("一次请求时间太长 含插入数据库,达到:" + totalMilliseconds);
                }
            }
            catch (Exception ex)
            {
                logger.Error("InitOneKine --> " + ex.Message, ex);
            }
        }