Skip to content

Authentication

sonvister edited this page Mar 14, 2018 · 8 revisions

For REST API methods that require authentication, create a user instance (IBinanceApiUser) providing your Binance account API-Key and API-Secret. The interface is IDisposable due to an internal HMAC used for signing requests (subsequently, the API-Secret is not stored as a property in the BinanceApiUser class privately or otherwise).

NOTE: The IBinanceApiUserProvider service allows for configurable dependency injection of the IApiRateLimiter and IOptions<BinanceApiOptions> implementations.

var userProvider = serviceProvider.GetService<IBinanceApiUserProvider>();
using (var user = userProvider.CreateUser("API-Key", "API-Secret"))
{
    // ...
}

Optionally, without dependecy injection (and IBinanceApiUserProvider).

using (var user = new BinanceApiUser("API-Key", "API-Secret"))
{
    // ...
}

NOTE: User authentication is method injected -- only where required -- so a single Binance API instance supports multiple users.

NOTE: This 'user' variable is referenced in other examples.

Sample (Console) Application Prerequisites

When using the BinanceConsoleApp sample you may see this message when accessing non-public API methods:

To access some Binance endpoint features, your API Key and Secret may be required. You can either modify the 'ApiKey' and 'ApiSecret' configuration values in appsettings.json.

Or use the following commands to configure the .NET user secrets for the project:

        dotnet user-secrets set BinanceApiKey <your api key>
        dotnet user-secrets set BinanceApiSecret <your api secret>

For more information: https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets