Exemplo n.º 1
0
        public async Task <object> listMoreBuyIsNotFinished(string userName, string symbolName, string quoteCurrency, string sort = "lastbuy")
        {
            try
            {
                var list    = new List <DogMoreBuyDTO>();
                var symbols = CoinUtils.GetAllCommonSymbols(quoteCurrency);
                var tickers = PlatformApi.GetInstance("xx").GetTickers();
                Dictionary <string, decimal> closeDic = new Dictionary <string, decimal>();
                Dictionary <string, decimal> todayDic = new Dictionary <string, decimal>();
                var findTickers = tickers.FindAll(it => it.symbol.EndsWith(quoteCurrency));
                foreach (var item in findTickers)
                {
                    var itemSymbolName = item.symbol.Substring(0, item.symbol.Length - quoteCurrency.Length);
                    closeDic.Add(itemSymbolName, item.close);

                    if (item.close > 0)
                    {
                        todayDic.Add(itemSymbolName + "+", item.high / item.close);
                    }

                    if (item.low > 0)
                    {
                        todayDic.Add(itemSymbolName, item.high / item.low);
                        todayDic.Add(itemSymbolName + "-", item.close / item.low);
                    }
                }

                var dogcontrol    = new DogControlDao().ListAllDogControl();
                var maxInputPrice = new Dictionary <string, decimal>();
                var emptyPrice    = new Dictionary <string, decimal>();
                foreach (var item in dogcontrol)
                {
                    if (item.QuoteCurrency != quoteCurrency)
                    {
                        continue;
                    }
                    maxInputPrice.Add(item.SymbolName, item.MaxInputPrice);
                    emptyPrice.Add(item.SymbolName, item.EmptyPrice);
                }

                if (string.IsNullOrEmpty(symbolName))
                {
                    list = new DogMoreBuyDao().listEveryMinPriceMoreBuyIsNotFinished(userName, quoteCurrency);
                    var countSymbol = new DogMoreBuyDao().CountSymbol(userName, quoteCurrency);
                    foreach (var item in list)
                    {
                        item.Count = countSymbol.Find(it => it.SymbolName == item.SymbolName)?.Count ?? 0;
                    }
                    list = list.Where(it => it.SymbolName != "btc" && it.SymbolName != "ven" && it.SymbolName != "hsr").ToList();

                    if (sort != "lastbuy")
                    {
                        list.Sort((a, b) =>
                        {
                            if (!closeDic.ContainsKey(a.SymbolName) || !closeDic.ContainsKey(b.SymbolName))
                            {
                                return(1);
                            }
                            var aTradePrice = a.BuyTradePrice;
                            if (aTradePrice <= 0)
                            {
                                aTradePrice = a.BuyOrderPrice;
                            }
                            var bTradePrice = b.BuyTradePrice;
                            if (bTradePrice <= 0)
                            {
                                bTradePrice = b.BuyOrderPrice;
                            }
                            var ap = closeDic[a.SymbolName] / aTradePrice;
                            var bp = closeDic[b.SymbolName] / bTradePrice;
                            if (sort == "more")
                            {
                                return(ap > bp ? 1 : -1);
                            }
                            else
                            {
                                return(ap > bp ? -1 : 1);
                            }
                        });
                    }
                    else
                    {
                        list.Sort((a, b) =>
                        {
                            return((b.BuyDate.Ticks > a.BuyDate.Ticks || (b.BuyDate.Ticks == a.BuyDate.Ticks && string.Compare(b.SymbolName, a.SymbolName) > 0)) ? 1 : -1);
                        });
                    }
                }
                else
                {
                    list = new DogMoreBuyDao().listMoreBuyIsNotFinished(userName, symbolName, quoteCurrency);
                }

                var noBuy = symbols.Select(it => it.BaseCurrency).ToList();
                noBuy.RemoveAll(it => list.Find(item => item.SymbolName == it) != null);

                return(new { list, closeDic, todayDic, noBuy, maxInputPrice, emptyPrice });
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
                throw ex;
            }
        }
Exemplo n.º 2
0
        public async Task <object> ListDogMoreBuyNotFinishedStatistics(string userName, string quoteCurrency, string sort)
        {
            try
            {
                var res = new DogMoreBuyDao().ListDogMoreBuyNotFinishedStatistics(userName, quoteCurrency);

                var symbols = CoinUtils.GetAllCommonSymbols("usdt");
                symbols = symbols.Where(it => it.BaseCurrency != "btc").ToList();
                var nowPriceList = new DogNowPriceDao().ListDogNowPrice(quoteCurrency);
                Dictionary <string, decimal> closeDic = new Dictionary <string, decimal>();
                foreach (var item in nowPriceList)
                {
                    if (item.QuoteCurrency != quoteCurrency)
                    {
                        continue;
                    }
                    closeDic.Add(item.SymbolName, item.NowPrice);
                }

                foreach (var item in res)
                {
                    if (closeDic.ContainsKey(item.SymbolName))
                    {
                        item.NowPrice       = closeDic[item.SymbolName];
                        item.NowTotalAmount = closeDic[item.SymbolName] * item.TotalQuantity;
                    }
                }
                if (sort == "maxmin")
                {
                    Console.WriteLine(res.Find(it => it.MinPrice <= 0 || it.MaxPrice <= 0) == null);

                    var rate = 1;
                    if (quoteCurrency == "btc")
                    {
                        rate = 1000000;
                    }
                    if (quoteCurrency == "eth")
                    {
                        rate = 100000;
                    }
                    res.Sort((b, a) =>
                    {
                        if (a.MinPrice == 0 || b.MinPrice == 0)
                        {
                            return(0);
                        }
                        var aMaxPrice = a.MaxPrice * rate;
                        var bMaxPrice = b.MaxPrice * rate;
                        var aMinPrice = a.MinPrice * rate;
                        var bMinPrice = b.MinPrice * rate;
                        var bb        = ((aMaxPrice * bMinPrice) - (bMaxPrice * aMinPrice));
                        if (bb == 0)
                        {
                            return(0);
                        }
                        return(bb > 0 ? 1 : -1);
                    });
                }
                if (sort == "amount")
                {
                    res.Sort((b, a) => (int)(a.TotalAmount - b.TotalAmount));
                }
                if (sort == "nowamount")
                {
                    res.Sort((b, a) => (int)(a.NowTotalAmount - b.NowTotalAmount));
                }
                if (sort == "diffamount")
                {
                    res.Sort((b, a) => (int)(a.TotalAmount - a.NowTotalAmount - (b.TotalAmount - b.NowTotalAmount)));
                }
                if (sort == "count")
                {
                    res.Sort((b, a) => a.Count - b.Count);
                }
                return(res);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
                throw ex;
            }
        }