Ejemplo n.º 1
0
        public static bool IsQuickRise(string coin, ResponseKline res)
        {
            // 判断是否快速上涨,如果是快速上涨,防止追涨
            var klineData = res.data;
            // 暂时判断 1个小时内是否上涨超过12%, 如果超过,则控制下
            var max     = (decimal)0;
            var min     = (decimal)9999999;
            var nowOpen = klineData[0].open;

            for (var i = 0; i < 60; i++)
            {
                var item = klineData[i];
                if (max < item.open)
                {
                    max = item.open;
                }
                if (min > item.open)
                {
                    min = item.open;
                }
            }
            bool isQuickRise = false;

            if (max > min * (decimal)1.12)
            {
                if (nowOpen > min * (decimal)1.03)
                {
                    logger.Error($"一个小时内有大量的上涨,防止追涨,所以不能交易。coin:{coin}, nowOpen:{nowOpen}, min:{min}, max:{max}");
                    isQuickRise = true;
                }
            }
            return(isQuickRise);
        }
Ejemplo n.º 2
0
        public decimal AnalyzeNeedSell(decimal comparePrice, DateTime compareDate, string coin, string toCoin, out decimal nowOpen, ResponseKline res)
        {
            // 当前open
            nowOpen = 0;

            decimal higher = new decimal(0);

            try
            {
                //ResponseKline res = new AnaylyzeApi().kline(coin + toCoin, "1min", 1000);

                nowOpen = res.data[0].open;

                List <FlexPoint> flexPointList = new List <FlexPoint>();

                decimal openHigh      = res.data[0].open;
                decimal openLow       = res.data[0].open;
                long    idHigh        = 0;
                long    idLow         = 0;
                int     lastHighOrLow = 0; // 1 high, -1: low
                foreach (var item in res.data)
                {
                    if (Utils.GetDateById(item.id) < compareDate)
                    {
                        continue;
                    }

                    if (item.open > higher)
                    {
                        higher = item.open;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
                Console.WriteLine("1111111111111111111111 over  " + ex.Message);
            }
            return(higher);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 分析价位走势
        /// </summary>
        /// <param name="coin"></param>
        /// <param name="toCoin"></param>
        public List <FlexPoint> Analyze(ResponseKline res, out decimal lastLow, out decimal nowOpen, decimal flexPercent)
        {
            nowOpen = 0;
            lastLow = 999999999;

            try
            {
                //ResponseKline res = new AnaylyzeApi().kline(coin + toCoin, "1min", 1000);
                Console.WriteLine($"总数:{res.data.Count}");
                //Console.WriteLine(Utils.GetDateById(res.data[0].id));
                //Console.WriteLine(Utils.GetDateById(res.data[res.data.Count - 1].id));

                nowOpen = res.data[0].open;

                List <FlexPoint> flexPointList = new List <FlexPoint>();

                decimal openHigh      = res.data[0].open;
                decimal openLow       = res.data[0].open;
                long    idHigh        = res.data[0].id;
                long    idLow         = res.data[0].id;
                int     lastHighOrLow = 0; // 1 high, -1: low
                foreach (var item in res.data)
                {
                    if (item.open > openHigh)
                    {
                        openHigh = item.open;
                        idHigh   = item.id;
                    }
                    if (item.open < openLow)
                    {
                        openLow = item.open;
                        idLow   = item.id;
                    }

                    if (openHigh >= openLow * (decimal)flexPercent)
                    {
                        var dtHigh = Utils.GetDateById(idHigh);
                        var dtLow  = Utils.GetDateById(idLow);
                        // 相差了2%, 说明是一个节点了。
                        if (idHigh > idLow && lastHighOrLow != 1)
                        {
                            flexPointList.Add(new FlexPoint()
                            {
                                isHigh = true, open = openHigh, id = idHigh
                            });
                            lastHighOrLow = 1;
                            openHigh      = openLow;
                            idHigh        = idLow;
                        }
                        else if (idHigh < idLow && lastHighOrLow != -1)
                        {
                            flexPointList.Add(new FlexPoint()
                            {
                                isHigh = false, open = openLow, id = idLow
                            });
                            lastHighOrLow = -1;
                            openLow       = openHigh;
                            idLow         = idHigh;
                        }
                        else if (lastHighOrLow == 1)
                        {
                        }
                    }
                }

                if (flexPointList.Count == 0)
                {
                    logger.Error("flexpointlist 长度为0");
                }

                if (flexPointList.Count != 0 && flexPointList[0].isHigh)
                {
                    //
                    foreach (var item in res.data)
                    {
                        if (item.id < flexPointList[0].id && lastLow > item.open)
                        {
                            lastLow = item.open;
                        }
                    }
                }

                return(flexPointList);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }
            return(new List <FlexPoint>());
        }