Authentication overview
Coinigy provides programmatic access to its trading and portfolio management platform primarily through a REST API. Authentication for this API relies on a signature-based mechanism using API keys and secrets. This approach ensures that all requests originating from a user's application or script are verified as legitimate and authorized to interact with their Coinigy account.
The authentication process typically involves generating a unique API key pair (an API key and an API secret) from within the Coinigy user interface. These credentials are then used to construct signed requests. When a request is sent to the Coinigy API, a cryptographic hash (signature) is created using the request's parameters and the user's API secret. The Coinigy server then validates this signature against its own calculation, granting access only if they match. This method is a common practice for securing APIs, particularly in financial contexts, as it prevents tampering with requests and ensures data integrity during transmission.
For detailed information on the Coinigy API's capabilities and endpoints, refer to the Coinigy API documentation.
Supported authentication methods
Coinigy's primary and recommended authentication method for its REST API is HMAC-SHA256 signature-based authentication using API keys. This method provides a balance of security and flexibility for developers building custom integrations.
HMAC-SHA256 with API Keys:
- Mechanism: This method requires users to generate a public API key and a private API secret. The public API key identifies the user, while the private API secret is used to create a unique cryptographic signature for each request. The signature is typically generated using a Hash-based Message Authentication Code (HMAC) algorithm with SHA-256 hash function, incorporating elements of the request (like timestamp, endpoint, and payload) and the secret key.
- Purpose: It verifies both the identity of the sender and the integrity of the message, ensuring that the request has not been altered in transit and originates from an authorized source. This is crucial for sensitive operations like placing trades or accessing financial data.
- When to Use: This method is suitable for all programmatic interactions with the Coinigy API, including developing trading bots, portfolio trackers, or integrating Coinigy data into other applications.
Coinigy does not currently support OAuth 2.0 for third-party application authentication or password-based API authentication. The focus remains on the secure, direct API key model.
Authentication Methods Summary
| Method | When to Use | Security Level |
|---|---|---|
| HMAC-SHA256 with API Keys | All programmatic access to Coinigy API (trading, portfolio, data) | High (requires secure handling of private key) |
Getting your credentials
To obtain the necessary API credentials for Coinigy, you must have an active paid subscription, as API access is included with all paid plans. Follow these general steps to generate your API key and secret:
- Log in to Your Coinigy Account: Access your Coinigy dashboard via the official Coinigy website.
- Navigate to API Settings: Look for a section related to 'API Keys', 'API Management', or 'Settings' within your account dashboard. The exact path may vary but is typically found under your user profile or security settings.
- Generate New API Key: Within the API settings, there should be an option to 'Generate New API Key' or 'Create API Credentials'. Clicking this will typically generate a pair of credentials: an API Key (public) and an API Secret (private).
- Configure Permissions (Optional but Recommended): Some platforms allow you to set specific permissions for your API key (e.g., read-only access, trading access, withdrawal access). For security, grant only the minimum necessary permissions required for your application. Coinigy's API documentation will specify available permissions.
- Record Your Credentials: The API Secret is often displayed only once upon generation. It is critical to copy and store both your API Key and API Secret securely immediately after creation. If you lose your API Secret, you will typically need to revoke the existing key and generate a new one.
- Whitelist IP Addresses (Recommended): If Coinigy offers IP whitelisting, configure your API key to only accept requests from specific, trusted IP addresses. This adds an extra layer of security.
Always consult the official Coinigy API documentation for the most up-to-date and specific instructions on generating and managing your API keys, as UI elements and processes can change.
Authenticated request example
While specific implementation details depend on the programming language and libraries used, an authenticated request to the Coinigy API generally follows this pattern. This example illustrates the conceptual steps for making a signed request.
import hashlib
import hmac
import time
import json
import requests
# --- Your Coinigy API Credentials ---
API_KEY = "YOUR_COINIGY_API_KEY" # Replace with your actual API Key
API_SECRET = "YOUR_COINIGY_API_SECRET" # Replace with your actual API Secret
# --- Request Parameters ---
BASE_URL = "https://api.coinigy.com/api/v1"
ENDPOINT = "/accounts"
METHOD = "POST"
# Example payload for a POST request (if applicable, otherwise use an empty string)
# For GET requests, the payload is typically empty or part of the query string.
# Consult Coinigy API docs for specific endpoint requirements.
PAYLOAD = {
"exchangeCode": "GDAX",
"authId": "example_auth_id"
}
# Convert payload to JSON string for signing if it's a POST/PUT request with body
json_payload = json.dumps(PAYLOAD) if PAYLOAD else ""
# --- Create the Message for Signing ---
# The exact components and order for signing depend on Coinigy's specific API requirements.
# Common components include: timestamp, HTTP method, request path, and request body.
# ALWAYS refer to the official Coinigy API documentation for the precise signing string format.
# For illustrative purposes, let's assume a simple signing string:
# timestamp + method + endpoint + json_payload
timestamp = str(int(time.time() * 1000)) # Milliseconds timestamp
# This is a hypothetical signing string format.
# Coinigy's actual format will be specified in their documentation.
string_to_sign = f"{timestamp}{METHOD}{ENDPOINT}{json_payload}"
# --- Generate the HMAC-SHA256 Signature ---
signature = hmac.new(
API_SECRET.encode('utf-8'),
string_to_sign.encode('utf-8'),
hashlib.sha256
).hexdigest()
# --- Construct Request Headers ---
headers = {
"Content-Type": "application/json",
"X-API-KEY": API_KEY,
"X-API-SIGNATURE": signature,
"X-API-TIMESTAMP": timestamp
}
# --- Make the Request ---
try:
response = requests.request(METHOD, f"{BASE_URL}{ENDPOINT}", headers=headers, data=json_payload)
response.raise_for_status() # Raise an exception for HTTP errors
print("Request successful!")
print("Response:", response.json())
except requests.exceptions.HTTPError as err:
print(f"HTTP error occurred: {err}")
print("Response body:", response.text)
except Exception as err:
print(f"An error occurred: {err}")
Key points in this example:
- API Key and Secret: These are your unique credentials. The secret must never be exposed.
- Timestamp: A current timestamp (often in milliseconds) is included to prevent replay attacks and ensure requests are fresh.
- String to Sign: This is a concatenated string of specific request elements (timestamp, method, path, body). The exact composition is critical and defined by the API provider. Incorrect composition will result in authentication failure.
- HMAC-SHA256 Signature: The private API secret is used to generate a unique hash of the
string_to_sign. - Headers: The API key, signature, and timestamp are typically sent in custom HTTP headers (e.g.,
X-API-KEY,X-API-SIGNATURE,X-API-TIMESTAMP). - Payload: For POST/PUT requests, the request body (payload) is also part of the signing process to ensure its integrity.
This example is illustrative. Always refer to the official Coinigy API documentation for the precise requirements for constructing the string_to_sign and the exact header names, as these details are unique to each API.
Security best practices
Properly securing your Coinigy API keys is crucial to prevent unauthorized access to your trading accounts and sensitive data. Adhering to these best practices can significantly mitigate risks:
- Keep API Secrets Confidential: Your API secret is equivalent to your password. Never hardcode it directly into client-side code, commit it to public version control systems (like GitHub), or share it with unauthorized individuals. Store it in environment variables, a secure configuration management system, or a dedicated secret management service.
- Implement IP Whitelisting: If Coinigy supports it, configure your API keys to only accept requests originating from a predefined list of trusted IP addresses. This significantly reduces the attack surface, as even if your keys are compromised, they cannot be used from an unauthorized IP address.
- Grant Least Privilege: When generating API keys, assign only the minimum necessary permissions required for your application's functionality. For example, if your application only needs to read portfolio data, do not grant it trading or withdrawal permissions. This limits the damage if a key is compromised.
- Regularly Rotate API Keys: Periodically generate new API keys and revoke old ones. This practice reduces the window of exposure for a compromised key. The frequency depends on your security policy and risk assessment.
- Monitor API Usage: Regularly review your API usage logs (if provided by Coinigy) for any unusual activity or unauthorized access attempts. Anomalies could indicate a compromise.
- Secure Your Development Environment: Ensure that the machines and environments where you store and use API keys are secure. This includes using strong passwords, two-factor authentication (2FA), up-to-date antivirus software, and firewalls.
- Validate Input and Output: Always validate data received from the API and sanitize any input sent to prevent injection attacks or unexpected behavior.
- Use Secure Communication (HTTPS): All communications with the Coinigy API should occur over HTTPS to encrypt data in transit and protect against eavesdropping. Coinigy's API endpoints are inherently served over HTTPS. This is a fundamental security measure for any web-based API interaction, as described in RFC 2818 for HTTP Over TLS.
- Error Handling and Logging: Implement robust error handling to gracefully manage API failures and log relevant information for debugging and security auditing, without exposing sensitive data.
- Time Synchronization: Ensure your system's clock is accurately synchronized, as timestamp-based authentication mechanisms (like HMAC with timestamps) can fail if there's a significant clock skew between your server and the API server.