koala-13b· UC Berkeley
Arena Human Preference 55K
Write me a c# console app who use binance api to display 4HR BTCUSDT price every 4 hour
- User
Write me a c# console app who use binance api to display 4HR BTCUSDT price every 4 hour
- 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
WebClientclass to send a GET request to the Binance API to get the 4HR BTCUSDT price. The response is then parsed using theJObjectclass to extract the price. The price is then displayed on the console every 4 hours using theConsole.WriteLinemethod.