public async Task <object> InitAccountInfo(string userName, string quoteCurrency, string sort, bool stat) { try { PlatformApi api = PlatformApi.GetInstance(userName); var accountInfo = api.GetAccountBalance(AccountConfigUtils.GetAccountConfig(userName).MainAccountId); var nowPriceList = new DogNowPriceDao().ListDogNowPrice(quoteCurrency); var result = new List <Dictionary <string, object> >(); foreach (var balanceItem in accountInfo.Data.list) { try { if (balanceItem.balance < (decimal)0.00001 || balanceItem.type == "frozen") { continue; } var nowPriceItem = nowPriceList.Find(it => it.SymbolName == balanceItem.currency); if (stat && balanceItem.currency == "usdt") { new DogStatSymbolDao().CreateDogStatSymbol(new DogStatSymbol { Amount = balanceItem.balance, CreateTime = DateTime.Now, EarnAmount = balanceItem.balance, StatDate = DateTime.Now.ToString("yyyy-MM-dd"), SymbolName = balanceItem.currency, UserName = userName }); } if (nowPriceItem == null) { continue; } var totalQuantity = new DogMoreBuyDao().GetBuyQuantityOfDogMoreBuyIsNotFinished(userName, balanceItem.currency); var kongAmount = new DogEmptySellDao().GetSellAmountOfDogEmptySellIsNotFinished(userName, balanceItem.currency); kongAmount = Math.Round(kongAmount, 6); Dictionary <string, object> item = new Dictionary <string, object>(); item.Add("currency", balanceItem.currency); item.Add("buyQuantity", totalQuantity); item.Add("balance", Math.Round(balanceItem.balance, 6)); item.Add("nowPrice", nowPriceItem.NowPrice); item.Add("kongAmount", kongAmount); if (kongAmount > 0) { item.Add("canEmptyQuantity", Math.Round((balanceItem.balance - totalQuantity), 6) + $"({kongAmount})"); } else { item.Add("canEmptyQuantity", Math.Round((balanceItem.balance - totalQuantity), 6)); } item.Add("canEmptyAmount", Math.Round((balanceItem.balance - totalQuantity - kongAmount) * nowPriceItem.NowPrice, 6)); result.Add(item); if (stat) { new DogStatSymbolDao().CreateDogStatSymbol(new DogStatSymbol { Amount = balanceItem.balance, CreateTime = DateTime.Now, EarnAmount = (decimal)Math.Round((balanceItem.balance - totalQuantity - kongAmount), 6), StatDate = DateTime.Now.ToString("yyyy-MM-dd"), SymbolName = balanceItem.currency, UserName = userName }); } } catch (Exception ex) { logger.Error(ex.Message, ex); logger.Info(JsonConvert.SerializeObject(balanceItem)); } } if (sort == "canEmptyAmountasc") { result.Sort((a, b) => decimal.Compare((decimal)a["canEmptyAmount"], (decimal)b["canEmptyAmount"])); } if (sort == "canEmptyAmountdesc") { result.Sort((a, b) => decimal.Compare((decimal)b["canEmptyAmount"], (decimal)a["canEmptyAmount"])); } else if (sort == "currencydesc") { result.Sort((a, b) => string.Compare(b["currency"].ToString(), a["currency"].ToString())); } else if (sort == "currencyasc") { result.Sort((a, b) => string.Compare(a["currency"].ToString(), b["currency"].ToString())); } return(result); } catch (Exception ex) { logger.Error(ex.Message, ex); throw ex; } }
public async Task <object> getNeedEmpty(string quoteCurrency) { try { var list = new List <string>(); var nowPriceList = new DogNowPriceDao().ListDogNowPrice(quoteCurrency); foreach (var nowPriceItem in nowPriceList) { if (nowPriceItem.SymbolName == "gxs" || nowPriceItem.SymbolName == "btc") { continue; } if (nowPriceItem.QuoteCurrency == "btc") { if (nowPriceItem.SymbolName == "btm" || nowPriceItem.SymbolName == "iost" || nowPriceItem.SymbolName == "icx") { continue; } } if (nowPriceItem.QuoteCurrency == "eth") { if (nowPriceItem.SymbolName == "ela" || nowPriceItem.SymbolName == "smt" || nowPriceItem.SymbolName == "mana") { continue; } } var nowPrice = nowPriceList.Find(it => it.SymbolName == nowPriceItem.SymbolName).NowPrice; { // 一个月内最上面 var maxPrice = new KlineDao().GetMaxPrice(quoteCurrency, nowPriceItem.SymbolName, DateTime.Now.AddDays(-30)); var minPrice = new KlineDao().GetMinPrice(quoteCurrency, nowPriceItem.SymbolName, DateTime.Now.AddDays(-30)); if (nowPrice >= maxPrice) { list.Add(nowPriceItem.SymbolName); continue; } if (nowPrice <= minPrice) { continue; } if ((nowPrice - minPrice) > (maxPrice - nowPrice) * 2) { list.Add(nowPriceItem.SymbolName); } } { // 一周内最上面 var maxPrice = new KlineDao().GetMaxPrice(quoteCurrency, nowPriceItem.SymbolName, DateTime.Now.AddDays(-7)); var minPrice = new KlineDao().GetMinPrice(quoteCurrency, nowPriceItem.SymbolName, DateTime.Now.AddDays(-7)); if (nowPrice >= maxPrice) { list.Add(nowPriceItem.SymbolName); continue; } if (nowPrice <= minPrice) { continue; } if ((nowPrice - minPrice) > (maxPrice - nowPrice) * 3) { list.Add(nowPriceItem.SymbolName); } } { // 一天内最上面 var maxPrice = new KlineDao().GetMaxPrice(quoteCurrency, nowPriceItem.SymbolName, DateTime.Now.AddDays(-1)); var minPrice = new KlineDao().GetMinPrice(quoteCurrency, nowPriceItem.SymbolName, DateTime.Now.AddDays(-1)); if (nowPrice >= maxPrice) { list.Add(nowPriceItem.SymbolName); continue; } if (nowPrice <= minPrice) { continue; } if ((nowPrice - minPrice) > (maxPrice - nowPrice) * 4) { list.Add(nowPriceItem.SymbolName); } } } return(list); } catch (Exception ex) { logger.Error(ex.Message, ex); throw ex; } }