Request Signatures
SnapTrade API requests are authenticated using your clientId, a Unix timestamp, and a Signature header.
The official SnapTrade SDKs generate request signatures automatically. You only need to implement this flow manually if you are calling the SnapTrade API directly without an SDK.
Overview
To generate a request signature:
- Build a signature payload containing the request body, path, and query string.
- Serialize the payload into canonical JSON.
- Sign the canonical JSON string using HMAC-SHA256 with your
consumerKey. - Base64-encode the HMAC digest.
- Send the encoded value in the
Signatureheader.
Signature Payload
The signature payload is a JSON object with exactly three fields:
| Field | Description |
|---|---|
content | The JSON request body. Use null when the request has no body or the body is empty. |
path | The request path, including /api/v1, excluding the query string. |
query | The raw query string exactly as sent in the request URL, excluding the leading ?. |
Example request:
POST /api/v1/snapTrade/registerUser?clientId=PASSIVTEST×tamp=1635790389
Signature: <generated_signature>
Content-Type: application/json
{"userId":"new_user_123"}
The signature payload for this request is:
Canonical JSON Rules
Before signing, the signature payload must be serialized into a canonical JSON string.
Use these rules:
- Sort object keys alphabetically at every level.
- Remove unnecessary whitespace.
- Encode the resulting string as UTF-8.
- Use
nullfor empty request bodies.
The canonical signature string for the example above is:
The following string represents the same JSON object, but it is not valid for signing because it contains extra whitespace:
Cryptographic signatures are generated from the exact bytes of the string. Even small formatting differences will produce a different signature.
Request Details
The query value is the exact query string sent in the request URL, excluding the leading ?.
Example:
/api/v1/snapTrade/registerUser?clientId=PASSIVTEST×tamp=1635790389
Use:
clientId=PASSIVTEST×tamp=1635790389
Do not sort, decode, re-encode, or otherwise modify query parameters before signing.
For requests without body, set content to null. This includes GET requests, bodyless DELETE/POST requests, and requests where the body would otherwise be {}.