Authentication overview

CryptoMarket's API authentication system is designed to secure programmatic access to user accounts and trading functionalities. It relies on a combination of API keys and HMAC (Hash-based Message Authentication Code) signatures. This method ensures that requests originate from an authorized source and that their content remains unaltered during transmission. API keys serve as identifiers, while HMAC signatures provide a cryptographic verification of the request's integrity and authenticity.

The authentication process typically involves generating a unique API key and a corresponding secret key from the user's CryptoMarket account. These credentials are then used to sign each API request. The signature is computed using a cryptographic hash function, commonly SHA256, over a specific set of request parameters, including the request body, path, and a timestamp. This signed request is then sent to the CryptoMarket API, which independently verifies the signature using the stored secret key associated with the provided API key. If the signatures match, the request is processed; otherwise, it is rejected as unauthorized or tampered.

This approach aligns with common industry practices for securing RESTful APIs, providing a balance between security and usability for developers building automated trading systems or integrating CryptoMarket services into other applications. For a comprehensive guide on API interactions, refer to the official CryptoMarket API documentation.

Supported authentication methods

CryptoMarket primarily supports API Key and HMAC Signature authentication for its programmatic interfaces. This method is standard for cryptocurrency exchanges due to its robust security properties for non-interactive access.

The table below summarizes the supported authentication method:

Method When to Use Security Level
API Key + HMAC Signature Automated trading, portfolio management, data retrieval, any programmatic interaction with the CryptoMarket API. High. Provides both authentication and integrity verification for each request.

API Key + HMAC Signature Details:

  • API Key: A public identifier associated with your account. It is included in the request headers to identify the caller.
  • API Secret: A private key known only to you and CryptoMarket. It is used to generate the HMAC signature for each request. The API secret must never be exposed publicly or transmitted directly in API requests.
  • HMAC Signature: A cryptographic hash generated using your API secret and specific request parameters (e.g., HTTP method, request path, query parameters, request body, and timestamp). This signature is included in the request headers, allowing the CryptoMarket server to verify the request's authenticity and integrity. The use of HMAC-SHA256 is a common practice for ensuring message integrity and authentication, as detailed by the IETF RFC 2104 on HMAC.

This combination ensures that:

  • Only requests from an authorized source (possessing the correct API Key and Secret) can interact with your account.
  • The request content has not been altered since it was signed, protecting against man-in-the-middle attacks.
  • Each request is unique, often incorporating a nonce or timestamp to prevent replay attacks.

Getting your credentials

To obtain the necessary API credentials for CryptoMarket, you must generate them within your account settings on the CryptoMarket platform. The process typically involves the following steps:

  1. Log in to your CryptoMarket account: Access your account through the official CryptoMarket website.
  2. Navigate to API Settings: Look for a section labeled "API Keys," "API Management," or similar within your account security or profile settings. The exact path may vary, but it is generally found under security or developer options.
  3. Generate New API Key: Click on an option to "Create New API Key" or "Generate Credentials." You may be prompted to enter a label for the key (e.g., "My Trading Bot") to help you identify its purpose later.
  4. Configure Permissions: When generating a key, you will typically have the option to set specific permissions for it. These permissions dictate what actions the API key can perform (e.g., read market data, place orders, withdraw funds). It is a critical security practice to grant only the minimum necessary permissions for the key's intended use. For example, if your application only needs to read market data, do not grant it trading or withdrawal permissions.
  5. Record API Key and Secret: Upon generation, CryptoMarket will display your API Key and API Secret. The API Secret is typically shown only once at the time of creation. You must securely store both these credentials immediately. If you lose your API Secret, you will need to revoke the existing key and generate a new one.
  6. IP Whitelisting (Optional but Recommended): Some exchanges, including CryptoMarket, may offer an option to whitelist IP addresses. This feature restricts API access to requests originating only from specified IP addresses, adding an extra layer of security. If available, configure this with the static IP addresses of your application servers.

Always treat your API Secret as you would your account password. Never embed it directly in client-side code, commit it to version control, or share it with unauthorized individuals. For detailed instructions on key generation and management, consult the CryptoMarket API documentation on authentication.

Authenticated request example

An authenticated request to the CryptoMarket API involves constructing a payload, signing it with your API Secret, and including the generated signature and API Key in the request headers. While specific implementation details can vary by programming language, the core logic remains consistent. This example illustrates the conceptual steps for a GET request to a hypothetical /v1/account/balance endpoint.

