Exemple #1
0
        public Service(EtherDeltaConfiguration config, ILogger configLogger)
        {
            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 addressEtherDelta = Web3.ToChecksumAddress(config.AddressEtherDelta);

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

            EtherDeltaContract = Web3.Eth.GetContract(abi, addressEtherDelta);

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

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

            InitSocket();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // Tells us which bot program to run
            if (args.Length < 1 || args[0] != "taker" && args[0] != "maker" && args[0] != "custom")
            {
                Console.WriteLine("Please run with 'taker' or 'maker' or 'custom' argument!");
                return;
            }

            // maps the configuration file information to a model
            var config = new EtherDeltaConfiguration
            {
                SocketUrl         = ConfigurationManager.AppSettings["SocketUrl"],
                Provider          = ConfigurationManager.AppSettings["Provider"],
                AddressEtherDelta = ConfigurationManager.AppSettings["AddressEtherDelta"],
                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     = new BigInteger(UInt64.Parse(ConfigurationManager.AppSettings["GasPrice"])),
                GasLimit     = new BigInteger(UInt64.Parse(ConfigurationManager.AppSettings["GasLimit"]))
            };

            // create a console logger if in verbose mode
            ILogger logger = null;

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

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

            Console.ReadLine();
        }
        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 EtherDeltaConfiguration
            {
                SocketUrl         = ConfigurationManager.AppSettings["SocketUrl"],
                Provider          = ConfigurationManager.AppSettings["Provider"],
                AddressEtherDelta = ConfigurationManager.AppSettings["AddressEtherDelta"],
                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     = new BigInteger(UInt64.Parse(ConfigurationManager.AppSettings["GasPrice"])),
                GasLimit     = new BigInteger(UInt64.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);
            }
        }
Exemple #4
0
        public BaseBot(EtherDeltaConfiguration config, ILogger logger = null)
        {
            Console.Clear();
            Console.ResetColor();
            Service = new Service(config, logger);

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

            Task.WaitAll(tasks);

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

            Console.WriteLine();
        }
Exemple #5
0
        public Taker(EtherDeltaConfiguration config, ILogger logger = null) : base(config, logger)
        {
            var order = Service.GetBestAvailableSell();

            if (order != null)
            {
                Console.WriteLine($"Best available: Sell {order.EthAvailableVolume.ToString("N3")} @ {order.Price.ToString("N9")}");
                var 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;
                    if (ex.InnerException != null)
                    {
                        Console.WriteLine(ex.InnerException.Message);
                    }
                    else
                    {
                        Console.WriteLine(ex.Message);
                    }
                    Console.ResetColor();
                }
            }
            else
            {
                Console.WriteLine("No Available order");
            }

            Console.WriteLine();
        }
Exemple #6
0
        public Maker(EtherDeltaConfiguration config, ILogger logger = null) : base(config, logger)
        {
            PrintMyOrders();

            var ordersPerSide     = 1;
            var expires           = Service.GetBlockNumber().Result + 10;
            var buyOrdersToPlace  = ordersPerSide - Service.MyOrders.Buys.Count();
            var sellOrdersToPlace = ordersPerSide - Service.MyOrders.Sells.Count();
            var buyVolumeToPlace  = EtherDeltaETH;
            var sellVolumeToPlace = EtherDeltaToken;
            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.ToString("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.ToString("N3")} @ { price.ToString("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;
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
                else
                {
                    Console.WriteLine(ex.Message);
                }
                Console.ResetColor();
            }

            Console.WriteLine("Done");
        }