コード例 #1
0
        public async Task BuyTest(string quoteCurrency)
        {
            var symbols = CoinUtils.GetAllCommonSymbols(quoteCurrency);
            var account = AccountConfigUtils.GetAccountConfig("qq");

            foreach (var symbol in symbols)
            {
                PlatformApi       api = PlatformApi.GetInstance("qq");
                OrderPlaceRequest req = new OrderPlaceRequest();
                req.account_id = account.MainAccountId;
                req.amount     = "0.0000001";
                req.price      = "0.001";
                req.source     = "api";
                req.symbol     = symbol.BaseCurrency + symbol.QuoteCurrency;
                req.type       = "buy-limit";

                try
                {
                    HBResponse <long> order = api.OrderPlace(req);

                    logger.Error($"3 ------------------------");
                }
                catch (Exception ex)
                {
                    logger.Error($"{ symbol.BaseCurrency + symbol.QuoteCurrency}" + ex.Message, ex);
                }
            }
        }
コード例 #2
0
        public async Task <object> listEmptySellIsNotFinished(string symbolName, string quoteCurrency, string userName)
        {
            var list         = new List <DogEmptySell>();
            var symbols      = CoinUtils.GetAllCommonSymbols(quoteCurrency);
            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);
            }
            if (string.IsNullOrEmpty(symbolName))
            {
                list = new DogEmptySellDao().listEveryMaxPriceEmptySellIsNotFinished(userName, quoteCurrency);
            }
            else
            {
                list = new DogEmptySellDao().ListDogEmptySellNotFinished(symbolName, userName, quoteCurrency);
            }

            return(new { list, closeDic });
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: radtek/PigAuto
        static void Main(string[] args)
        {
            XmlConfigurator.Configure(new FileInfo("log4net.config"));
            ILog logger = LogManager.GetLogger("program");

            logger.Info("----------------------  begin  --------------------------------");

            // 初始化
            CoinUtils.Init();
            var symbols = CoinUtils.GetAllCommonSymbols();

            // 初始化kline
            KlineUtils.Begin();

            // 不停的对每个币做操作
            BuyOrSellUtils.Begin();

            // 状态检查
            TradeStateUtils.Begin();

            while (true)
            {
                Console.ReadLine();
            }
        }
コード例 #4
0
        public async Task <string> shouge(long orderId)
        {
            try
            {
                var dogMoreBuy = new DogMoreBuyDao().GetDogMoreBuyByBuyOrderId(orderId);
                if (dogMoreBuy.IsFinished)
                {
                    return("已完成出售");
                }

                var dogMoreSellList = new DogMoreSellDao().ListDogMoreSellByBuyOrderId(orderId);
                if (dogMoreSellList.Count > 0 &&
                    dogMoreSellList.Find(it =>
                                         it.SellState != StateConst.Canceled.ToString() &&
                                         it.SellState != StateConst.PartialFilled.ToString() &&
                                         it.SellState != StateConst.Filled.ToString()
                                         ) != null)
                {
                    // 存在操作中的,则不操作
                    return("存在出售中的");
                }

                var          symbols = CoinUtils.GetAllCommonSymbols(dogMoreBuy.QuoteCurrency);
                CommonSymbol symbol  = symbols.Find(it => it.BaseCurrency == dogMoreBuy.SymbolName);

                CoinTrade.ShouGeDogMore(dogMoreBuy, symbol);

                return("操作结束");
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
                return(ex.Message);
            }
        }
コード例 #5
0
        static void Main(string[] args)
        {
            // 大起大落
            Task.Run(() =>
            {
                Price24Alert.RunAlert();
            });

            var symbols = CoinUtils.GetAllCommonSymbols("usdt");

            // 空
            //EmptyOrderTask.Run(symbols);

            //ReadAutoBuySellText(symbols);

            //while (true)
            //{
            //    Console.WriteLine("请输入symbol");
            //    var symbol = Console.ReadLine();
            //    Console.WriteLine("请输入big");
            //    var big = Console.ReadLine();
            //    Console.WriteLine("请输入small");
            //    var small = Console.ReadLine();

            //    PriceAlert.RunAlert(symbols.Find(it => it.BaseCurrency == symbol), decimal.Parse(big), decimal.Parse(small));
            //}

            Console.WriteLine("over - over - over");
            Console.ReadLine();
        }
コード例 #6
0
        public static List <CommonSymbol> InitHtData()
        {
            // 准备好各种对
            var symbols = CoinUtils.GetAllCommonSymbols("ht");

            return(symbols.ToList());
        }
コード例 #7
0
        public static List <CommonSymbol> InitEthData(List <string> allPre120)
        {
            // 准备好各种对
            var ethSymbols = CoinUtils.GetAllCommonSymbols("eth");

            ethSymbols.RemoveAll(it => !allPre120.Contains(it.BaseCurrency));
            return(ethSymbols.ToList());
        }
