Beispiel #1
0
        public static bool IsQuickRise(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("一个小时内有大量的上涨,防止追涨,所以不能交易。");
                    isQuickRise = true;
                }
            }
            return(isQuickRise);
        }
Beispiel #2
0
        /// <summary>
        /// 分析价位走势
        /// </summary>
        /// <param name="coin"></param>
        /// <param name="toCoin"></param>
        public List <FlexPoint> Analyze(ResponseKline res, out decimal lastLow, out decimal nowOpen)
        {
            nowOpen = 0;
            lastLow = 999999999;

            try
            {
                //ResponseKline res = new AnaylyzeApi().kline(coin + toCoin, "1min", 1440);
                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)1.025)
                    {
                        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[0].isHigh)
                {
                    //
                    foreach (var item in res.data)
                    {
                        if (item.id < flexPointList[0].id && lastLow > item.open)
                        {
                            lastLow = item.open;
                        }
                    }
                }

                if (flexPointList.Count < 0)
                {
                    logger.Error($"--------------{idHigh}------{idLow}------------------");
                    logger.Error(JsonConvert.SerializeObject(flexPointList));
                    logger.Error(JsonConvert.SerializeObject(res.data));
                }

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