Beispiel #1
0
        public void MACD(string coin, List <Domain.Coin.CoinKLineData.CoinKLineData> kline, CoinTime type)
        {
            try
            {
                Console.WriteLine($"---{coin} MACD---");

                if (kline == null || kline.Count < 1)
                {
                    return;
                }

                var macd = _indicator.MACD(kline);

                if (macd.Count < 1 || macd.FirstOrDefault()?.Item2 < macd.FirstOrDefault()?.Item3)
                {
                    return;
                }

                //获取时间段
                var typename = GetTimeType(type);

                var model = new Domain.Coin.CoinAnalyse.CoinAnalyse
                {
                    Id            = Guid.NewGuid().ToString(),
                    Coin          = coin,
                    TimeType      = typename,
                    CreateTime    = DateTime.Now,
                    Platform      = "火币",
                    IsDelete      = 0,
                    Close         = kline.First().Close,
                    Open          = kline.First().Open,
                    High          = kline.First().High,
                    Low           = kline.First().Low,
                    IndicatorType = 2,
                    Desc          = $"【{typename}级别,MACD金叉】"
                };

                model.HighRange  = model.High / model.Low - 1;
                model.CloseRange = model.Close / model.Open - 1;

                Console.WriteLine($" {coin}【{typename}】MACD,金叉");
                list_coin.Add(model);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 综合分析
        /// </summary>
        /// <param name="type"></param>
        public void Analyse(CoinTime type)
        {
            lock (_lock)
            {
                try
                {
                    using var scope      = _scopeFactory.CreateScope();
                    using var db_context = scope.ServiceProvider.GetRequiredService <CoinDbContext>();

                    var Average = db_context.CoinAnalyse.Where(x => x.IsDelete == 0 && x.IndicatorType == 1).ToList();
                    var Macd    = db_context.CoinAnalyse.Where(x => x.IsDelete == 0 && x.IndicatorType == 2).ToList();
                    var Kdj     = db_context.CoinAnalyse.Where(x => x.IsDelete == 0 && x.IndicatorType == 3).ToList();
                    var Fast    = db_context.CoinAnalyse.Where(x => x.IsDelete == 0 && x.IndicatorType == 4).ToList();

                    var list = new List <Domain.Coin.CoinAnalyse.CoinAnalyse>();
                    list.AddRange(Average);
                    list.AddRange(Macd);
                    list.AddRange(Kdj);
                    list.AddRange(Fast);

                    TotalDesc(list, Macd);
                    TotalDesc(list, Kdj);
                    TotalDesc(list, Fast);

                    var removecoin = new List <string>();
                    list = list.GroupBy(c => c.Coin).Select(c => c.First()).ToList();
                    var temp_list_coin = new List <Domain.Coin.CoinAnalyse.CoinAnalyse>();

                    foreach (var item in list.Where(item => item.Desc.Contains("☆")))
                    {
                        removecoin.Add(item.Coin);
                        var model = new Domain.Coin.CoinAnalyse.CoinAnalyse
                        {
                            Id         = Guid.NewGuid().ToString(),
                            Coin       = item.Coin,
                            CreateTime = DateTime.Now,

                            Platform      = "火币",
                            IsDelete      = 0,
                            Open          = item.Open,
                            Close         = item.Close,
                            CloseRange    = item.CloseRange,
                            HighRange     = item.HighRange,
                            TimeType      = GetTimeType(type),
                            Desc          = item.Desc,
                            IndicatorType = 0
                        };
                        temp_list_coin.Add(model);
                    }

                    if (!temp_list_coin.Any())
                    {
                        return;
                    }
                    db_context.Database.ExecuteSqlRaw("UPDATE CoinAnalyse SET IsDelete=1 where IndicatorType=0 ");
                    var sql = @"UPDATE CoinAnalyse SET IsDelete=1 where Coin in ('{0}')";
                    sql = string.Format(sql, string.Join("','", removecoin.ToArray()));
                    db_context.Database.ExecuteSqlRaw(sql);
                    db_context.CoinAnalyse.AddRange(temp_list_coin);
                    db_context.SaveChanges();
                    Console.WriteLine("---Analyse  SaveChanges---");
                }
                catch (Exception ex)
                {
                    _logger.LogError(new EventId(ex.HResult), ex, "---Analyse---");
                }
            }
        }
Beispiel #3
0
        public void KDJ(string coin, List <Domain.Coin.CoinKLineData.CoinKLineData> kline, CoinTime type)
        {
            try
            {
                Console.WriteLine($"---{coin} KDJ---");

                if (kline == null || kline.Count < 1)
                {
                    return;
                }

                var kdj = _indicator.KDJ(kline);
                //获取时间段
                var typename = GetTimeType(type);

                var desc = $"【{typename}级别,KDJ金叉】";

                //J值大于K值
                if (kdj.Count < 1 || kdj.FirstOrDefault()?.Item4 < kdj.FirstOrDefault()?.Item2)
                {
                    //超卖状态
                    if (kdj.FirstOrDefault()?.Item2 < 20 && kdj.FirstOrDefault()?.Item3 < 20 &&
                        kdj.FirstOrDefault()?.Item4 < 20)
                    {
                        desc = $"【{typename}级别,KDJ超卖状态,建议买入】";
                    }
                    else
                    {
                        return;
                    }
                }

                //超买状态
                if (kdj.FirstOrDefault()?.Item2 > 80 && kdj.FirstOrDefault()?.Item3 > 80 &&
                    kdj.FirstOrDefault()?.Item4 > 80)
                {
                    desc = $"【{typename}级别,KDJ超买状态,建议卖出】";
                }

                var model = new Domain.Coin.CoinAnalyse.CoinAnalyse
                {
                    Id            = Guid.NewGuid().ToString(),
                    Coin          = coin,
                    TimeType      = typename,
                    CreateTime    = DateTime.Now,
                    Platform      = "火币",
                    IsDelete      = 0,
                    Close         = kline.First().Close,
                    Open          = kline.First().Open,
                    High          = kline.First().High,
                    Low           = kline.First().Low,
                    IndicatorType = 3,
                    Desc          = desc
                };

                model.HighRange  = model.High / model.Low - 1;
                model.CloseRange = model.Close / model.Open - 1;

                Console.WriteLine($" {coin}【{typename}】KDJ,{desc}");
                list_coin.Add(model);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 均线系统
        /// </summary>
        public void SMA(string coin, List <Domain.Coin.CoinKLineData.CoinKLineData> kline, CoinTime type)
        {
            try
            {
                Console.WriteLine($"---{coin} SMA---");

                if (kline == null)
                {
                    return;
                }

                var data5  = _indicator.SMA(kline, 5);
                var data10 = _indicator.SMA(kline, 10);
                var data30 = _indicator.SMA(kline, 30);
                var data60 = _indicator.SMA(kline, 60);

                //获取时间段
                var typename = GetTimeType(type);

                if (data5.Count > 0 && data10.Count > 0 && data5.First().Item2 > data10.First().Item2)
                {
                    var model = new Domain.Coin.CoinAnalyse.CoinAnalyse
                    {
                        Id            = Guid.NewGuid().ToString(),
                        Coin          = coin,
                        TimeType      = typename,
                        CreateTime    = DateTime.Now,
                        Platform      = "火币",
                        IsDelete      = 0,
                        Close         = kline.First().Close,
                        Open          = kline.First().Open,
                        High          = kline.First().High,
                        Low           = kline.First().Low,
                        IndicatorType = 1
                    };

                    if (data5.Count > 0 && data30.Count > 0 && data5.First().Item2 > data30.First().Item2)
                    {
                        if (data5.Count > 0 && data60.Count > 0 && data5.First().Item2 > data60.First().Item2)
                        {
                            Console.WriteLine($" {coin}【{typename}】突破60K压力位,金叉");
                            model.Desc = $"【{typename}级别,均线突破60K压力位】";
                        }
                        else
                        {
                            Console.WriteLine($" {coin}【{typename}】突破30K压力位,金叉");
                            model.Desc = $"【{typename}级别,均线突破30K压力位】";
                        }
                    }
                    else
                    {
                        model.Desc = $"【{typename}级别,均线突破10K压力位】";
                        Console.WriteLine($" {coin}【{typename}】突破10K压力位,金叉");
                    }

                    model.HighRange  = model.High / model.Low - 1;
                    model.CloseRange = model.Close / model.Open - 1;
                    list_coin.Add(model);
                }

                Console.WriteLine("---Average  SaveChanges---");
            }
            catch (Exception ex)
            {
                _logger.LogError(new EventId(ex.HResult), ex, "---Average---");
            }
        }