Bitget’s API uses a three-part credential system: an API Key, an API Secret, and an API Passphrase. Every authenticated REST request and every private WebSocket connection must carry a signature derived from these three values. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/bitget-api/llms.txt
Use this file to discover all available pages before exploring further.
bitget-api SDK handles the signing automatically — you only need to supply the credentials when constructing a client. Both HMAC-SHA256 and RSA-SHA256 signing are supported, and the SDK detects which method to use based on the format of your apiSecret.
Creating API Credentials
Visit How to create an API key and log in to your Bitget account. Navigate to Profile → API Management and click Create API.
Constructor Options
Pass credentials and configuration to any client constructor via theRestClientOptions interface. The same options object is accepted by RestClientV3, RestClientV2, WebsocketClientV3, and WebsocketClientV2.
Your Bitget API key. Optional for public endpoints; required for any authenticated REST call or private WebSocket subscription.
Your API secret. For HMAC, this is the secret string provided by Bitget. For RSA, pass your full PEM-encoded private key, including the
-----BEGIN PRIVATE KEY----- header — the SDK detects RSA automatically from this header.The passphrase you chose when creating the API key. This is not your Bitget account login password — it is the separate passphrase set at API key creation time. Optional for public endpoints; required for authenticated calls.
Set to
true to route all requests to Bitget’s paper trading (demo) environment. No other code changes are required — the SDK switches base URLs and WebSocket endpoints automatically.An optional function that overrides the default signing implementation. Useful for latency-sensitive applications that want to use Node’s native
createHmac instead of the Web Crypto API. See the Custom Sign Function section below.Override the REST API base URL. Defaults to
https://api.bitget.com. Useful when routing through a proxy or a custom gateway.When
true, the SDK throws an error if any request parameter is undefined. Useful during development to catch accidental omissions before they reach the API.When
true (the default), query string values are URI-encoded via encodeURIComponent. Disable only if you are pre-encoding values yourself; leaving this enabled prevents signature errors caused by special characters in parameter values.When
true (the default), the SDK post-processes API error responses and throws them as structured exceptions. Set to false to receive raw error responses instead.Enable HTTP keep-alive for REST API requests via the underlying axios agent. Reuses TCP connections across requests, which can reduce latency at high call rates.
When
keepAlive is true, controls how often (in milliseconds) TCP keep-alive packets are sent on idle sockets. Only relevant when keepAlive is enabled. Defaults to 1000 ms.HMAC Authentication
HMAC is the default signing method. Pass your credentials to the constructor and the SDK signs every request automatically:RSA Authentication
RSA authentication is supported for both V2 and V3 clients. To use it, generate an RSA key pair locally, register the public key with Bitget when creating the API key, and pass the private key asapiSecret. The SDK detects RSA automatically when the secret contains the PRIVATE KEY marker.
Generate RSA keys with OpenSSL:
rsa-public-key.pem to Bitget when creating a “self-generated” API key. Bitget will issue you an API key string to use as apiKey. Your private key (rsa-private-key.pem) never leaves your machine.
Use the RSA private key with the SDK:
The SDK uses
RSA-SHA256 for RSA signing. Detection is automatic — if apiSecret contains the string "PRIVATE KEY" (as all standard PEM headers do), RSA mode is activated. No additional configuration is needed.Custom Sign Function
Starting from SDK v3.0.0, the default signing implementation uses the Web Crypto API, which works in both Node.js and browser environments. However, for latency-sensitive applications, Node’s nativecreateHmac is measurably faster.
You can inject your own signing function via customSignMessageFn. The function receives the pre-built message string and the secret, and must return a Promise<string> containing the hex-encoded signature:
customSignMessageFn is called on every authenticated REST request and once each time a private WebSocket connection is opened, so even small per-call savings compound at high request rates.
Demo Trading
Bitget’s demo (paper) trading environment mirrors the live API but operates with simulated funds. Enable it with a single flag:You must create a separate set of API keys in the Demo Trading environment. Live API keys do not work against the demo endpoints, and vice versa.
Debugging HTTP Requests
If you need to inspect the raw HTTP requests being sent to Bitget (for example when troubleshooting signature errors), set theBITGETTRACE environment variable to true before starting your application: