Skip to main content
ExchangeCredentials is a container that holds strongly-typed API credentials for every exchange supported by CryptoClients.Net. It is passed to IExchangeRestClient.SetApiCredentials, the tracker factory, or GlobalExchangeOptions at startup.

Creating credentials

There are three patterns for creating an ExchangeCredentials instance. Set only the exchanges you need. All properties are nullable.
var credentials = new ExchangeCredentials
{
    Binance  = new BinanceCredentials("api-key", "api-secret"),
    Bybit    = new BybitCredentials("api-key", "api-secret"),
    Kucoin   = new KucoinCredentials("api-key", "api-secret", "passphrase"),
    OKX      = new OKXCredentials("api-key", "api-secret", "passphrase"),
};

CreateFrom(Dictionary<string, ApiCredentials>)

Build from a runtime dictionary — useful when exchange names and credentials are loaded from configuration.
var credentials = ExchangeCredentials.CreateFrom(new Dictionary<string, ApiCredentials>
{
    ["Binance"] = new BinanceCredentials("api-key", "api-secret"),
    ["Bybit"]   = new BybitCredentials("api-key", "api-secret"),
});

CreateFrom(string, ApiCredentials)

Convenience overload for a single exchange.
var credentials = ExchangeCredentials.CreateFrom("Binance",
    new BinanceCredentials("api-key", "api-secret"));

Credential types by exchange

Different exchanges require different credential combinations. The table below summarises what each exchange’s credential type expects.
ExchangeCredential typeRequired fields
AsterAsterCredentialsAPI key, private key
BinanceBinanceCredentialsAPI key, API secret
BingXBingXCredentialsAPI key, API secret
BitfinexBitfinexCredentialsAPI key, API secret
BitgetBitgetCredentialsAPI key, API secret, passphrase
BitMartBitMartCredentialsAPI key, API secret, memo
BitMEXBitMEXCredentialsAPI key, API secret
BitstampBitstampCredentialsAPI key, API secret
BloFinBloFinCredentialsAPI key, API secret, passphrase
BybitBybitCredentialsAPI key, API secret
CoinbaseCoinbaseCredentialsAPI key, API secret
CoinExCoinExCredentialsAPI key, API secret
CoinGeckoCoinGeckoCredentialsAPI key only
CoinWCoinWCredentialsAPI key, API secret
CryptoComCryptoComCredentialsAPI key, API secret
DeepCoinDeepCoinCredentialsAPI key, API secret, passphrase
GateIoGateIoCredentialsAPI key, API secret
HTXHTXCredentialsAPI key, API secret
HyperLiquidHyperLiquidCredentialsWallet address, private key
KrakenKrakenCredentialsAPI key, API secret (spot and/or futures)
KucoinKucoinCredentialsAPI key, API secret, passphrase
MexcMexcCredentialsAPI key, API secret
OKXOKXCredentialsAPI key, API secret, passphrase
PolymarketPolymarketCredentials(See exchange docs)
ToobitToobitCredentialsAPI key, API secret
WhiteBitWhiteBitCredentialsAPI key, API secret
XTXTCredentialsAPI key, API secret
Upbit does not support authenticated operations through the shared client at this time.

Code examples by credential type

var credentials = new ExchangeCredentials
{
    Binance  = new BinanceCredentials("api-key", "api-secret"),
    Bybit    = new BybitCredentials("api-key", "api-secret"),
    HTX      = new HTXCredentials("api-key", "api-secret"),
    GateIo   = new GateIoCredentials("api-key", "api-secret"),
    Mexc     = new MexcCredentials("api-key", "api-secret"),
    CoinEx   = new CoinExCredentials("api-key", "api-secret"),
    Bitfinex = new BitfinexCredentials("api-key", "api-secret"),
    Bitstamp = new BitstampCredentials("api-key", "api-secret"),
    WhiteBit = new WhiteBitCredentials("api-key", "api-secret"),
    XT       = new XTCredentials("api-key", "api-secret"),
};
var credentials = new ExchangeCredentials
{
    Kucoin  = new KucoinCredentials("api-key", "api-secret", "passphrase"),
    OKX     = new OKXCredentials("api-key", "api-secret", "passphrase"),
    Bitget  = new BitgetCredentials("api-key", "api-secret", "passphrase"),
    BloFin  = new BloFinCredentials("api-key", "api-secret", "passphrase"),
    DeepCoin = new DeepCoinCredentials("api-key", "api-secret", "passphrase"),
};
// Aster uses a versioned credential wrapper
var credentials = new ExchangeCredentials
{
    Aster = new AsterCredentials(
        new AsterV3Credential("api-key", "private-key")),

    // HyperLiquid uses wallet address as the key
    HyperLiquid = new HyperLiquidCredentials("wallet-address", "private-key"),
};
Kraken issues separate API keys for spot and futures.
var credentials = new ExchangeCredentials
{
    Kraken = new KrakenCredentials(
        spotCredentials:    new HMACCredential("spot-api-key",    "spot-api-secret"),
        futuresCredentials: new HMACCredential("futures-api-key", "futures-api-secret")),
};

Applying credentials

At startup via GlobalExchangeOptions

