Create a C# app to subscribe live BTCUSDT data with Binance Client Library
In this page, I will describe how to create an application using C# from Visual Code that connects to the Binance Test network with Binance Client Library, subscribes to BTCUSDT data, and tracks the price changes of the symbol.
If you need WebSockets to subscribe, follow Binance WebSocket tutorial.
1. Prerequisites
Install:
• .NET SDK (7 or later recommended)
• Visual Studio Code
• VS Code extension: C# (by Microsoft)
Then verify your .Net version:
dotnet --version
2. Create Solution + Console Project
Open a terminal:
mkdir BinanceClientApp
cd BinanceClientApp
dotnet new console -n BinanceClientApp
cd BinanceClientApp
code .
3. Install Binance Client Library
Install Binance.Net:
dotnet add package Binance.Net
This will also install dependencies like:
• CryptoExchange.Net (core engine)
4. Understand Testnet vs Production
By default, the library connects to real Binance.
You must explicitly enable Testnet:
options.SpotApiOptions.BaseAddress = "https://testnet.binance.vision";
options.SpotApiOptions.BaseAddress = "wss://testnet.binance.vision";
But the library provides a cleaner way (shown below).
5. Project Structure (Simple but Clean)
BinanceClientApp/
├── Program.cs
└── Services/
└── BinanceService.cs
6. Create Binance Service
Create: Services/BinanceService.cs
using System;
using System.Threading.Tasks;
using Binance.Net.Clients;
using Binance.Net.Enums;
using CryptoExchange.Net.Authentication;
using Binance.Net.Objects;
public class BinanceService
{
private readonly BinanceSocketClient _socketClient;
public BinanceService()
{
_socketClient = new BinanceSocketClient(options =>
{
options.Environment = BinanceEnvironment.Testnet;
});
}
public async Task StartAsync()
{
Console.WriteLine("Connecting to Binance Testnet...");
var result = await _socketClient.SpotApi.ExchangeData.SubscribeToTradeUpdatesAsync(
"BTCUSDT",
data =>
{
Console.WriteLine(
$"[{DateTime.Now}] {data.Data.Symbol} Price: {data.Data.Price} Qty: {data.Data.Quantity}");
});
if (!result.Success)
{
Console.WriteLine("Subscription failed: " + result.Error);
return;
}
Console.WriteLine("Subscribed to BTCUSDT trades.");
// Keep app alive
await Task.Delay(-1);
}
}
7. Update Program.cs
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var service = new BinanceService();
await service.StartAsync();
}
}
8. Run the Application
And finally run the application:
dotnet run