BinanceAPI.NET
26.1.0.35
See the version list below for details.
dotnet add package BinanceAPI.NET --version 26.1.0.35
NuGet\Install-Package BinanceAPI.NET -Version 26.1.0.35
<PackageReference Include="BinanceAPI.NET" Version="26.1.0.35" />
paket add BinanceAPI.NET --version 26.1.0.35
#r "nuget: BinanceAPI.NET, 26.1.0.35"
// Install BinanceAPI.NET as a Cake Addin
#addin nuget:?package=BinanceAPI.NET&version=26.1.0.35
// Install BinanceAPI.NET as a Cake Tool
#tool nuget:?package=BinanceAPI.NET&version=26.1.0.35
Authentication
Create an Authentication Provider
that can be used by multiple Rest Clients
AuthenticationProvider authenticationProvider = new AuthenticationProvider(api_key, api_secret);
Create Rest Client
Change the Rest Client Options
and create a new Rest Client
using the Authentication Provider
above
RestClientOptions restClientOptions = new()
{
SyncUpdateTime = 5,
GetCacheSize = 2048,
PutCacheSize = 2048,
PostCacheSize = 2048,
DeleteCacheSize = 2048,
ReceiveWindow = TimeSpan.FromMilliseconds(1000),
DefaultApiController = BinanceApiController.DEFAULT
};
RestClient restClient = new RestClient(authenticationProvider, restClientOptions, CancellationToken.None);
Create Socket Client
Create a Socket Client
that can be used to Connect/Subscribe
to Websocket Streams
Returns a SocketClientHost
that can be used to manage the connection.
SocketClient socketClient = new SocketClient(50);
SocketClientHost example = socketClient.Subscribe.SymbolMiniTickerUpdates(...);
example.ConnectionStatusChanged += BinanceSocket_StatusChanged;
example.ReconnectSocket();
example.DestroySocket();
50
is the default number of Reconnect Attempts
before the socket will Fail
Server Time Client
The Server Time Client
is used to produce high quality Timestamps
for requests by guessing the Server Time
You don't need to sync your clock or use any external tools, etc.
Wait for Start
You must wait for the Server Time Client
to start before you can make requests that require a Timestamp
if (!ServerTimeClient.IsReady())
{
await ServerTimeClient.WaitForStart(serverTimeStartWaitToken.Token).ConfigureAwait(false);
}
Requests
will automatically use the ServerTimeClient
, you don't need to do anything.
Get Server Time
Get the current Server Time Guess
according to the Server Time Client
so you can display it on a UI
ServerTimeClient.ServerTimeTicks
Cache Client
The library provides objects so that certain data about orders can be cached for fast access to order placement endpoints.
You are responsible for creating the cache and storing the Cachable
objects for orders
CachableSpotRequest
Create a spot order request so it can be cached and reused
CachableSpotRequest cachableSpotRequest = CacheClientSpot.CreateOrderLimit();
CachableMarginRequest
Create a margin order request so it can be cached and reused
CachableMarginRequest cachableMarginRequest = CacheClientMargin.CreateMarginOrderLimit();
Order Endpoints
Spot Orders
CreateOrderLimit
Create a new cachable limit order that can be used in multiple future requests
CachableSpotRequest order = CacheClientSpot.CreateOrderLimit();
CreateOrderMarket
Create a new cachable market order that can be used in multiple future requests
CachableSpotRequest order = CacheClientSpot.CreateOrderMarket();
PlaceOrderSpotCached
Place a Spot Order
from data that can be cached
CachableSpotRequest order = CacheClientSpot.CreateOrderMarket(symbolName, orderSide, orderQuantity, recvWindow);
RestResult<BinancePlacedOrderSpot> result = restClient.Spot.Order.PlaceOrderSpot(ref order);
Place a Spot Order
from data that can be cached and also return a copy of the raw response
RestResultRaw<BinancePlacedOrderSpot> result = restClient.Spot.Order.PlaceOrderSpotRaw(ref order, ref request);
PlaceTestOrder
Places a new test order.
Test orders are not actually being executed and just test the functionality.
CachableSpotRequest spotRequest = CacheClientSpot.CreateOrderMarket("BTCUSDT", OrderSide.Sell, 1, 1000);
RestResult<BinancePlacedOrderSpot> result = restClient.Spot.Order.PlaceTestOrder(ref spotRequest);
GetOrder
Retrieves data for a specific order.
Either orderId
or origClientOrderId
should be provided.
restClient.Spot.Order.GetOrder();
GetOrders
Gets all orders for the provided symbol
restClient.Spot.Order.GetOrders();
GetOpenOrders
Gets a list of open orders
restClient.Spot.Order.GetOpenOrders();
GetUserTrades
Gets all user trades for provided symbol
restClient.Spot.Order.GetUserTrades();
CancelOrder
Cancels a pending order on a symbol
restClient.Spot.Order.CancelOrder();
CancelAllOpenOrders
Cancels all open orders on a symbol
restClient.Spot.Order.CancelAllOpenOrders()
Margin/Isolated Orders
CreateOrderLimit
Create a new cachable limit order that can be used in multiple future requests
CachableMarginRequest order = CacheClientMargin.CreateMarginOrderLimit();
CreateOrderMarket
Create a new cachable market order that can be used in multiple future requests
CachableMarginRequest order = CacheClientMargin.CreateMarginOrderMarket();
PlaceOrderMarginCached
Place a Margin Order
from data that can be cached
CachableMarginRequest order = CacheClientMargin.CreateMarginOrderMarket(symbolName, orderSide, orderQuantity, recvWindow);
RestResult<BinancePlacedOrderMargin> result = restClient.Margin.Order.PlaceOrderMargin(ref order);
Place a Margin Order
from data that can be cached and also return a copy of the raw response
RestResultRaw<BinancePlacedOrderMargin> result = restClient.Margin.Order.PlaceOrderMarginRaw(ref order, ref request);
GetMarginAccountOrder
Retrieves data for a specific margin account order.
Either orderId
or origClientOrderId
should be provided.
restClient.Margin.Order.GetMarginAccountOrder();
GetMarginAccountOrders
Gets all margin account orders for the provided symbol
restClient.Margin.Order.GetMarginAccountOrders();
GetMarginAccountOpenOrders
Gets a list of open margin account orders
restClient.Margin.Order.GetMarginAccountOpenOrders();
GetMarginAccountUserTrades
Gets all user margin account trades for provided symbol
restClient.Margin.Order.GetMarginAccountUserTrades();
CancelMarginOrder
Cancel an active order for margin account
restClient.Margin.Order.CancelMarginOrder();
CancelOpenMarginOrders
Cancel all active orders for a symbol
restClient.Margin.Order.CancelOpenMarginOrders();
Account Endpoints
General
GetAccountInfo
Gets the account information, including balances
restClient.General.GetAccountInfo();
GetAccountStatus
Gets the status of the account associated with the api key/secret
restClient.General.GetAccountStatus();
GetDailySpotAccountSnapshot
Get a daily account snapshot (balances)
restClient.General.GetDailySpotAccountSnapshot();
Margin
Transfer
Execute transfer between spot account and cross margin account.
restClient.Margin.System.Transfer();
GetMarginAccountInfo
Query margin account details
restClient.Margin.System.GetMarginAccountInfo();
GetMarginLevelInformation
Get personal margin level information for your account
restClient.Margin.System.GetMarginLevelInformation();
GetTransferHistory
Get history of transfers
restClient.Margin.System.GetTransferHistory();
GetForceLiquidationHistory
Get history of forced liquidations
restClient.Margin.System.GetForceLiquidationHistory();
GetMaxTransferAmount
Query max transfer-out amount
restClient.Margin.System.GetMaxTransferAmount();
Isolated
EnableIsolatedMarginAccount
Enable an isolated margin account
restClient.Margin.System.EnableIsolatedMarginAccount();
GetIsolatedMarginAccount
Isolated margin account info
restClient.Margin.System.GetIsolatedMarginAccount();
GetEnabledIsolatedMarginAccountLimit
Get max number of enabled isolated margin accounts
restClient.Margin.System.GetEnabledIsolatedMarginAccountLimit();
GetInterestIsolatedMarginData
Get interest isolated margin data
restClient.Margin.System.GetInterestIsolatedMarginData();
DisableIsolatedMarginAccount
Disable an isolated margin account
restClient.Margin.System.DisableIsolatedMarginAccount();
Lending Endpoints
Borrow
Borrow. Apply for a loan.
restClient.Lending.Borrow();
Repay
Repay loan for margin account.
restClient.Lending.Repay();
GetLoans
Query loan records
restClient.Lending.GetLoans();
GetRepays
Query repay records
restClient.Lending.GetRepays();
GetMaxBorrowAmount
Query max borrow amount
restClient.Lending.GetMaxBorrowAmount();
GetInterestHistory
Get history of interest
restClient.Lending.GetInterestHistory();
GetInterestRateHistory
Get history of interest rates
restClient.Lending.GetInterestRateHistory();
GetInterestMarginData
Get interest margin data
restClient.Lending.GetInterestMarginData();
Market Endpoints
Spot
GetTicker
Get data regarding the last 24 hours for the provided symbol
restClient.Spot.Market.GetTicker();
GetTickers
Get data regarding the last 24 hours for all symbols
restClient.Spot.Market.GetTickers();
GetAggTradeHistory
Gets compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.
restClient.Spot.Market.GetAggregatedTradeHistory();
GetCurrentAvgPrice
Gets current average price for a symbol
restClient.Spot.Market.GetCurrentAvgPrice();
GetKlines
Get candlestick data for the provided symbol
restClient.Spot.Market.GetKlines();
GetTradeHistory
Gets the historical trades for a symbol
restClient.Spot.Market.GetTradeHistory();
GetRecentTradeHistory
Gets the recent trades for a symbol
restClient.Spot.Market.GetRecentTradeHistory();
GetBookPrice
Gets the best price/quantity on the order book for a symbol.
restClient.Spot.Market.GetBookPrice();
GetAllBookPrices
Gets the best price/quantity on the order book for all symbols.
restClient.Spot.Market.GetAllBookPrices();
GetPrice
Gets the price of a symbol
restClient.Spot.Market.GetPrice();
GetAllPrices
Get a list of the prices of all symbols
restClient.Spot.Market.GetAllPrices();
GetTradeFee
Gets the trade fee for a symbol
restClient.Spot.Market.GetTradeFee();
Margin
GetMarginAsset
Get a margin asset
restClient.Margin.Market.GetMarginAsset();
GetAllMarginAssets
Get all assets available for margin trading
restClient.Margin.Market.GetAllMarginAssets();
GetMarginPair
Get a margin pair
restClient.Margin.Market.GetMarginPair();
GetAllMarginPairs
Get all asset pairs available for margin trading
restClient.Margin.Market.GetAllMarginPairs();
GetMarginPriceIndex
Get margin price index
restClient.Margin.Market.GetMarginPriceIndex();
Isolated
GetIsolatedSymbol
Isolated margin symbol info for a specific symbol
restClient.Margin.Market.GetIsolatedMarginSymbol();
GetAllIsolatedSymbols
Isolated margin symbol info for all symbols
restClient.Margin.Market.GetAllIsolatedMarginSymbols();
Userstream Endpoints
Spot
StartUserStream
Starts a user stream by requesting a listen key.
This listen key can be used in subsequent requests to SubscribeToUserDataUpdates
The stream will close after 60 minutes unless a keep alive is send.
restClient.Spot.UserStream.StartUserStream();
KeepAliveUserStream
Sends a keep alive for the current user stream listen key to keep the stream from closing.
Stream auto closes after 60 minutes if no keep alive is send.
30 minute interval for keep alive is recommended.
restClient.Spot.UserStream.KeepAliveUserStream();
StopUserStream
Stops the current user stream
restClient.Spot.UserStream.StopUserStream();
Margin
StartUserStream
Starts a user stream for margin account by requesting a listen key.
This listen key can be used in subsequent requests to SubscribeToUserDataUpdates
The stream will close after 60 minutes unless a keep alive is send.
restClient.Margin.UserStream.StartUserStream();
KeepAliveUserStream
Sends a keep alive for the current user stream for margin account listen key to keep the stream from closing.
Stream auto closes after 60 minutes if no keep alive is send. 30 minute interval for keep alive is recommended.
restClient.Margin.UserStream.KeepAliveUserStream();
StopUserStream
Close the user stream for the cross margin account
restClient.Margin.UserStream.StopUserStream();
Isolated
StartIsolatedUserStream
Starts a user stream for margin account by requesting a listen key.
This listen key can be used in subsequent requests to SubscribeToUserDataUpdates
The stream will close after 60 minutes unless a keep alive is send.
restClient.Margin.IsolatedUserStream.StartIsolatedMarginUserStream();
KeepAliveIsolatedUserStream
Sends a keep alive for the current user stream for margin account listen key to keep the stream from closing.
Stream auto closes after 60 minutes if no keep alive is send. 30 minute interval for keep alive is recommended.
restClient.Margin.IsolatedUserStream.KeepAliveIsolatedMarginUserStream();
CloseIsolatedUserStream
Close the user stream for the isolated margin account
restClient.Margin.IsolatedUserStream.StopIsolatedMarginUserStream();
Common Endpoints
SetBnbBurnStatus
Sets the status of the BNB burn switch for spot trading and margin interest
restClient.General.SetBnbBurnStatus();
DustTransfer
Converts dust (small amounts of) assets to BNB
restClient.General.DustTransfer();
GetFundingWallet
Get funding wallet assets
restClient.General.GetFundingWallet();
Transfer
Transfers between accounts
restClient.General.Transfer();
GetUserCoins
Gets information of coins for a user
restClient.General.GetUserCoins();
GetAssetDividendRecords
Get asset dividend records
restClient.General.GetAssetDividendRecords();
GetBnbBurnStatus
Gets the status of the BNB burn switch for spot trading and margin interest
restClient.General.GetBnbBurnStatus();
GetServerTimeTicks
Get the server time ticks as reported by the binance server
long stt = await ServerTimeClient.GetServerTimeTicks().ConfigureAwait(false);
GetDustLog
Gets the history of dust conversions
restClient.General.GetDustLog();
GetExchangeInfo
Get's information about the exchange including rate limits and information on the provided symbol or symbols
restClient.Spot.System.GetExchangeInfo();
GetSystemStatus
Gets the status of the Binance platform
restClient.Spot.System.GetSystemStatus();
Ping
Pings the Binance API
restClient.Spot.System.Ping();
GetTradingStatus
Gets the trading status for the current account
restClient.General.GetTradingStatus();
GetTransfers
Get universal transfer history
restClient.General.GetTransfers();
Websocket Streams
User Data Streams
Subscribes to the account update stream. Prior to using this, one of the StartUserStream
methods should be called.
socketClient.UserDataStreams.Updates();
SymbolTickerUpdates
Subscribes to ticker updates stream for a specific symbol
socketClient.Subscribe.SymbolTickerUpdates()
AggregatedTradeUpdates
Subscribes to the aggregated trades update stream for the provided symbol
socketClient.Subscribe.AggregatedTradeUpdates()
TradeUpdates
Subscribes to the trades update stream for the provided symbol
socketClient.Subscribe.TradeUpdates()
KlineUpdates
Subscribes to the candlestick update stream for the provided symbols and intervals
socketClient.Subscribe.KlineUpdates()
SymbolMiniTickerUpdates
Subscribes to mini ticker updates stream for a specific symbol or symbols
socketClient.Subscribe.SymbolMiniTickerUpdates()
AllSymbolMiniTickerUpdates
Subscribes to mini ticker updates stream for all symbols
socketClient.Subscribe.AllSymbolMiniTickerUpdates()
BookTickerUpdates
Subscribes to the book ticker update stream for the provided symbol or symbols
socketClient.Subscribe.BookTickerUpdates()
AllBookTickerUpdates
Subscribes to the book ticker update stream for all symbols
socketClient.Subscribe.AllBookTickerUpdates()
SymbolTickerUpdates
Subscribes to ticker updates stream for a specific symbol or symbols
socketClient.Subscribe.SymbolTickerUpdates()
AllSymbolTickerUpdates
Subscribes to ticker updates stream for all symbols
socketClient.Subscribe.AllSymbolTickerUpdates()
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- AsyncBlocker.NET (>= 1.0.1.4)
- BinanceObjects (>= 1.0.7.62)
- BinanceUriCache (>= 1.0.2.4)
- High_Resolution_Sleep (>= 1.1.2.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
This update
-----
Small optimization to RestClient
Update BinanceObjects package to v1.0.7.62
Recent
-----
CachableHttpRequestMessagePost is no longer required when placing orders
Improved CacheClient
Add Exception to RestError, Exception will have a value if the error was caused by an Exception
Add GetCacheSize to RestClientOptions
Add PostCacheSize to RestClientOptions
Add PutCacheSize to RestClientOptions
Add DeleteCacheSize to RestClientOptions
Add DeleteCache
Add GetCache
Add PostCache
Add PutCache
Remove SetNewAuthentication
Breaking changes can be fixed by looking at the Documentation/README for this version