Authentication Parameters
For the REST API, the following parameters are used for authentication to endpoints which contain private data:API-KeyHTTP header parameter: the public key from your API key-pair.API-SignHTTP header parameter: encrypted signature of message.noncepayload parameter: always increasing, unsigned 64-bit integer.otppayload parameter: one-time-password and is only required if additional 2FA is configured for API.
Setting the API-Key Parameter
The value for theAPI-Key HTTP header parameter is your public API key.
An API key-pair is required to access the authenticated endpoints, see How to Create an API Key.
Setting the API-Sign Parameter
The value for theAPI-Sign HTTP header parameter is a signature generated from encoding your private API key, nonce, encoded payload, and URI path.
Examples
The following is a specific example of a signature generated with a particular private key, nonce, and payload corresponding to a new limit order (buy 1.25 XBTUSD at $37,500).If your code is generating a different signature (API-Sign) for this example, then there is likely an issue with your application of the above methodology. Code snippets for generating the signature in Python, Golang and Node.js follow below.
- Python
- Go
- Node JS
Setting the nonce Parameter
The value for thenonce payload body parameter is an always increasing, unsigned 64-bit integer for each request that is made with a particular API key.
While a simple counter would provide a valid nonce, a more usual method of generating a valid nonce is to use e.g. a UNIX timestamp in milliseconds. There is no way to reset the nonce for an API key to a lower value, so be sure to use a nonce generation method that won’t produce numbers less than the previous nonce.
Too many requests with invalid nonces (EAPI:Invalid nonce) can result in temporary bans.
Problems can arise from requests arriving out of order due to API keys being shared across processes, or from system clock drift/recalibration. An optional “nonce window” can be configured to specify a tolerance between nonce values.
Additional info can be found in our support pages.
Examples
The following are some examples of how to generate valid millisecond resolution nonce values in different programming languages:- Python
- Go
- Node JS
Setting the otp Parameter
The optional value for theotp payload body parameter is your one-time-password.
This parameter is only required if two-factor authentication (2FA) is enabled for the API key and action in question. The 2FA authentication is not needed for Websocket and FIX APIs.