2026-06-09 14:32:05 +02:00
|
|
|
using System.Globalization;
|
2026-06-17 01:49:11 +02:00
|
|
|
using Wickra;
|
2026-06-09 14:32:05 +02:00
|
|
|
|
|
|
|
|
// Download real BTCUSDT hourly klines from the Binance REST API into a CSV that the
|
2026-06-17 01:49:11 +02:00
|
|
|
// other examples can consume, using Wickra's native fetcher — no third-party HTTP or
|
|
|
|
|
// JSON library. Requires network access (build-only in CI).
|
|
|
|
|
Console.WriteLine("Fetching 500 BTCUSDT 1h klines from Binance...");
|
2026-06-09 14:32:05 +02:00
|
|
|
|
2026-06-17 01:49:11 +02:00
|
|
|
var klines = BinanceFeed.FetchKlines("BTCUSDT", BinanceInterval.OneHour, 500);
|
2026-06-09 14:32:05 +02:00
|
|
|
|
|
|
|
|
var dir = Path.Combine(AppContext.BaseDirectory, "data");
|
|
|
|
|
Directory.CreateDirectory(dir);
|
|
|
|
|
var path = Path.Combine(dir, "btcusdt_1h.csv");
|
|
|
|
|
|
|
|
|
|
using var writer = new StreamWriter(path);
|
|
|
|
|
writer.WriteLine("timestamp,open,high,low,close,volume");
|
2026-06-17 01:49:11 +02:00
|
|
|
foreach (var k in klines)
|
2026-06-09 14:32:05 +02:00
|
|
|
{
|
2026-06-17 01:49:11 +02:00
|
|
|
writer.WriteLine(string.Create(CultureInfo.InvariantCulture,
|
|
|
|
|
$"{(long)k.Timestamp},{k.Open},{k.High},{k.Low},{k.Close},{k.Volume}"));
|
2026-06-09 14:32:05 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-17 01:49:11 +02:00
|
|
|
Console.WriteLine($"Wrote {klines.Length} klines to {path}");
|