- Getting Started
- Configuring Environment
- HTTP API Requests
- Web Sockets Streams
- Node RPC Requests
- Wallet Management
- Transaction Broadcast
BinanceChain .NET is available on NuGet. To install, go to Visual Studio > Tools > NuGet Package Manager > Package Manager Console.
PM> Install-Package BinanceChain.NET
Binance Chain .NET includes two build in environments by default - TestNet and MainNet. If you would like to configure your own environment, you can do so as follow.
// MainNet
EnvironmentInfo mainnetEnv = EnvironmentInfo.PROD;
var mainnetAPI = BinanceApiFactory.CreateApiClient(mainnetEnv);
// TestNet
EnvironmentInfo testnetEnv = EnvironmentInfo.TESTNET;
var testnetAPI = BinanceApiFactory.CreateApiClient(testnetEnv);
// Custom
EnvironmentInfo customEnv = new EnvironmentInfo("Local", "http://localhost/api", "ws://localhost/api", "cbnb");
var customAPI = BinanceApiFactory.CreateApiClient(customEnv);
To interact with the Binance Chain HTTP API, include the BinanceChain .NET API namespaces in your class.
using BinanceChain.NET.Api;
using BinanceChain.NET.Api.Domain.Requests;
Official HTTP Api documentation: https://docs.binance.org/api-reference/dex-api/paths.html
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetNodeInfo();
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetValidators();
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetPeers();
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetFees();
string address = "{address}";
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetAccount(address);
string address = "{address}";
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetAccountSequence(address);
string hash = "E81BAB8E555819E4211D62E2E536B6D5812D3D91C105F998F5C6EB3AB8136482";
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetTransactionMetadata(hash);
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetNodeInfo();
MarketRequest request = new MarketRequest()
{
Limit = null,
Offset = null
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetMarkets(request);
OrderBookRequest request = new OrderBookRequest()
{
Symbol = "NNB-0AD_BNB",
Limit = null
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetOrderBook(request);
CandlestickBars request = new CandlestickBars()
{
Symbol = "NNB-338_BNB",
Interval = Api.Domain.Intervals.FiveMinute,
Limit = null,
StartTime = null,
EndTime = null
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetCandlestickBars(request);
OpenOrdersRequest request = new OpenOrdersRequest()
{
Address = "{address}",
Limit = null,
Offset = null,
Symbol = null,
Total = null
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetOpenOrders(request);
ClosedOrdersRequest request = new ClosedOrdersRequest()
{
Address = "{address}",
End = null,
Limit = null,
Offset = null,
Side = null,
Start = null,
Symbol = null,
Total = null
};
request.Status.Add(Api.Domain.OrderStatuses.Canceled);
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetClosedOrders(request);
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetOrder("{orderid}");
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.Get24HrPriceStatistics();
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetTrades();
TransactionsRequest request = new TransactionsRequest()
{
Address = "{address}",
BlockHeight = null,
EndTime = null,
Limit = null,
Offset = null,
Side = null,
StartTime = null,
TxAsset = null,
TxType = Api.Domain.TransactionTypes.TRANSFER
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.GetTransactions(request);
string address = "{address}";
var stream = BinanceWebSocketFactory.CreateOrdersStream(EnvironmentInfo.TESTNET);
stream.Subscribe(address);
stream.OnDataReceived += (List<WebSocket.Domain.OrdersData> message) =>
{
Console.WriteLine(message);
};
string address = "{address}";
var stream = BinanceWebSocketFactory.CreateAccountStream(EnvironmentInfo.TESTNET);
stream.Subscribe(address);
stream.OnDataReceived += (List<WebSocket.Domain.AccountData> message) =>
{
Console.WriteLine(message);
};
string address = "{address}";
var stream = BinanceWebSocketFactory.CreateTransferStream(EnvironmentInfo.TESTNET);
stream.Subscribe(address);
stream.OnDataReceived += (WebSocket.Domain.TransferData message) =>
{
Console.WriteLine(message);
};
string address = "{address}";
var stream = BinanceWebSocketFactory.CreateTradesStream(EnvironmentInfo.TESTNET);
stream.Subscribe(address);
stream.OnDataReceived += (List<WebSocket.Domain.TradesData> message) =>
{
Console.WriteLine(message);
};
List<string> symbols = new List<string>();
symbols.Add("BNB_BTC");
var stream = BinanceWebSocketFactory.CreateDiffDepthStream(EnvironmentInfo.TESTNET);
stream.Subscribe(symbols);
stream.OnDataReceived += (WebSocket.Domain.MarketDiffData message) =>
{
Console.WriteLine(message);
};
List<string> symbols = new List<string>();
symbols.Add("BNB_BTC");
var stream = BinanceWebSocketFactory.CreateBookDepthStream(EnvironmentInfo.TESTNET);
stream.Subscribe(symbols);
stream.OnDataReceived += (WebSocket.Domain.MarketDepthData message) =>
{
Console.WriteLine(message);
};
List<string> symbols = new List<string>();
symbols.Add("BNB_BTC");
var stream = BinanceWebSocketFactory.CreateCandlestickStream(EnvironmentInfo.TESTNET);
stream.Subscribe(symbols, WebSocket.Streams.CandlestickStream.KlineIntervals.FiveMinute);
stream.OnDataReceived += (List<WebSocket.Domain.TradesData> message) =>
{
Console.WriteLine(message);
};
List<string> symbols = new List<string>();
symbols.Add("BNB_BTC");
var stream = BinanceWebSocketFactory.CreateTickerStream(EnvironmentInfo.TESTNET);
stream.Subscribe(symbols);
stream.OnDataReceived += (WebSocket.Domain.TickerData message) =>
{
Console.WriteLine(message);
};
var stream = BinanceWebSocketFactory.CreateAllSymbolsTickerStream(EnvironmentInfo.TESTNET);
stream.Subscribe();
stream.OnDataReceived += (List<WebSocket.Domain.TickerData> message) =>
{
Console.WriteLine(message);
};
List<string> symbols = new List<string>();
symbols.Add("BNB_BTC");
var stream = BinanceWebSocketFactory.CreateMiniTickerStream(EnvironmentInfo.TESTNET);
stream.Subscribe(symbols);
stream.OnDataReceived += (WebSocket.Domain.MiniTickerData message) =>
{
Console.WriteLine(message);
};
var stream = BinanceWebSocketFactory.CreateAllSymbolsMiniTickerStream(EnvironmentInfo.TESTNET);
stream.Subscribe();
stream.OnDataReceived += (List<WebSocket.Domain.MiniTickerData> message) =>
{
Console.WriteLine(message);
};
To interact with the Binance Chain Node RPC, include the BinanceChain .NET NodeRPC namespaces in your class.
using BinanceChain.NET.NodeRPC;
using BinanceChain.NET.NodeRPC.Domain.Requests;
Official Node RPC documentation: https://docs.binance.org/api-reference/node-rpc.html
var api = BinanceNodeFactory.CreateNodeClient(EnvironmentInfo.TESTNET_NODE);
var result = api.GetNodeStatus();
var api = BinanceNodeFactory.CreateNodeClient(EnvironmentInfo.TESTNET_NODE);
var result = api.GetABCIInfo();
var api = BinanceNodeFactory.CreateNodeClient(EnvironmentInfo.TESTNET_NODE);
var result = api.GetConsensusState();
var api = BinanceNodeFactory.CreateNodeClient(EnvironmentInfo.TESTNET_NODE);
var result = api.GetDumpConsensusState();
var api = BinanceNodeFactory.CreateNodeClient(EnvironmentInfo.TESTNET_NODE);
var result = api.GetNetInfo();
var api = BinanceNodeFactory.CreateNodeClient(EnvironmentInfo.TESTNET_NODE);
var result = api.GetNumUnconfirmedTxs();
ABCIQueryRequest request = new ABCIQueryRequest()
{
Path = "/store/acc/key",
Data = "6163636F756E743A89F856CB39D25C1BDDAAEC74A381577CA8E2F886"
};
var api = BinanceNodeFactory.CreateNodeClient(EnvironmentInfo.TESTNET_NODE);
var result = api.GetABCIQuery(request);
Wallet wallet = Wallet.NewWallet("testpassword", EnvironmentInfo.TESTNET);
Opening a wallet by mnemonic words
Wallet wallet = Wallet.Open("{mnemonicWords}", "{password}", EnvironmentInfo.TESTNET);
Opening a wallet by private key
Wallet wallet = Wallet.Open("{privateKey}", EnvironmentInfo.TESTNET);
All transactions are signed with your wallet upon broadcast. To broadcast transactions, include the following namespaces in your class.
using BinanceChain.NET.Api.Domain;
using BinanceChain.NET.Api.Domain.Broadcast;
Wallet wallet = Wallet.Open("{privateKey}", EnvironmentInfo.TESTNET);
NewOrder newOrder = new NewOrder()
{
Symbol = "BNB_BTC",
OrderType = OrderTypes.LimitOrder,
Side = OrderSides.Buy,
Price = "10",
Quantity = "1",
TimeInForce = TimeInForce.GoodTillExpire
};
TransactionOption option = new TransactionOption()
{
Memo = null,
Source = 1,
Data = null
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.NewOrder(newOrder, wallet, option);
Wallet wallet = Wallet.Open("{privateKey}", EnvironmentInfo.TESTNET);
Vote vote = new Vote()
{
ProposalId = 1,
Option = 1
};
TransactionOption option = new TransactionOption()
{
Memo = null,
Source = 1,
Data = null
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.Vote(vote, wallet, option);
Wallet wallet = Wallet.Open("{privateKey}", EnvironmentInfo.TESTNET);
CancelOrder cancelOrder = new CancelOrder()
{
Symbol = null,
RefId = null
};
TransactionOption option = new TransactionOption()
{
Memo = null,
Source = 1,
Data = null
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.CancelOrder(cancelOrder, wallet, option);
Wallet wallet = Wallet.Open("{privateKey}", EnvironmentInfo.TESTNET);
Transfer transfer = new Transfer()
{
FromAddress = null,
ToAddress = null,
Coin = null,
Amount = null
};
TransactionOption option = new TransactionOption()
{
Memo = null,
Source = 1,
Data = null
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.Transfer(transfer, wallet, option);
Wallet wallet = Wallet.Open("{privateKey}", EnvironmentInfo.TESTNET);
TokenFreeze tokenFreeze = new TokenFreeze()
{
Symbol = null,
Amount = null
};
TransactionOption option = new TransactionOption()
{
Memo = null,
Source = 1,
Data = null
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.Freeze(tokenFreeze, wallet, option);
Wallet wallet = Wallet.Open("{privateKey}", EnvironmentInfo.TESTNET);
TokenUnfreeze tokenUnfreeze = new TokenUnfreeze()
{
Symbol = null,
Amount = null
};
TransactionOption option = new TransactionOption()
{
Memo = null,
Source = 1,
Data = null
};
var api = BinanceApiFactory.CreateApiClient(EnvironmentInfo.TESTNET);
var result = api.Unfreeze(tokenUnfreeze, wallet, option);