Exemple #1
0
        private static void RunCoin(List <CommonSymbols> symbols)
        {
            Task.Run(() =>
            {
                while (true)
                {
                    foreach (var symbol in symbols)
                    {
                        try
                        {
                            // 判断kline存不存在, 不存在读取一次.
                            var key = HistoryKlinePools.GetKey(symbol, "1min");
                            var historyKlineData = HistoryKlinePools.Get(key);
                            if (historyKlineData == null || historyKlineData.Data == null || historyKlineData.Data.Count == 0 || historyKlineData.Date < DateTime.Now.AddSeconds(-10))
                            {
                                KlineUtils.InitOneKine(symbol);
                            }

                            CoinTrade.Run(symbol);
                        }
                        catch (Exception ex)
                        {
                            logger.Error("RunCoin:  " + ex.Message, ex);
                        }
                        //Thread.Sleep(1000 * 1);
                    }
                }
            });
        }
        public async Task <string> shouge(long orderId)
        {
            try
            {
                var dogEmptySell = new DogEmptySellDao().GetDogEmptySellBySellOrderId(orderId);
                if (dogEmptySell.IsFinished)
                {
                    return("已经完成的不操作");
                }

                var dogEmptyBuyList = new DogEmptyBuyDao().ListDogEmptyBuyBySellOrderId(orderId);
                if (dogEmptyBuyList.Count > 0 && dogEmptyBuyList.Find(it => it.BuyState != StateConst.Canceled.ToString() && it.BuyState != StateConst.PartialFilled.ToString() && it.BuyState != StateConst.Filled.ToString()) != null)
                {
                    // 存在操作中的,则不操作
                    return("存在操作中的,则不操作");
                }

                CommonSymbol symbol = CoinUtils.GetCommonSymbol(dogEmptySell.SymbolName, dogEmptySell.QuoteCurrency);

                // 先初始化一下
                AnalyzeResult analyzeResult = AnalyzeResult.GetAnalyzeResult(symbol);
                if (analyzeResult == null)
                {
                    return("分析结果未null");
                }
                return(CoinTrade.ShouGeDogEmpty(dogEmptySell, symbol, analyzeResult, true));
            }
            catch (Exception ex)
            {
                logger.Error($"严重 orderId:{orderId}- {ex.Message}", ex);
                return(ex.Message);
            }
        }
Exemple #3
0
        public async Task <string> shouge(long orderId)
        {
            try
            {
                var dogMoreBuy = new DogMoreBuyDao().GetDogMoreBuyByBuyOrderId(orderId);
                if (dogMoreBuy.IsFinished)
                {
                    return("已完成出售");
                }

                var dogMoreSellList = new DogMoreSellDao().ListDogMoreSellByBuyOrderId(orderId);
                if (dogMoreSellList.Count > 0 &&
                    dogMoreSellList.Find(it =>
                                         it.SellState != StateConst.Canceled.ToString() &&
                                         it.SellState != StateConst.PartialFilled.ToString() &&
                                         it.SellState != StateConst.Filled.ToString()
                                         ) != null)
                {
                    // 存在操作中的,则不操作
                    return("存在出售中的");
                }

                var          symbols = CoinUtils.GetAllCommonSymbols(dogMoreBuy.QuoteCurrency);
                CommonSymbol symbol  = symbols.Find(it => it.BaseCurrency == dogMoreBuy.SymbolName);

                CoinTrade.ShouGeDogMore(dogMoreBuy, symbol);

                return("操作结束");
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
                return(ex.Message);
            }
        }
