Search code examples
c#apixamarinbinance

Binance api get only USDT pairs - Achieve that by only getting data from symbol that has USDT as the last 4 letters


I have a function here that gets the data from binance api but the problem is, it gets all the trading pairs. I only want to show the ones that ends with USDT in my picker. How do i do that?

        public class Crypto
        {
            public string symbol { get; set; }
            public string price { get; set; }
        }


        private async void GetSymbol()
        {
            HttpClient client = new HttpClient();
            var response = await client.GetStringAsync("https://api.binance.com/api/v3/ticker/price");
            var cryptoconverted = JsonConvert.DeserializeObject<List<Crypto>>(response);
            var sorted = cryptoconverted.OrderBy(x => x.symbol).ToList();
            pairPicker.ItemsSource = sorted;

        }

Solution

  • You can use EndsWith() as a condition inside of Linq Where() method:

     var sorted = cryptoconverted.OrderBy(x => x.symbol).Where(x => x.symbol.EndsWith("USDT")).ToList();