Request Parameters for Signature:

  • method: HTTP method (e.g., GET, POST)
  • path: Request path (e.g., /v1/account/balance)
  • query: Query string parameters (if any, URL-encoded)
  • body: Request body (if any, JSON string for POST/PUT)
  • timestamp: Current Unix timestamp in milliseconds

Signature Generation Steps:

  1. Prepare the string to sign: Concatenate the timestamp, method, path, query, and body into a single string. The exact order and separators are critical and defined in the CryptoMarket API reference. For a GET request without a body or query parameters, this might be timestamp + GET + /v1/account/balance + '' + ''.
  2. Hash the string: Compute the HMAC-SHA256 hash of this concatenated string using your API Secret as the key.
  3. Encode the hash: Convert the resulting hash to a hexadecimal string.

Example (Conceptual Python-like Pseudocode):


import hmac
import hashlib
import time

api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET".encode('utf-8') # Secret must be bytes

method = "GET"
path = "/v1/account/balance"
query = ""
body = "" # No body for GET requests
timestamp = str(int(time.time() * 1000)) # Milliseconds

# 1. Prepare the string to sign
sign_string = timestamp + method + path + query + body

# 2. Hash the string
hasher = hmac.new(api_secret, sign_string.encode('utf-8'), hashlib.sha256)

# 3. Encode the hash
signature = hasher.hexdigest()

# Construct headers for the HTTP request
headers = {
    "X-CM-APIKEY": api_key,
    "X-CM-TIMESTAMP": timestamp,
    "X-CM-SIGNATURE": signature,
    "Content-Type": "application/json"
}

# Example of how a request might be sent (using requests library concept)
# import requests
# url = "https://api.cryptomarket.com" + path
# response = requests.get(url, headers=headers)
# print(response.json())

This example demonstrates the core logic. Developers should consult the CryptoMarket API documentation for exact header names, signature string construction rules, and specific endpoint details, as these can vary.

Security best practices

Implementing strong security practices is crucial when integrating with the CryptoMarket API to protect your assets and data. Adhering to these guidelines minimizes risks associated with API key exposure and unauthorized access:

  1. Least Privilege Principle: When generating API keys, grant only the minimum necessary permissions required for your application's functionality. For example, if your application only needs to read market data, do not enable trading or withdrawal permissions. Regularly review and adjust permissions as your application's needs evolve.
  2. Secure Storage of API Secrets: Never hardcode API secrets directly into your application's source code. Avoid committing them to version control systems (e.g., Git repositories). Instead, store API secrets in secure environments such as environment variables, dedicated secret management services (e.g., AWS Secrets Manager, Google Secret Manager), or encrypted configuration files that are not publicly accessible.
  3. IP Whitelisting: If CryptoMarket offers IP whitelisting, configure it to allow API requests only from a predefined list of trusted IP addresses belonging to your application servers. This significantly reduces the attack surface, as requests from any other IP address will be automatically rejected. This practice is widely recommended for API security, as noted by Google Cloud's security best practices.
  4. Rate Limiting and Error Handling: Implement robust rate limiting and error handling in your application. Excessive or malformed requests can sometimes indicate malicious activity. Properly handle API errors, especially authentication failures, without exposing sensitive information.
  5. Regular Key Rotation: Periodically rotate your API keys. This practice limits the window of exposure if a key is compromised. A common rotation schedule might be every 90 days, but the optimal frequency depends on your risk assessment.
  6. Monitoring and Alerting: Set up monitoring for API usage and security events. Look for unusual activity, such as a sudden increase in failed authentication attempts, requests from unexpected IP addresses, or attempts to access unauthorized endpoints. Configure alerts to notify you of such events promptly.
  7. Secure Communication (HTTPS/TLS): Always ensure that all API communications occur over HTTPS/TLS. This encrypts data in transit, protecting against eavesdropping and man-in-the-middle attacks. CryptoMarket's API inherently uses HTTPS, but it's essential to verify your client library or HTTP client is configured to enforce TLS verification.
  8. Timestamp and Nonce Usage: The HMAC signature process typically incorporates a timestamp and/or a nonce to prevent replay attacks. Ensure your implementation correctly generates and includes these values as required by the CryptoMarket API specification.
  9. Consider Multi-Factor Authentication (MFA) for Account Access: While not directly for API key usage, enabling MFA on your CryptoMarket account itself adds a critical layer of security against unauthorized access to your API management panel, where keys are generated and revoked.

By diligently applying these best practices, developers can significantly enhance the security posture of their CryptoMarket API integrations, safeguarding their digital assets and maintaining operational integrity.