Exemple #1
0
        public async Task Buy(string coin, double price, double quantity)
        {
            // Convert to SAT.
            if (price > 1)
            {
                price = price / 100000000;
            }

            ConsoleHelpers.WriteColored($"\tWARNING: GOING TO BUY {quantity:0.00000000} {coin} at a rate of {price:0.00000000}, " +
                                        $"DO YOU WANT TO CONTINUE? (YES/NO) ", ConsoleColor.Yellow);

            if (Console.ReadLine()?.ToLower() == "yes")
            {
                await _bittrexApi.Buy("BTC-" + coin.ToUpper(), quantity, price);

                ConsoleHelpers.WriteColoredLine("\tBuy order placed.", ConsoleColor.Green);
            }
            else
            {
                ConsoleHelpers.WriteColoredLine("\tBuy cancelled.", ConsoleColor.Red);
            }
        }
Exemple #2
0
        /// <summary>
        /// Checks the implemented trading indicator(s),
        /// if one pair triggers the buy signal a new trade record gets created.
        /// </summary>
        /// <param name="trades"></param>
        /// <param name="amountOfBtcToInvestPerTrader"></param>
        /// <returns></returns>
        private async Task <Trade> FindTrade(List <Trade> trades, double amountOfBtcToInvestPerTrader)
        {
            // Get our Bitcoin balance from the exchange
            var currentBtcBalance = await _api.GetBalance("BTC");

            // Do we even have enough funds to invest?
            if (currentBtcBalance < Constants.AmountOfBtcToInvestPerTrader)
            {
                throw new Exception("Insufficient BTC funds to perform a trade.");
            }

            // Retrieve our current markets
            var markets = await _api.GetMarketSummaries();

            // Check if there are markets matching our volume.
            markets = markets.Where(x => (x.BaseVolume > Constants.MinimumAmountOfVolume || Constants.AlwaysTradeList.Contains(x.MarketName)) && x.MarketName.StartsWith("BTC-")).ToList();

            // Remove existing trades from the list to check.
            foreach (var trade in trades)
            {
                markets.RemoveAll(x => x.MarketName == trade.Market);
            }

            // Remove items that are on our blacklist.
            foreach (var market in Constants.MarketBlackList)
            {
                markets.RemoveAll(x => x.MarketName == market);
            }

            // Check the buy signal!
            string pair = null;

            // Prioritize markets with high volume.
            foreach (var market in markets.Distinct().OrderByDescending(x => x.BaseVolume).ToList())
            {
                if (await GetBuySignal(market.MarketName))
                {
                    // A match was made, buy that please!
                    pair = market.MarketName;
                    break;
                }
            }

            // No pairs found. Return.
            if (pair == null)
            {
                return(null);
            }

            var openRate     = GetTargetBid(await _api.GetTicker(pair));
            var amount       = amountOfBtcToInvestPerTrader / openRate;
            var amountYouGet = (amountOfBtcToInvestPerTrader * (1 - Constants.TransactionFeePercentage)) / openRate;
            var orderId      = await _api.Buy(pair, openRate, amount);

            return(new Trade()
            {
                Market = pair,
                StakeAmount = Constants.AmountOfBtcToInvestPerTrader,
                OpenRate = openRate,
                OpenDate = DateTime.UtcNow,
                Quantity = amountYouGet,
                OpenOrderId = orderId,
                BuyOrderId = orderId,
                IsOpen = true,
                StrategyUsed = _strategy.Name,
                PartitionKey = "TRADE",
                SellType = SellType.None,
                RowKey = $"MNT{(DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks):d19}"
            });
        }