예제 #1
0
        private static void RunBuy(CommonSymbol symbol, AnalyzeResult analyzeResult)
        {
            var nowPrice = analyzeResult.NowPrice;

            var userNames = UserPools.GetAllUserName();

            // 空单的自动波动收割
            foreach (var userName in userNames)
            {
                var dogEmptySellList = new DogEmptySellDao().GetNeedShougeDogEmptySell(userName, symbol.BaseCurrency, symbol.QuoteCurrency);
                if (dogEmptySellList == null || dogEmptySellList.Count == 0)
                {
                    continue;
                }

                Console.WriteLine("做空收割 " + symbol.BaseCurrency + symbol.QuoteCurrency + $", nowPrice:{nowPrice} 空单数量:" + dogEmptySellList.Count);
                foreach (var dogEmptySellItem in dogEmptySellList)
                {
                    try
                    {
                        ShouGeDogEmpty(dogEmptySellItem, symbol, analyzeResult);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            // 1.低于管控的购入价
            if (!JudgeBuyUtils.ControlCanBuy(symbol.BaseCurrency, symbol.QuoteCurrency, nowPrice))
            {
                return;
            }

            // 自动波动做多
            foreach (var userName in userNames)
            {
                try
                {
                    BuyWhenDoMore(symbol, AccountConfigUtils.GetAccountConfig(userName), analyzeResult);
                }
                catch (Exception ex)
                {
                }
            }
        }
예제 #2
0
        public static string BuyWhenDoMoreAnalyze(CommonSymbol symbol, AccountConfig account, decimal ladderBuyPercent)
        {
            AnalyzeResult analyzeResult = AnalyzeResult.GetAnalyzeResult(symbol);

            if (analyzeResult == null)
            {
                // 初始化数据, 再次拿去
                analyzeResult = AnalyzeResult.GetAnalyzeResult(symbol);
                if (analyzeResult == null)
                {
                    throw new ApplicationException("做多失败,分析出错");
                }
            }

            var historyKlines = analyzeResult.HistoryKlines;
            var nowPrice      = analyzeResult.NowPrice;

            // 1.低于管控的购入价
            var controlCanBuy = JudgeBuyUtils.ControlCanBuy(symbol.BaseCurrency, symbol.QuoteCurrency, nowPrice);

            if (!controlCanBuy)
            {
                return($"判断 发现不适合 controlCanBuy:{controlCanBuy}");
            }

            try
            {
                BuyWhenDoMore(symbol, account, analyzeResult);
            }
            catch (Exception ex)
            {
                //logger.Error($"{userName} {JsonConvert.SerializeObject(symbol)} {ex.Message}", ex);
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex);
                return(ex.Message);
            }
            return("----");
        }
예제 #3
0
        private static void RunSell(CommonSymbol symbol, AnalyzeResult analyzeResult, Ticker ticker)
        {
            if (ticker.symbol != symbol.BaseCurrency + symbol.QuoteCurrency)
            {
                Console.WriteLine("--------------------- 数据错误");
                return;
            }

            var historyKlines = analyzeResult.HistoryKlines;
            var nowPrice      = analyzeResult.NowPrice;

            var userNames = UserPools.GetAllUserName();

            // 多单的自动波动收割
            foreach (var userName in userNames)
            {
                var needSellDogMoreBuyList = new DogMoreBuyDao().GetNeedSellDogMoreBuy(userName, symbol.BaseCurrency, symbol.QuoteCurrency);

                foreach (var dogMoreBuyItem in needSellDogMoreBuyList)
                {
                    try
                    {
                        if (ticker.close < dogMoreBuyItem.BuyOrderPrice * (decimal)1.07)
                        {
                            continue;
                        }

                        ShouGeDogMore(dogMoreBuyItem, symbol, analyzeResult);
                    }
                    catch (Exception ex)
                    {
                        logger.Error($"收割出错 {ex.Message} {JsonConvert.SerializeObject(dogMoreBuyItem)}", ex);
                        continue;
                    }
                }
            }

            // 不符合管控的,则不考虑做空
            if (!JudgeBuyUtils.ControlCanSell(symbol.BaseCurrency, symbol.QuoteCurrency, historyKlines, nowPrice))
            {
                if (symbol.BaseCurrency == "xmx")
                {
                    Console.WriteLine("----------------------------------------------------------------------------------------");
                }
                return;
            }

            foreach (var userName in userNames)
            {
                try
                {
                    Console.WriteLine($"---> before doempty {userName}   {symbol.BaseCurrency},{symbol.QuoteCurrency}");

                    // 和上次做空价格要相差8%
                    var maxSellTradePrice = new DogEmptySellDao().GetMaxSellTradePrice(userName, symbol.BaseCurrency, symbol.QuoteCurrency);
                    if (maxSellTradePrice != null && nowPrice < maxSellTradePrice * ladderEmptySellPercent)
                    {
                        continue;
                    }

                    var accountConfig = AccountConfigUtils.GetAccountConfig(userName);
                    var accountId     = accountConfig.MainAccountId;

                    // 要减去未收割得。
                    var notShougeQuantity = new DogMoreBuyDao().GetBuyQuantityNotShouge(userName, symbol.BaseCurrency);

                    // 出售
                    decimal sellPrice = decimal.Round(nowPrice * (decimal)0.988, symbol.PricePrecision);

                    // 阶梯有数量差别
                    var minSellEmptyPrice = new DogEmptySellDao().GetMaxSellEmptyPrice(userName, symbol.BaseCurrency, symbol.QuoteCurrency);
                    var sellQuantity      = DogControlUtils.GetEmptySize(userName, symbol.BaseCurrency, minSellEmptyPrice, nowPrice);
                    sellQuantity = decimal.Round(sellQuantity, symbol.AmountPrecision);

                    if (
                        (symbol.QuoteCurrency == "usdt" && sellQuantity * nowPrice < (decimal)0.8) ||
                        (symbol.QuoteCurrency == "btc" && sellQuantity * nowPrice < (decimal)0.00009) ||
                        (symbol.QuoteCurrency == "eth" && sellQuantity * nowPrice < (decimal)0.003) ||
                        (symbol.QuoteCurrency == "ht" && sellQuantity * nowPrice < (decimal)0.5)
                        )
                    {
                        Console.WriteLine($"    {symbol.BaseCurrency}{symbol.QuoteCurrency},做空不超过{sellQuantity * nowPrice},, sellQuantity: {sellQuantity},  nowPrice:{nowPrice}");
                        continue;
                    }

                    Console.WriteLine($"准备做空 sellQuantity:{sellQuantity}, nowPrice:{nowPrice}");
                    SellWhenDoEmpty(accountId, userName, symbol, sellQuantity, sellPrice, $"device:");
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message, ex);
                }
            }
        }