コード例 #8
0
ファイル: BuyOrSellUtils.cs プロジェクト: radtek/PigAuto
        public static void Begin()
        {
            var symbols = CoinUtils.GetAllCommonSymbols();

            RunCoin(symbols.Where(it => it.BaseCurrency != "btc").ToList());
            //var splitIndex = 16;
            //RunCoin(symbols.GetRange(0, splitIndex + 1));
            //RunCoin(symbols.GetRange(splitIndex, symbols.Count - splitIndex));
        }
コード例 #9
0
        public static List <CommonSymbol> InitHtData()
        {
            // 准备好各种对
            var htSymbols = CoinUtils.GetAllCommonSymbols("ht");

            foreach (var symbol in htSymbols)
            {
                KlineUtils.CheckTableExistAndCreate(symbol);
            }
            return(htSymbols.ToList());
        }
コード例 #10
0
ファイル: KlineUtils.cs プロジェクト: radtek/PigAuto
        public static void Begin()
        {
            logger.Info("----------------------  begin  --------------------------------");
            // 初始化
            var symbols = CoinUtils.GetAllCommonSymbols();

            // 定时任务, 不停的获取最新数据, 以供分析使用
            foreach (var symbol in symbols)
            {
                RunHistoryKline(symbol);
            }
        }
コード例 #11
0
        public static void RunAlert()
        {
            var symbols = CoinUtils.GetAllCommonSymbols("usdt");

            Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        foreach (var symbol in symbols)
                        {
                            PlatformApi api = PlatformApi.GetInstance("xx");
                            var period      = "1min";
                            var klines      = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period);

                            var nowPrice = klines[0].Close;
                            // 5分钟内有5%, 或者 15分钟内有10%
                            foreach (var item in klines)
                            {
                                if (Utils.GetDateById(item.Id) > DateTime.Now.AddMinutes(-5) && (
                                        item.Close / nowPrice > (decimal)1.05 || nowPrice / item.Close > (decimal)1.05))
                                {
                                    Console.WriteLine($"{symbol.BaseCurrency}, now:{nowPrice} ->{ item.Close} ");
                                    OpenUrlUtils.Open();
                                }

                                if (Utils.GetDateById(item.Id) > DateTime.Now.AddMinutes(-15) && (
                                        item.Close / nowPrice > (decimal)1.10 || nowPrice / item.Close > (decimal)1.10))
                                {
                                    Console.WriteLine($"{symbol.BaseCurrency}, now:{nowPrice} ->{ item.Close} ");
                                    OpenUrlUtils.Open();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            });
        }
コード例 #12
0
        public async Task <object> DoEmpty(string userName, string symbolName, string quoteCurrency)
        {
            // 立马空单
            var symbols    = CoinUtils.GetAllCommonSymbols("usdt");
            var symbol     = symbols.Find(it => it.BaseCurrency == symbolName);
            var dao        = new KlineDao();
            var lastKlines = dao.List24HourKline(symbol.QuoteCurrency, symbol.BaseCurrency);

            if (Utils.GetDateById(lastKlines[0].Id) < DateTime.Now.AddMinutes(-3))
            {
                // 数据是3分钟前的数据, 不合理.
                return("没有拿到最近3分钟的数据");
            }
            // 大于今天最小值30%才行 or 大于24小时60%  并且大于历史最小的15%
            var control = new DogControlDao().GetDogControl(symbolName, quoteCurrency);

            if (control == null)
            {
                return("没有管控");
            }
            var nowPrice = lastKlines[0].Close;

            if (nowPrice < control.HistoryMin && nowPrice < control.HistoryMin + (control.HistoryMax - control.HistoryMin) * (decimal)0.12)
            {
                return("要大于区间12%");
            }

            var min24    = lastKlines.Min(it => it.Close);
            var minToday = lastKlines.Where(it => Utils.GetDateById(it.Id) >= DateTime.Now.Date).Min(it => it.Close);

            if (nowPrice > min24 * (decimal)1.60 || nowPrice > minToday * (decimal)1.30)
            {
                CoinTrade.DoEmpty(symbol, userName, AccountConfigUtils.GetAccountConfig(userName).MainAccountId);
                return(new { nowPrice, min24, minToday, DoEmpty = true });
            }
            return(new { nowPrice, min24, minToday });
        }
コード例 #13
0
        public static void Begin()
        {
            var symbols = CoinUtils.GetAllCommonSymbols("usdt");

            RunCoin(symbols.Where(it => it.BaseCurrency != "btc" && it.BaseCurrency != "ven").ToList());
        }
コード例 #14
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;
            }
        }
コード例 #15
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;
            }
        }