Skip to content
TheChatArchiveThe Chat Archive
koala-13b· UC BerkeleyHugging Face Arena Human Preference 55K

Write me a c# console app who use binance api to display 4HR BTCUSDT price every 4 hour

  1. User

    Write me a c# console app who use binance api to display 4HR BTCUSDT price every 4 hour

  2. Assistant

    Here's an example of a C# console app that uses the Binance API to display the 4HR BTCUSDT price every 4 hours:

    using System;
    using System.Net;
    using Newtonsoft.Json.Linq;
    
    namespace ConsoleApp
    {
        class Program
        {
            static void Main(string[] args)
            {
                while (true)
                {
                    // Get the current time
                    var currentTime = DateTime.Now;
                    if (currentTime.Hour == 4 && currentTime.Minute == 30)
                    {
                        // Get the 4HR BTCUSDT price from the Binance API
                        var url = "https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT";
                        var client = new WebClient();
                        var response = client.GetStringAsync(url).Result;
                        var json = JObject.Parse(response);
                        var price = json["result"]["c"][0];
    
                        // Display the current price
                        Console.WriteLine("4HR BTCUSDT Price: {0}", price);
                    }
    
                    // Wait for 4 hours
                    System.Threading.Thread.Sleep(240 * 60 * 4);
                }
            }
        }
    }
    
    

    In this example, the app uses the WebClient class to send a GET request to the Binance API to get the 4HR BTCUSDT price. The response is then parsed using the JObject class to extract the price. The price is then displayed on the console every 4 hours using the Console.WriteLine method.