Skip to main content
CryptoClients.Net uses the ExchangeCredentials class to hold typed API credentials for every exchange you want to authenticate with. Each exchange has its own credential type — most require a key and secret, while some also require a passphrase.

Basic usage

Set credentials globally in AddCryptoClients:
builder.Services.AddCryptoClients(options =>
{
    options.ApiCredentials = new ExchangeCredentials
    {
        Binance = new BinanceCredentials("BinanceKey", "BinanceSecret"),
        Bybit   = new BybitCredentials("BybitKey", "BybitSecret"),
        GateIo  = new GateIoCredentials("GateKey", "GateSecret"),
        Kraken  = new KrakenCredentials(
            spotCredentials: new HMACCredential("KrakenKey", "KrakenSecret"),
            futuresCredentials: null)
    };
});
Some exchanges require a passphrase (also called a memo or API password) in addition to a key and secret. These exchanges include Kucoin, OKX, Bitget, BitMart, BloFin, and DeepCoin. Their credential constructors accept a third string parameter for the passphrase.
options.ApiCredentials = new ExchangeCredentials
{
    Kucoin = new KucoinCredentials("KucoinKey", "KucoinSecret", "KucoinPassphrase"),
    OKX    = new OKXCredentials("OKXKey", "OKXSecret", "OKXPassphrase"),
    Bitget = new BitgetCredentials("BitgetKey", "BitgetSecret", "BitgetPassphrase")
};

Setting credentials at runtime

You can update credentials on an already-constructed client using SetApiCredentials:
public class TradingService
{
    private readonly IExchangeRestClient _client;

    public TradingService(IExchangeRestClient client)
    {
        _client = client;
    }

    public void UpdateCredentials(string exchange, DynamicCredentials credentials)
    {
        _client.SetApiCredentials(exchange, credentials);
    }
}
The overload SetApiCredentials(string exchange, string apiKey, string apiSecret, string? apiPass = null) is deprecated as of v4.7.0. Use SetApiCredentials(string exchange, DynamicCredentials credentials) instead, which works with DynamicCredentials and correctly maps parameters to the exchange-specific credential type.

Dynamic credentials

DynamicCredentials lets you build credentials from generic string parameters when you don’t know at compile time which exchange you’re targeting. This is useful for multi-user scenarios or configuration-driven setups.
// Binance: key + secret (Param1 = secret)
var binanceCreds = new DynamicCredentials(
    TradingMode.Spot,
    key:    "BinanceApiKey",
    param1: "BinanceApiSecret");

_client.SetApiCredentials("Binance", binanceCreds);

// Kucoin: key + secret + passphrase (Param1 = secret, Param2 = passphrase)
var kucoinCreds = new DynamicCredentials(
    TradingMode.Spot,
    key:    "KucoinApiKey",
    param1: "KucoinApiSecret",
    param2: "KucoinPassphrase");

_client.SetApiCredentials("Kucoin", kucoinCreds);

DynamicCredentials properties

TradingMode
TradingMode
The trading mode these credentials are for (Spot, PerpetualLinear, PerpetualInverse, etc.). Some exchanges (e.g. Kraken) use different credentials for spot vs futures.
Key
string
The API key.
Param1
string?
First parameter — generally the API secret or private key.
Param2
string?
Second parameter — generally the passphrase.
Param3
string?
Third parameter, for exchanges that require additional values.

Discovering what parameters an exchange needs

Use ExchangeCredentials.GetDynamicCredentialInfo to find out at runtime which parameters a given exchange requires:
var info = ExchangeCredentials.GetDynamicCredentialInfo(TradingMode.Spot, "Kucoin");

Console.WriteLine(info.KeyDescription);    // "API key"
Console.WriteLine(info.Param1Required);    // true
Console.WriteLine(info.Param1Description); // "API secret"
Console.WriteLine(info.Param2Required);    // true
Console.WriteLine(info.Param2Description); // "Passphrase"
DynamicCredentialInfo contains:
Exchange
string
The exchange name.
KeyDescription
string
Description of what the Key value should be (e.g. "API key").
Param1Required
bool
Whether Param1 is required for this exchange.
Param1Description
string?
Description of what Param1 should contain (e.g. "API secret").
Param2Required
bool
Whether Param2 is required for this exchange.
Param2Description
string?
Description of what Param2 should contain (e.g. "Passphrase").
Param3Required
bool
Whether Param3 is required for this exchange.
Param3Description
string?
Description of what Param3 should contain.

Building ExchangeCredentials dynamically

Use the static factory methods on ExchangeCredentials when you need to construct credentials from a dictionary or from a DynamicCredentials object.

ExchangeCredentials.CreateFrom

Creates an ExchangeCredentials instance from a dictionary of exchange names to typed credential objects:
var dict = new Dictionary<string, ApiCredentials>
{
    { "Binance", new BinanceCredentials("key", "secret") },
    { "OKX",     new OKXCredentials("key", "secret", "passphrase") }
};

ExchangeCredentials creds = ExchangeCredentials.CreateFrom(dict);
Or from a single exchange and credential pair:
ExchangeCredentials creds = ExchangeCredentials.CreateFrom(
    "Binance",
    new BinanceCredentials("key", "secret"));

ExchangeCredentials.CreateCredentialsForExchange

Converts a DynamicCredentials object into the correct typed ApiCredentials for a named exchange:
var dynamic = new DynamicCredentials(TradingMode.Spot, "myKey", "mySecret", "myPassphrase");
ApiCredentials typed = ExchangeCredentials.CreateCredentialsForExchange("Kucoin", dynamic);
// typed is now a KucoinCredentials instance
This is useful when you receive raw key/secret/passphrase strings from user input and need to turn them into exchange-specific objects without knowing the exact type ahead of time.

Build docs developers (and LLMs) love