Example #1
0
        public static decimal AnalyzeNeedSell(decimal comparePrice, DateTime compareDate, string coin, string toCoin, out decimal nowOpen)
        {
            // 当前open
            nowOpen = 0;

            decimal higher = new decimal(0);

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

                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)
            {
                Console.WriteLine("1111111111111111111111 over");
            }
            return(higher);
        }
Example #2
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure(new FileInfo("log4net.config"));
            ILog logger = LogManager.GetLogger("program");
            var  k      = "ltc";

            while (true)
            {
                decimal lastlow, nowOpen;

                //var res = CoinAnalyze.Analyze(k, out lastlow, out nowOpen);
                //Console.WriteLine(k + $" -->   {lastlow}, {nowOpen}");
                //foreach (var item in res)
                //{
                //    Console.WriteLine(Utils.GetDateById(item.id).ToString("yyyy-MM-dd HH:mm:ss") + " -->   " + JsonConvert.SerializeObject(item));
                //}

                //res = CoinAnalyze.Analyze(k, out lastlow, out nowOpen, 1.035);
                //Console.WriteLine(k + $" -->   {lastlow}, {nowOpen}");
                //foreach (var item in res)
                //{
                //    Console.WriteLine(Utils.GetDateById(item.id).ToString("yyyy-MM-dd HH:mm:ss") + " -->   " + JsonConvert.SerializeObject(item));
                //}
                // 1. kline
                var           dt    = DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss");
                ResponseKline kline = AnaylyzeApi.kline(k + toCoin, "1min", 1440);
                var           data  = kline.data;
                var           end   = data[data.Count - 1].close;
                for (var i = data.Count - 2; i >= 0; i--)
                {
                    var item    = data[i];
                    var percent = (end - item.close) / item.close;
                    percent = Math.Abs(percent);

                    var rate = percent / (data.Count - i);
                    if (rate > (decimal)0.001)
                    {
                        logger.Error("平均一分钟降低了0.1%,好恐怖啊");
                    }
                }
                logger.Error(JsonConvert.SerializeObject(kline));
                FileUtils.write(JsonConvert.SerializeObject(kline), "a" + dt + "-kline.txt");

                // 2. merged
                var merged = AnaylyzeApi.Merged(k + "usdt");
                logger.Error(JsonConvert.SerializeObject(merged));
                FileUtils.write(JsonConvert.SerializeObject(merged), "b" + dt + "-merged.txt");

                // 3. depth
                var depth = AnaylyzeApi.Depth(k + "usdt", "step0");
                logger.Error(JsonConvert.SerializeObject(depth));
                FileUtils.write(JsonConvert.SerializeObject(depth), "c" + dt + "-depth.txt");

                // 4. trade
                var trade = AnaylyzeApi.trade(k + "usdt");
                logger.Error(JsonConvert.SerializeObject(trade));
                FileUtils.write(JsonConvert.SerializeObject(trade), "d" + dt + "-trade.txt");

                // 5. histroy trade
                var historytrade = AnaylyzeApi.historytrade(k + "usdt");
                logger.Error(JsonConvert.SerializeObject(historytrade));
                FileUtils.write(JsonConvert.SerializeObject(historytrade), "e" + dt + "-historytrade.txt");

                // 6. detail
                var detail = AnaylyzeApi.detail(k + "usdt");
                logger.Error(JsonConvert.SerializeObject(detail));
                FileUtils.write(JsonConvert.SerializeObject(detail), "f" + dt + "-detail.txt");


                //res = CoinAnalyze.AnalyzeBs(k, out lastlow, out nowOpen);
                //Console.WriteLine(k + $" -->   {lastlow}, {nowOpen}");
                //foreach (var item in res)
                //{
                //    Console.WriteLine(Utils.GetDateById(item.id).ToString("yyyy-MM-dd HH:mm:ss")+" -->   "+JsonConvert.SerializeObject(item));
                //}
                Console.WriteLine("请输入");
                k = Console.ReadLine();
            }


            Console.ReadLine();
        }
Example #3
0
        /// <summary>
        /// 分析价位走势
        /// </summary>
        /// <param name="coin"></param>
        /// <param name="lastLow">最近一次最低的价格</param>
        /// <param name="nowOpen"></param>
        /// <param name="min"></param>
        /// <returns></returns>
        public static List <FlexPoint> Analyze(string coin, out decimal lastLow, out decimal nowOpen, double percentAuto = 1.005, string min = "1min")
        {
            nowOpen = 0;
            lastLow = 999999999;

            decimal smallest = 9999999;
            decimal biggest  = 0;

            try
            {
                ResponseKline res = AnaylyzeApi.kline(coin + toCoin, min, 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;
                //DateTime dtHight = Utils.GetDateById(idHigh);
                //DateTime dtLow = Utils.GetDateById(idLow);
                int lastHighOrLow = 0; // 1 high, -1: low
                for (var i = 1; i < res.data.Count; i++)
                {
                    var item = res.data[i];
                    if (item.open > biggest)
                    {
                        biggest = item.open;
                    }
                    if (item.open < smallest)
                    {
                        smallest = item.open;
                    }

                    if (item.open > openHigh)
                    {
                        openHigh = item.open;
                        idHigh   = item.id;
                    }
                    if (item.open < openLow)
                    {
                        openLow = item.open;
                        idLow   = item.id;
                    }

                    // 相差了2%, 说明是一个节点了。
                    if (openHigh >= openLow * (decimal)percentAuto) //1.005
                    {
                        var dtHigh = Utils.GetDateById(idHigh);
                        var dtLow  = Utils.GetDateById(idLow);

                        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)
                //{
                //    Console.WriteLine($"--------------{idHigh}------{idLow}------------------");
                //    Console.WriteLine(JsonConvert.SerializeObject(flexPointList));
                //    Console.WriteLine(JsonConvert.SerializeObject(res.data));
                //}

                Console.WriteLine($"最大: {biggest}, 最小: {smallest}, 比率: {biggest / smallest}, 现在:{res.data[0].open}");

                return(flexPointList);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message, ex);
            }
            return(new List <FlexPoint>());
        }
Example #4
0
        public static List <FlexPoint> AnalyzeBs(string coin, out decimal lastLow, out decimal nowOpen, string min = "1min")
        {
            nowOpen = 0;
            lastLow = 999999999;

            decimal smallest = 9999999;
            decimal biggest  = 0;

            try
            {
                ResponseKline res = AnaylyzeApi.kline(coin + toCoin, min, 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 comOpen       = res.data[0].open;
                long    comId         = res.data[0].id;
                int     lastHighOrLow = 0; // 1 high, -1: low
                for (var i = 1; i < res.data.Count; i++)
                {
                    var item = res.data[i];
                    if (item.open > biggest)
                    {
                        biggest = item.open;
                    }
                    if (item.open < smallest)
                    {
                        smallest = item.open;
                    }

                    if (item.open > comOpen && lastHighOrLow != 0)
                    {
                        flexPointList.Add(new FlexPoint()
                        {
                            isHigh = false, open = comOpen, id = comId
                        });
                        lastHighOrLow = 0;
                    }
                    else if (item.open < comOpen && lastHighOrLow != 1)
                    {
                        flexPointList.Add(new FlexPoint()
                        {
                            isHigh = true, open = comOpen, id = comId
                        });
                        lastHighOrLow = 1;
                    }

                    comOpen = item.open;
                    comId   = item.id;
                }

                Console.WriteLine($"总数:{flexPointList.Count} 最大: {biggest}, 最小: {smallest}, 比率: {biggest / smallest}");

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