BinanceAPI.NET
16.0.0.7
Please update to the most recent version to benefit from cache improvements
See the version list below for details.
dotnet add package BinanceAPI.NET --version 16.0.0.7
NuGet\Install-Package BinanceAPI.NET -Version 16.0.0.7
<PackageReference Include="BinanceAPI.NET" Version="16.0.0.7" />
paket add BinanceAPI.NET --version 16.0.0.7
#r "nuget: BinanceAPI.NET, 16.0.0.7"
// Install BinanceAPI.NET as a Cake Addin
#addin nuget:?package=BinanceAPI.NET&version=16.0.0.7
// Install BinanceAPI.NET as a Cake Tool
#tool nuget:?package=BinanceAPI.NET&version=16.0.0.7
Server Time Client
The Server Time Client
is used to produce high quality Timestamps
for requests
Unlike other libraries BinanceAPI.NET
deals completely in remote time, The local time doesn't matter and you don't need to sync your clock etc or use any external tools or the windows time service etc.
You do however have to wait for the Server Time Client
to start before you can make requests, It should start instantly but you can also wait to be sure.
if (!ServerTimeClient.IsReady())
{
await ServerTimeClient.WaitForStart(serverTimeStartWaitToken.Token).ConfigureAwait(false);
}
Authentication
AuthenticationProvider authenticationProvider = new AuthenticationProvider(api_key, api_secret);
RestClient restClient = new RestClient(authenticationProvider, serverTimeStartWaitToken.Token);
Change Keys/Provider
restClient.SetNewAuthentication(authenticationProvider);
Change Controller
When you aren't making requests you can change the endpoint controller
BaseClient.SetEndpointController = BinanceApiController.ONE;
Default Options Socket Client
Change default options for socket clients
SocketClient.SetDefaultOptions(new SocketClientHostOptions()
{
LogLevel = SimpleLogLevel.Debug,
LogPath = socketLogs,
LogToConsole = false,
MaxReconnectTries = 50
});
Default Options Rest Client
Change the default options for Rest Clients
RestClient.SetDefaultOptions(new RestClientOptions()
{
LogLevel = SimpleLogLevel.Debug,
LogPath = clientLogs,
TimeLogPath = timeLogs,
LogToConsole = true,
SyncUpdateTime = 15,
ReceiveWindow = TimeSpan.FromMilliseconds(1000)
});
Create Rest Client
Create a rest client to make requests
RestClient restClient = new RestClient(serverTimeStartWaitToken.Token);
Create Socket Client
Create a socket client to connect/subscribe to sockets
SocketClient socketClient = new SocketClient();
Get the Server Time Ticks
Get the current Server Time Guess
according to the Server Time Client
ServerTimeClient.ServerTimeTicks
Account Endpoints
General
GetAccountInfo
Gets the account information, including balances
restClient.General.GetAccountInfoAsync();
GetAccountStatus
Gets the status of the account associated with the api key/secret
restClient.General.GetAccountStatusAsync();
GetDailySpotAccountSnapshot
Get a daily account snapshot (balances)
restClient.General.GetDailySpotAccountSnapshotAsync();
Shared
GetForceLiquidationHistory
Get history of forced liquidations
restClient.Margin.GetForceLiquidationHistoryAsync();
GetMaxBorrowAmount
Query max borrow amount
restClient.Margin.GetMaxBorrowAmountAsync();
GetMaxTransferAmount
Query max transfer-out amount
restClient.Margin.GetMaxTransferAmountAsync();
Margin
Borrow
Borrow. Apply for a loan.
restClient.Margin.BorrowAsync();
Repay
Repay loan for margin account.
restClient.Margin.RepayAsync();
Transfer
Execute transfer between spot account and cross margin account.
restClient.Margin.TransferAsync();
GetMarginAccountInfo
Query margin account details
restClient.Margin.GetMarginAccountInfoAsync();
GetInterestHistory
Get history of interest
restClient.Margin.GetInterestHistoryAsync();
GetInterestRateHistory
Get history of interest rates
restClient.Margin.GetInterestRateHistoryAsync();
GetInterestMarginData
Get interest margin data
restClient.Margin.GetInterestMarginDataAsync();
GetLoans
Query loan records
restClient.Margin.GetLoansAsync();
GetMarginLevelInformation
Get personal margin level information for your account
restClient.Margin.GetMarginLevelInformationAsync();
GetRepays
Query repay records
restClient.Margin.GetRepaysAsync();
GetTransferHistory
Get history of transfers
restClient.Margin.GetTransferHistoryAsync();
Isolated
EnableIsolatedMarginAccount
Enable an isolated margin account
restClient.Margin.EnableIsolatedMarginAccountAsync();
IsolatedMarginAccountTransfer
Transfer from or to isolated margin account
restClient.Margin.IsolatedMarginAccountTransferAsync();
GetIsolatedMarginAccount
Isolated margin account info
restClient.Margin.GetIsolatedMarginAccountAsync();
GetEnabledIsolatedMarginAccountLimit
Get max number of enabled isolated margin accounts
restClient.Margin.GetEnabledIsolatedMarginAccountLimitAsync();
GetInterestIsolatedMarginData
Get interest isolated margin data
restClient.Margin.GetInterestIsolatedMarginDataAsync();
GetIsolatedMarginAccountTransferHistory
Get history of transfer to and from the isolated margin account
restClient.Margin.GetIsolatedMarginAccountTransferHistoryAsync();
DisableIsolatedMarginAccount
Disable an isolated margin account
restClient.Margin.DisableIsolatedMarginAccountAsync();
Market Endpoints
Spot
GetTicker
Get data regarding the last 24 hours for the provided symbol
restClient.Spot.Market.GetTickerAsync();
GetTickers
Get data regarding the last 24 hours for all symbols
restClient.Spot.Market.GetTickersAsync();
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.GetAggregatedTradeHistoryAsync();
GetCurrentAvgPrice
Gets current average price for a symbol
restClient.Spot.Market.GetCurrentAvgPriceAsync();
GetKlines
Get candlestick data for the provided symbol
restClient.Spot.Market.GetKlinesAsync();
GetTradeHistory
Gets the historical trades for a symbol
restClient.Spot.Market.GetTradeHistoryAsync();
GetRecentTradeHistory
Gets the recent trades for a symbol
restClient.Spot.Market.GetRecentTradeHistoryAsync();
GetBookPrice
Gets the best price/quantity on the order book for a symbol.
restClient.Spot.Market.GetBookPriceAsync();
GetAllBookPrices
Gets the best price/quantity on the order book for all symbols.
restClient.Spot.Market.GetAllBookPricesAsync();
GetPrice
Gets the price of a symbol
restClient.Spot.Market.GetPriceAsync();
GetAllPrices
Get a list of the prices of all symbols
restClient.Spot.Market.GetAllPricesAsync();
GetTradeFee
Gets the trade fee for a symbol
restClient.Spot.Market.GetTradeFeeAsync();
Margin
GetMarginAsset
Get a margin asset
restClient.Margin.Market.GetMarginAssetAsync();
GetAllMarginAssets
Get all assets available for margin trading
restClient.Margin.Market.GetAllMarginAssetsAsync();
GetMarginPair
Get a margin pair
restClient.Margin.Market.GetMarginPairAsync();
GetAllMarginPairs
Get all asset pairs available for margin trading
restClient.Margin.Market.GetAllMarginPairsAsync();
GetMarginPriceIndex
Get margin price index
restClient.Margin.Market.GetMarginPriceIndexAsync();
Isolated
GetIsolatedSymbol
Isolated margin symbol info
restClient.Margin.Market.GetIsolatedMarginSymbolAsync();
GetAllIsolatedSymbols
Isolated margin symbol info for all symbols
restClient.Margin.Market.GetAllIsolatedMarginSymbolsAsync();
Order Endpoints
Spot
PlaceOrderLimit
Places a new limit order
restClient.Spot.Order.PlaceOrderLimitAsync()
PlaceOrderMarket
Places a new market order
restClient.Spot.Order.PlaceOrderMarketAsync()
PlaceTestOrder
Places a new test order.
Test orders are not actually being executed and just test the functionality.
restClient.Spot.Order.PlaceTestOrderAsync();
PlaceOcoOrder
Places a new OCO(One cancels other) order
restClient.Spot.Order.PlaceOcoOrderAsync();
GetOrder
Retrieves data for a specific order.
Either orderId
or origClientOrderId
should be provided.
restClient.Spot.Order.GetOrderAsync();
GetOrders
Gets all orders for the provided symbol
restClient.Spot.Order.GetOrdersAsync();
GetOpenOrders
Gets a list of open orders
restClient.Spot.Order.GetOpenOrdersAsync();
GetOcoOrders
Retrieves a list of oco orders matching the parameters
restClient.Spot.Order.GetOcoOrdersAsync();
GetOpenOcoOrders
Retrieves a list of open oco orders
restClient.Spot.Order.GetOpenOcoOrdersAsync();
GetUserTrades
Gets all user trades for provided symbol
restClient.Spot.Order.GetUserTradesAsync();
GetOcoOrder
Retrieves data for a specific oco order.
Either orderListId
or listClientOrderId
should be provided.
restClient.Spot.Order.GetOcoOrderAsync();
CancelOrder
Cancels a pending order on a symbol
restClient.Spot.Order.CancelOrderAsync();
CancelAllOpenOrders
Cancels all open orders on a symbol
restClient.Spot.Order.CancelAllOpenOrdersAsync()
CancelOcoOrder
Cancels a pending oco order
restClient.Spot.Order.CancelOcoOrderAsync()
Margin/Isolated
PlaceMarginOrderLimit
Margin account new limit order
restClient.Margin.Order.PlaceMarginOrderLimitAsync();
PlaceMarginOrderMarket
Margin account new market order
restClient.Margin.Order.PlaceMarginOrderMarketAsync();
PlaceMarginOCOOrder
Places a new OCO(One cancels other) order
restClient.Margin.Order.PlaceMarginOCOOrderAsync();
GetMarginAccountOrder
Retrieves data for a specific margin account order.
Either orderId
or origClientOrderId
should be provided.
restClient.Margin.Order.GetMarginAccountOrderAsync();
GetMarginAccountOrders
Gets all margin account orders for the provided symbol
restClient.Margin.Order.GetMarginAccountOrdersAsync();
GetMarginAccountOpenOrders
Gets a list of open margin account orders
restClient.Margin.Order.GetMarginAccountOpenOrdersAsync();
GetMarginAccountUserTrades
Gets all user margin account trades for provided symbol
restClient.Margin.Order.GetMarginAccountUserTradesAsync();
GetMarginOcoOrders
Retrieves a list of margin oco orders matching the parameters
restClient.Margin.Order.GetMarginOcoOrdersAsync();
GetOpenOcoOrders
Retrieves a list of open margin oco orders
restClient.Margin.Order.GetOpenOcoOrdersAsync();
GetMarginOcoOrder
Retrieves data for a specific margin oco order.
Either orderListId
or listClientOrderId
should be provided.
restClient.Margin.Order.GetMarginOcoOrderAsync();
CancelMarginOrder
Cancel an active order for margin account
restClient.Margin.Order.CancelMarginOrderAsync();
CancelOpenMarginOrders
Cancel all active orders for a symbol
restClient.Margin.Order.CancelOpenMarginOrdersAsync();
CancelMarginOcoOrder
Cancels a pending margin oco order
restClient.Margin.Order.CancelMarginOcoOrderAsync();
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.StartUserStreamAsync();
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.KeepAliveUserStreamAsync();
StopUserStream
Stops the current user stream
restClient.Spot.UserStream.StopUserStreamAsync();
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.StartUserStreamAsync();
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.KeepAliveUserStreamAsync();
StopUserStream
Close the user stream for the cross margin account
restClient.Margin.UserStream.StopUserStreamAsync();
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.StartIsolatedMarginUserStreamAsync();
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.KeepAliveIsolatedMarginUserStreamAsync();
CloseIsolatedUserStream
Close the user stream for the isolated margin account
restClient.Margin.IsolatedUserStream.StopIsolatedMarginUserStreamAsync();
Common Endpoints
SetBnbBurnStatus
Sets the status of the BNB burn switch for spot trading and margin interest
restClient.General.SetBnbBurnStatusAsync();
DustTransfer
Converts dust (small amounts of) assets to BNB
restClient.General.DustTransferAsync();
GetFundingWallet
Get funding wallet assets
restClient.General.GetFundingWalletAsync();
Transfer
Transfers between accounts
restClient.General.TransferAsync();
GetUserCoins
Gets information of coins for a user
restClient.General.GetUserCoinsAsync();
GetAPIKeyPermissions
Get permission info for the current API key
restClient.General.GetAPIKeyPermissionsAsync();
GetAssetDividendRecords
Get asset dividend records
restClient.General.GetAssetDividendRecordsAsync();
GetBnbBurnStatus
Gets the status of the BNB burn switch for spot trading and margin interest
restClient.General.GetBnbBurnStatusAsync();
GetServerTimeTicks
Get the server time ticks as reported by the binance server
long stt = await ServerTimeClient.GetServerTimeTicksAsync().ConfigureAwait(false);
GetDustLog
Gets the history of dust conversions
restClient.General.GetDustLogAsync();
GetExchangeInfo
Get's information about the exchange including rate limits and information on the provided symbol or symbols
restClient.Spot.System.GetExchangeInfoAsync();
GetSystemStatus
Gets the status of the Binance platform
restClient.Spot.System.GetSystemStatusAsync();
Ping
Pings the Binance API
restClient.Spot.System.PingAsync();
GetTradingStatus
Gets the trading status for the current account
restClient.General.GetTradingStatusAsync();
GetTransfers
Get universal transfer history
restClient.General.GetTransfersAsync();
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.UpdatesAsync();
User Data Streams Event
Subscribes to the account update stream. Prior to using this, one of the StartUserStream
methods should be called.
Subscribe to NotifyOrderUpdate
to get notified of BinanceStreamOrderUpdate
You can use TryGetOrderUpdateFromQueue
to get the Order Update
Subscribe to NotifyOrderListUpdate
to get notified of BinanceStreamOrderList
You can use TryGetOrderListUpdateFromQueue
to get the Order List Update
Subscribe to NotifyPositionUpdate
to get notified of BinanceStreamPositionsUpdate
You can use TryGetPositionUpdateFromQueue
to get the Position Update
socketClient.UserDataStreams.UpdateEventsAsync();
SymbolTickerUpdates
Subscribes to ticker updates stream for a specific symbol
socketClient.Subscribe.SymbolTickerUpdatesAsync()
AggregatedTradeUpdates
Subscribes to the aggregated trades update stream for the provided symbol
socketClient.Subscribe.AggregatedTradeUpdatesAsync()
TradeUpdates
Subscribes to the trades update stream for the provided symbol
socketClient.Subscribe.TradeUpdatesAsync()
KlineUpdates
Subscribes to the candlestick update stream for the provided symbols and intervals
socketClient.Subscribe.KlineUpdatesAsync()
SymbolMiniTickerUpdates
Subscribes to mini ticker updates stream for a specific symbol or symbols
socketClient.Subscribe.SymbolMiniTickerUpdatesAsync()
AllSymbolMiniTickerUpdates
Subscribes to mini ticker updates stream for all symbols
socketClient.Subscribe.AllSymbolMiniTickerUpdatesAsync()
BookTickerUpdates
Subscribes to the book ticker update stream for the provided symbol or symbols
socketClient.Subscribe.BookTickerUpdatesAsync()
AllBookTickerUpdates
Subscribes to the book ticker update stream for all symbols
socketClient.Subscribe.AllBookTickerUpdatesAsync()
SymbolTickerUpdates
Subscribes to ticker updates stream for a specific symbol or symbols
socketClient.Subscribe.SymbolTickerUpdatesAsync()
AllSymbolTickerUpdates
Subscribes to ticker updates stream for all symbols
socketClient.Subscribe.AllSymbolTickerUpdatesAsync()
Unsubscribe Stream
SocketClientHost example = socketClient.Subscribe.SymbolMiniTickerUpdatesAsync(...);
await example.UnsubscribeAsync().ConfigureAwait(false);
Reconnect Stream
SocketClientHost example = socketClient.Subscribe.SymbolMiniTickerUpdatesAsync(...);
await example.ReconnectSocketAsync().ConfigureAwait(false);
Socket Status
SocketClientHost example = socketClient.Subscribe.SymbolMiniTickerUpdatesAsync(...);
example.ConnectionStatusChanged += BinanceSocket_StatusChanged;
private static void BinanceSocket_StatusChanged(ConnectionStatus obj);
Dispose Stream and SocketHost
SocketClientHost example = socketClient.Subscribe.SymbolMiniTickerUpdatesAsync(...);
await example.DisposeAsync().ConfigureAwait(false);
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.3)
- BinanceUriCache (>= 1.0.1.6)
- Newtonsoft.Json (>= 13.0.3)
- SimpleLog4.NET (>= 2.0.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
General Improvements to the WebSocket Implementation, Fixes a bug that could cause a Socket to fail to Reconnect
Adds a new ConnectionStatus to Sockets called Failed that indicates that reconnecting wasn't successful after the maximum number of attempts
Updated SimpleLog4.NET
Add new Account Types