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.
Install:
• .NET SDK (7 or later recommended)
• Visual Studio Code
• VS Code extension: C# (by Microsoft)
Then verify your .Net version:
dotnet --version
Open a terminal:
mkdir BinanceClientApp
cd BinanceClientApp
dotnet new console -n BinanceClientApp
cd BinanceClientApp
code .
Install Binance.Net:
dotnet add package Binance.Net
This will also install dependencies like:
• CryptoExchange.Net (core engine)
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).
BinanceClientApp/
├── Program.cs
└── Services/
└── BinanceService.cs
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);
}
}
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var service = new BinanceService();
await service.StartAsync();
}
}
And finally run the application:
dotnet run