services.AddCryptoClients(options =>
{
    options.ApiCredentials = new ExchangeCredentials
    {
        Binance = new BinanceCredentials("api-key", "api-secret"),
        Bybit   = new BybitCredentials("api-key", "api-secret"),
    };
});

At runtime via SetApiCredentials

restClient.SetApiCredentials(new ExchangeCredentials
{
    Binance = new BinanceCredentials("new-key", "new-secret"),
});

Dynamic credentials

DynamicCredentials and DynamicCredentialInfo support scenarios where the exact exchange credential type is not known at compile time — for example, building a UI that accepts user-supplied keys.

DynamicCredentialInfo

Describes what fields are required for a given exchange and trading mode, so a UI can render the appropriate input fields.
Exchange
string
Exchange name.
KeyDescription
string
Human-readable label for the Key field (e.g. "API Key" or "Wallet Address").
Param1Required
bool
Whether the first extra parameter is required.
Param1Description
string?
Human-readable label for Param1 (typically "API Secret" or "Private Key").
Param2Required
bool
Whether the second extra parameter is required.
Param2Description
string?
Human-readable label for Param2 (typically "Passphrase").
Param3Required
bool
Whether a third parameter is required.
Param3Description
string?
Human-readable label for Param3.
Retrieve for a specific exchange and trading mode:
DynamicCredentialInfo? info = ExchangeCredentials.GetDynamicCredentialInfo(
    TradingMode.Spot, "Kucoin");

// info.KeyDescription    → "API Key"
// info.Param1Required    → true
// info.Param1Description → "API Secret"
// info.Param2Required    → true
// info.Param2Description → "Passphrase"

DynamicCredentials

A generic credential bag. Populate only the fields required by the target exchange (use GetDynamicCredentialInfo to determine which).
TradingMode
TradingMode
required
Trading mode this credential is intended for.
Key
string
required
The primary key field (API key, wallet address, etc.).
Param1
string?
First parameter — typically the API secret or private key.
Param2
string?
Second parameter — typically the passphrase.
Param3
string?
Third parameter — exchange-specific.

CreateCredentialsForExchange

Converts a DynamicCredentials instance into the strongly-typed ApiCredentials subclass that the exchange expects.
ApiCredentials creds = ExchangeCredentials.CreateCredentialsForExchange(
    "Kucoin",
    new DynamicCredentials(
        TradingMode.Spot,
        key:    "api-key",
        param1: "api-secret",
        param2: "passphrase"));

// Returned object is a KucoinCredentials instance

Setting dynamic credentials at runtime

restClient.SetApiCredentials("Kucoin",
    new DynamicCredentials(
        TradingMode.Spot,
        key:    "api-key",
        param1: "api-secret",
        param2: "passphrase"));

Full dynamic credential flow

string exchange = "OKX";
TradingMode mode = TradingMode.PerpetualLinear;

// 1. Query what fields the exchange needs
var info = ExchangeCredentials.GetDynamicCredentialInfo(mode, exchange);
// Render input form based on info.KeyDescription, info.Param1Description, etc.

// 2. User fills in values
var dynamic = new DynamicCredentials(mode,
    key:    userInput.ApiKey,
    param1: userInput.ApiSecret,
    param2: userInput.Passphrase);

// 3. Apply at runtime
restClient.SetApiCredentials(exchange, dynamic);

Properties reference

Aster
AsterCredentials?
Aster API credentials.
Binance
BinanceCredentials?
Binance API credentials.
BingX
BingXCredentials?
BingX API credentials.
Bitfinex
BitfinexCredentials?
Bitfinex API credentials.
Bitget
BitgetCredentials?
Bitget API credentials.
BitMart
BitMartCredentials?
BitMart API credentials.
BitMEX
BitMEXCredentials?
BitMEX API credentials.
Bitstamp
BitstampCredentials?
Bitstamp API credentials.
BloFin
BloFinCredentials?
BloFin API credentials.
Bybit
BybitCredentials?
Bybit API credentials.
Coinbase
CoinbaseCredentials?
Coinbase API credentials.
CoinEx
CoinExCredentials?
CoinEx API credentials.
CoinGecko
CoinGeckoCredentials?
CoinGecko API credentials (API key only).
CoinW
CoinWCredentials?
CoinW API credentials.
CryptoCom
CryptoComCredentials?
Crypto.com API credentials.
DeepCoin
DeepCoinCredentials?
DeepCoin API credentials.
GateIo
GateIoCredentials?
Gate.io API credentials.
HTX
HTXCredentials?
HTX API credentials.
HyperLiquid
HyperLiquidCredentials?
HyperLiquid API credentials.
Kraken
KrakenCredentials?
Kraken API credentials (supports separate spot and futures keys).
Kucoin
KucoinCredentials?
Kucoin API credentials.
Mexc
MexcCredentials?
Mexc API credentials.
OKX
OKXCredentials?
OKX API credentials.
Polymarket
PolymarketCredentials?
Polymarket API credentials.
Toobit
ToobitCredentials?
Toobit API credentials.
WhiteBit
WhiteBitCredentials?
WhiteBit API credentials.
XT
XTCredentials?
XT API credentials.

Build docs developers (and LLMs) love