public void CreateDogMoreBuy(DogMoreBuy dogMoreBuy) { try { using (var tx = Database.BeginTransaction()) { Database.Insert(dogMoreBuy); tx.Commit(); } } catch (Exception ex) { logger.Error($"严重 --------危险----- CreateDogMoreBuy ------ 防止出错时候, 无限购买. 业务上不能出错, {JsonConvert.SerializeObject(dogMoreBuy)}"); logger.Error(ex.Message, ex); Thread.Sleep(1000 * 60 * 60); } }
public bool CheckCanSellForHuiDiao(DogMoreBuy dogMoreBuy) { // 是否回掉了,可以出售。 肯定要是最高点回掉 if (dogMoreBuy == null || dogMoreBuy.BuyTradePrice <= 0) { return(false); } // 找到最近24小时,并且是出售之后的价格数据 var klines = HistoryKlines.FindAll(it => it.Id > dogMoreBuy.Id); if (klines.Count == 0) { return(false); } var upPercent = NowPrice / dogMoreBuy.BuyTradePrice; if (upPercent <= (decimal)1.05) { // 这个太差了吧. return(false); } // 判断是否有最小值,且小于nowPrice var min = klines.Min(it => it.Close); var max = klines.Max(it => it.Close); var minHuidiao = (decimal)1.005; var maxHuidiao = (decimal)1.03; var huidiao = 1 + ((NowPrice / dogMoreBuy.BuyTradePrice) - 1) / 11; huidiao = Math.Max(huidiao, minHuidiao); huidiao = Math.Min(huidiao, maxHuidiao); return(NowPrice * huidiao < max && NowPrice * upPercent * 4 > max); }
public static bool CheckCanSellForHuiDiao(DogMoreBuy dogMoreBuy, decimal nowPrice, decimal nearHighPrice) { var minHuidiao = (decimal)1.005; var maxHuidiao = (decimal)1.03; var huidiao = minHuidiao; var upPercent = nowPrice / dogMoreBuy.BuyTradePrice; if (upPercent <= (decimal)1.02) { // 这个太差了吧. return(false); } huidiao = 1 + ((nowPrice / dogMoreBuy.BuyTradePrice) - 1) / 10; huidiao = Math.Max(huidiao, minHuidiao); huidiao = Math.Min(huidiao, maxHuidiao); if (nowPrice > nearHighPrice) { return(true); } return(nowPrice * huidiao < nearHighPrice && nowPrice * upPercent > nearHighPrice); }
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; } }