Beispiel #1
0
        public Taker(RyxExConfiguration config, ILogger logger = null) : base(config, logger)
        {
            var order = Service.GetBestAvailableSell();

            if (order != null)
            {
                Console.WriteLine($"Best available: Sell {order.EthAvailableVolume:N3} @ {order.Price:N9}");
                const decimal desiredAmountBase = 0.001m;

                var fraction = Math.Min(desiredAmountBase / order.EthAvailableVolumeBase, 1);
                try
                {
                    var uc     = new UnitConversion();
                    var amount = order.AmountGet.Value * uc.ToWei(fraction);
                    Service.TakeOrder(order, amount).Wait();
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
                    Console.ResetColor();
                }
            }
            else
            {
                Console.WriteLine("No Available order");
            }

            Console.WriteLine();
        }
Beispiel #2
0
        public Service(RyxExConfiguration config, ILogger configLogger)
        {
            this._logger = configLogger;
            Log("Starting");

            Orders = new Orders
            {
                Sells = new List <Order>(),
                Buys  = new List <Order>()
            };

            MyOrders = new Orders
            {
                Sells = new List <Order>(),
                Buys  = new List <Order>()
            };

            Trades   = new List <Trade>();
            MyTrades = new List <Trade>();

            Config = config;
            Web3   = new Web3(config.Provider);
            var addressRyxEx = Web3.ToChecksumAddress(config.AddressRyxEx);

            // TODO: check file exists
            var abi = File.ReadAllText(config.AbiFile);

            RyxExContract = Web3.Eth.GetContract(abi, addressRyxEx);

            var tokenAbi = File.ReadAllText(config.TokenFile);

            EthContract = Web3.Eth.GetContract(tokenAbi, Config.Token);

            InitSocket();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            if (args.Length < 1 || args[0] != "taker" && args[0] != "maker")
            {
                Console.WriteLine("Please run with 'taker' or 'maker' argument!");
                return;
            }

            var config = new RyxExConfiguration
            {
                SocketUrl    = ConfigurationManager.AppSettings["SocketUrl"],
                Provider     = ConfigurationManager.AppSettings["Provider"],
                AddressRyxEx = ConfigurationManager.AppSettings["AddressRyxEx"],
                AbiFile      = ConfigurationManager.AppSettings["AbiFile"],
                TokenFile    = ConfigurationManager.AppSettings["TokenFile"],
                Token        = ConfigurationManager.AppSettings["Token"],
                User         = ConfigurationManager.AppSettings["User"],
                PrivateKey   = ConfigurationManager.AppSettings["PrivateKey"],
                UnitDecimals = int.Parse(ConfigurationManager.AppSettings["UnitDecimals"]),
                GasPrice     = BigInteger.Parse(ConfigurationManager.AppSettings["GasPrice"]),
                GasLimit     = BigInteger.Parse(ConfigurationManager.AppSettings["GasLimit"])
            };

            ILogger logger = null;

            if (args.Length == 2 && args[1] == "-v")
            {
                logger = new ConsoleLogger();
            }

            if (args[0] == "taker")
            {
                new Taker(config, logger);
            }
            else
            {
                new Maker(config, logger);
            }

            if (!Debugger.IsAttached)
            {
                return;
            }

            Console.WriteLine("Press enter to exit");
            while (Console.ReadKey().Key != ConsoleKey.Enter)
            {
                ;
            }
        }
Beispiel #4
0
        protected BaseBot(RyxExConfiguration config, ILogger logger = null)
        {
            Console.Clear();
            Console.ResetColor();
            Service = new Service(config, logger);

            Task[] tasks =
            {
                GetMarket(),
                GetBalanceAsync("ETH",       config.User),
                GetBalanceAsync(config.Token,config.User),
                GetRyxExBalance("ETH",       config.User),
                GetRyxExBalance(config.Token,config.User)
            };

            Task.WaitAll(tasks);

            PrintOrders();
            PrintTrades();
            PrintWallet();

            Console.WriteLine();
        }
Beispiel #5
0
        public Maker(RyxExConfiguration config, ILogger logger = null) : base(config, logger)
        {
            PrintMyOrders();

            const int ordersPerSide     = 1;
            var       expires           = Service.GetBlockNumber().Result + 10;
            var       buyOrdersToPlace  = ordersPerSide - Service.MyOrders.Buys.Count();
            var       sellOrdersToPlace = ordersPerSide - Service.MyOrders.Sells.Count();
            var       buyVolumeToPlace  = RyxExETH;
            var       sellVolumeToPlace = RyxExToken;
            var       bestBuy           = Service.GetBestAvailableBuy();
            var       bestSell          = Service.GetBestAvailableSell();

            if (bestBuy == null || bestSell == null)
            {
                Console.WriteLine("Market is not two-sided, cannot calculate mid-market");
                return;
            }

            // Make sure we have a reliable mid market
            if (Math.Abs((bestBuy.Price - bestSell.Price) / (bestBuy.Price + bestSell.Price) / 2) > 0.05m)
            {
                Console.WriteLine("Market is too wide, will not place orders");
                return;
            }

            var uc = new UnitConversion();

            var midMarket = (bestBuy.Price + bestSell.Price) / 2;
            var orders    = new List <Order>();

            for (var i = 0; i < sellOrdersToPlace; i += 1)
            {
                var price  = midMarket + ((i + 1) * midMarket * 0.05m);
                var amount = sellVolumeToPlace / sellOrdersToPlace;
                Console.WriteLine($"Sell { amount.ToString("N3")} @ { price:N9}");
                try
                {
                    var order = Service.CreateOrder(OrderType.Sell, expires, uc.ToWei(price), amount);
                    orders.Add(order);
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex.Message);
                    Console.ResetColor();
                }
            }

            for (var i = 0; i < buyOrdersToPlace; i += 1)
            {
                var price  = midMarket - ((i + 1) * midMarket * 0.05m);
                var amount = uc.FromWei(buyVolumeToPlace) / price / buyOrdersToPlace;
                Console.WriteLine($"Buy { amount:N3} @ { price:N9}");
                try
                {
                    var order = Service.CreateOrder(OrderType.Buy, expires, uc.ToWei(price), uc.ToWei(amount));
                    orders.Add(order);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            var orderTasks = new List <Task>();

            orders.ForEach(order =>
            {
                var amount = order.TokenGive == Service.ZeroToken ? order.AmountGet : order.AmountGive;
                orderTasks.Add(Service.TakeOrder(order, amount));
            });

            try
            {
                Task.WaitAll(orderTasks.ToArray());
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
                Console.ResetColor();
            }

            Console.WriteLine("Done");
        }