Exemple #4
0
        private static void RunCoin(List <CommonSymbol> symbols)
        {
            Task.Run(() =>
            {
                while (true)
                {
                    var begin          = DateTime.Now;
                    CoinTrade.RunCount = 0;
                    try
                    {
                        var tickers = PlatformApi.GetInstance("xx").GetTickers();
                        for (var i = 0; i < symbols.Count; i++)
                        {
                            var symbol = symbols[i];
                            try
                            {
                                DateTime now = DateTime.Now;
                                var bl       = CoinTrade.Run(i, symbol, tickers);
                                var mis      = (DateTime.Now - now).TotalMilliseconds;
                                if (mis > 1000)
                                {
                                    Console.WriteLine("每轮------------------------>" + mis);
                                }
                                if (bl)
                                {
                                    Thread.Sleep(150);
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.Error("RunCoin:  " + ex.Message, ex);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message, ex);
                    }
                    var useTime = (DateTime.Now - begin).TotalSeconds;
                    logger.Error("一轮总共耗时:" + (DateTime.Now - begin).TotalSeconds + ", 执行次数:" + CoinTrade.RunCount);


                    Thread.Sleep(1000);

                    if (DateTime.Now.Hour == 0 || DateTime.Now.Hour == 4 || DateTime.Now.Hour == 8 ||
                        DateTime.Now.Hour == 12 || DateTime.Now.Hour == 16 || DateTime.Now.Hour == 20)
                    {
                        if (DateTime.Now.Minute < 25)
                        {
                            new DogOrderStatDao().AddStatRecord();
                        }
                    }
                }
            });
        }
Exemple #5
0
 public static void Begin()
 {
     Task.Run(() =>
     {
         while (true)
         {
             try
             {
                 CoinTrade.CheckBuyOrSellState();
             }
             catch (Exception ex)
             {
                 logger.Error("查看购买以及出售结果" + ex.Message, ex);
             }
             Thread.Sleep(1000 * 30);
         }
     });
 }
Exemple #6
0
        public async Task <string> DoMore(string userName, string symbolName, string quoteCurrency)
        {
            try
            {
                var symbol = CoinUtils.GetCommonSymbol(symbolName, quoteCurrency);

                var ladder = (decimal)1.062;
                if (symbolName == "hb10" || symbolName == "eth" || symbolName == "ltc" || symbolName == "xrp" || symbolName == "bch" ||
                    symbolName == "etc" || symbolName == "eos" || symbolName == "ht" ||
                    symbolName == "dash" || symbolName == "zec" || symbolName == "omg" || symbolName == "ada" || symbolName == "iota")
                {
                    ladder = (decimal)1.058;
                }
                return(CoinTrade.BuyWhenDoMoreAnalyze(symbol, AccountConfigUtils.GetAccountConfig(userName), ladder));
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
                return(ex.Message);
            }
        }
        public async Task <object> DoEmpty(string userName, string symbolName, string quoteCurrency)
        {
            // 立马空单
            var symbols    = CoinUtils.GetAllCommonSymbols("usdt");
            var symbol     = symbols.Find(it => it.BaseCurrency == symbolName);
            var dao        = new KlineDao();
            var lastKlines = dao.List24HourKline(symbol.QuoteCurrency, symbol.BaseCurrency);

            if (Utils.GetDateById(lastKlines[0].Id) < DateTime.Now.AddMinutes(-3))
            {
                // 数据是3分钟前的数据, 不合理.
                return("没有拿到最近3分钟的数据");
            }
            // 大于今天最小值30%才行 or 大于24小时60%  并且大于历史最小的15%
            var control = new DogControlDao().GetDogControl(symbolName, quoteCurrency);

            if (control == null)
            {
                return("没有管控");
            }
            var nowPrice = lastKlines[0].Close;

            if (nowPrice < control.HistoryMin && nowPrice < control.HistoryMin + (control.HistoryMax - control.HistoryMin) * (decimal)0.12)
            {
                return("要大于区间12%");
            }

            var min24    = lastKlines.Min(it => it.Close);
            var minToday = lastKlines.Where(it => Utils.GetDateById(it.Id) >= DateTime.Now.Date).Min(it => it.Close);

            if (nowPrice > min24 * (decimal)1.60 || nowPrice > minToday * (decimal)1.30)
            {
                CoinTrade.DoEmpty(symbol, userName, AccountConfigUtils.GetAccountConfig(userName).MainAccountId);
                return(new { nowPrice, min24, minToday, DoEmpty = true });
            }
            return(new { nowPrice, min24, minToday });
        }