/// <summary>
        /// List everything that gives a positive trade signal.
        /// </summary>
        private async Task <List <string> > ListTrades()
        {
            var results = new List <string>();

            // 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 items that are on our blacklist.
            foreach (var market in Constants.MarketBlackList)
            {
                markets.RemoveAll(x => x.MarketName == market);
            }

            // Prioritize markets with high volume.
            foreach (var market in markets.Distinct().OrderByDescending(x => x.BaseVolume).ToList())
            {
                try
                {
                    var trend = await GetTrend(market.MarketName);

                    if (trend.Count > 0 && trend.Last() == 1)
                    {
                        // A match was made, buy that please!
                        results.Add(market.MarketName);
                    }
                }
                catch {
                    // Couldn't get a trend, no worries, move on.
                }
            }

            return(results);
        }
Beispiel #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}"
            });
        }
 private void btnMarketSummary_Click(object sender, RoutedEventArgs e)
 {
     coinsgrd.ItemsSource = BittrexApi.GetMarketSummaries().result;
 }