Ejemplo n.º 1
0
 public void CreateDogMoreSell(DogMoreSell dogMoreSell)
 {
     try
     {
         using (var tx = Database.BeginTransaction())
         {
             Database.Insert(dogMoreSell);
             tx.Commit();
         }
     }
     catch (Exception ex)
     {
         logger.Error($"--------危险----- CreateDogMoreSell-----------{JsonConvert.SerializeObject(dogMoreSell)}");
         logger.Error(ex.Message, ex);
         Thread.Sleep(1000 * 60 * 60);
     }
 }
Ejemplo n.º 2
0
        public static void ShouGeDogMore(DogMoreBuy dogMoreBuy, CommonSymbol symbol, AnalyzeResult analyzeResult = null)
        {
            if (analyzeResult == null)
            {
                analyzeResult = AnalyzeResult.GetAnalyzeResult(symbol);
            }
            if (analyzeResult == null)
            {
                return;
            }

            var nowPrice = analyzeResult.NowPrice;

            var thisLadderMoreSellPercent = ladderMoreSellPercent;

            if (analyzeResult.NowPrice / analyzeResult.MinPrice > (decimal)1.20)
            {
                thisLadderMoreSellPercent = (decimal)1.085;
            }
            else if (analyzeResult.NowPrice / analyzeResult.MinPrice > (decimal)1.30)
            {
                thisLadderMoreSellPercent = (decimal)1.08;
            }
            else if (analyzeResult.NowPrice / analyzeResult.MinPrice > (decimal)1.40)
            {
                thisLadderMoreSellPercent = (decimal)1.075;
            }
            else if (analyzeResult.NowPrice / analyzeResult.MinPrice > (decimal)1.50)
            {
                thisLadderMoreSellPercent = (decimal)1.07;
            }
            else if (analyzeResult.NowPrice / analyzeResult.MinPrice > (decimal)1.60)
            {
                thisLadderMoreSellPercent = (decimal)1.065;
            }
            thisLadderMoreSellPercent = Math.Max(thisLadderMoreSellPercent, (decimal)1.065);

            // 没有大于预期, 也不能收割
            if (nowPrice < dogMoreBuy.BuyTradePrice * thisLadderMoreSellPercent)
            {
                return;
            }

            if (!analyzeResult.CheckCanSellForHuiDiao(dogMoreBuy))
            {
                Console.WriteLine("不满足回调");
                // 判断是否有回掉
                return;
            }

            // 计算要出的数量
            decimal sellQuantity = JudgeSellUtils.CalcSellQuantityForMoreShouge(dogMoreBuy.BuyQuantity, dogMoreBuy.BuyTradePrice, nowPrice, symbol);
            // 计算要出的价格
            decimal sellPrice = decimal.Round(nowPrice * (decimal)0.988, symbol.PricePrecision);

            if (sellQuantity >= dogMoreBuy.BuyQuantity)
            {
                Console.WriteLine("出售的量过多");
                return;
            }
            if (sellQuantity * sellPrice <= dogMoreBuy.BuyQuantity * dogMoreBuy.BuyTradePrice)
            {
                //logger.Error($"{dogMoreBuy.SymbolName}{dogMoreBuy.QuoteCurrency} 未实现双向收益 sellQuantity:{sellQuantity}, BuyQuantity:{dogMoreBuy.BuyQuantity},sellQuantity * nowPrice:{sellQuantity * nowPrice},dogMoreBuy.BuyQuantity * dogMoreBuy.BuyTradePrice:{dogMoreBuy.BuyQuantity * dogMoreBuy.BuyTradePrice}");
                return;
            }

            OrderPlaceRequest req = new OrderPlaceRequest();

            req.account_id = dogMoreBuy.AccountId;
            req.amount     = sellQuantity.ToString();
            req.price      = sellPrice.ToString();
            req.source     = "api";
            req.symbol     = symbol.BaseCurrency + symbol.QuoteCurrency;;
            req.type       = "sell-limit";
            PlatformApi       api   = PlatformApi.GetInstance(dogMoreBuy.UserName);
            HBResponse <long> order = null;

            try
            {
                logger.Error($"");
                logger.Error($"1:开始下单 -----------------------------{JsonConvert.SerializeObject(req)}");
                order = api.OrderPlace(req);
                logger.Error($"2:下单结束 -----------------------------{JsonConvert.SerializeObject(order)}");

                // 下单出错, 报了异常, 也需要查询是否下单成功. 查询最近的订单.
                if (order.Status == "ok")
                {
                    DogMoreSell dogMoreSell = new DogMoreSell()
                    {
                        AccountId             = dogMoreBuy.AccountId,
                        UserName              = dogMoreBuy.UserName,
                        BuyOrderId            = dogMoreBuy.BuyOrderId,
                        SellOrderId           = order.Data,
                        SellOrderResult       = JsonConvert.SerializeObject(order),
                        SellDate              = DateTime.Now,
                        SellQuantity          = sellQuantity,
                        SellOrderPrice        = sellPrice,
                        SellState             = StateConst.Submitted,
                        SellTradePrice        = 0,
                        SymbolName            = symbol.BaseCurrency,
                        QuoteCurrency         = symbol.QuoteCurrency,
                        SellMemo              = "",
                        SellOrderDetail       = "",
                        SellOrderMatchResults = ""
                    };
                    new DogMoreSellDao().CreateDogMoreSell(dogMoreSell);

                    // 下单成功马上去查一次
                    QuerySellDetailAndUpdate(dogMoreBuy.UserName, order.Data);
                }
                logger.Error($"3:入库结束 ----------------------------- 多单收割 --> {JsonConvert.SerializeObject(dogMoreBuy)}");
                logger.Error($"");
            }
            catch (Exception ex)
            {
                logger.Error($"严重严重111111 -----------------------------  多单收割出错");
                Thread.Sleep(1000 * 60 * 5);
                throw ex;
            }
        }