Indodax API Documentation

repository·master·Indexed 41 days ago

https://github.com/btcid/indodax-official-api-docs

Official documentation for Indodax API interfaces, including Public and Private REST APIs, Market Data and Private WebSocket streams, and the high-performance Trade API 2.0. Features detailed guides on authentication using HMAC-SHA512 and HMAC-SHA256, order management, coin withdrawals, and the Deadman Switch safety mechanism for automatic order cancellation.

Tokens
22.5K
Snippets
69
Records
93
Agent score
51%

What's inside Indodax

  1. Overview of Indodax APIs and Streams

    master

    Indodax provides several interfaces for interacting with its platform, including REST APIs (Public and Private), WebSocket streams (Market Data and Private), and specialized trading APIs.

    Important Note on Support: Only the streams, endpoints, parameters, and payloads explicitly described in the official documentation within this repository are considered official and supported. Using any other interfaces is done at your own risk and is not guaranteed by Indodax.

  2. Overview of TAPI v2 Private Endpoints

    master

    TAPI v2 (Trade API 2.0) provides a standardized and secure set of private REST endpoints for authenticated users. It replaces the legacy private API. Key capabilities include order management (create, cancel, retrieve), account information, withdrawal/deposit history, and managing fiat/coin transfers.

    Important Migration Note: Existing integrations using the legacy endpoints must be migrated to TAPI v2. While legacy endpoints may support existing method parameters for a limited transition period, they are slated for decommissioning.

  3. General API Information for Indodax Private REST API

    master

    The Indodax Private REST API is used for authenticated operations.

    Base URL: https://indodax.com/tapi

    Key Characteristics:

    • All requests must be sent using the POST method.
    • All endpoints return data as a JSON object or array.
    • Data is returned in descending order (newest first).
    • All time and timestamp fields are in milliseconds.
  4. General information for Indodax Trade API 2.0

    master

    The Indodax Trade API 2.0 (TAPI v2) is used for interacting with private endpoints.

    Key Specifications:

    • Base URL: https://api.indodax.com/
    • Data Format: All endpoints return JSON objects or arrays.
    • Sorting: Data results are sorted in descending order (newest first, oldest last).
    • Time Format: All timestamps and time-related fields are in milliseconds (ms).
    • Authentication: For SIGNED endpoints, you must provide a signature using the Sign request header, or as a query parameter or request body field named signature.
  5. Understand the Deadman Switch concept

    master

    The Deadman Switch is a safety mechanism designed to automatically cancel all open orders for specified trading pairs if your system experiences an outage.

    To use it effectively, you must call the endpoint repeatedly as a 'heartbeat'. Each successful call resets the countdown timer. For example, if you call the endpoint every 30 seconds with a countdownTime of 120,000ms (120s), your orders remain safe. If your system fails and the endpoint isn't called within 120 seconds, Indodax will automatically cancel all open orders for those pairs.

    Key details:

    • Resetting: Calling the endpoint with a new countdownTime replaces the existing timer.
    • Stopping: Calling the endpoint with a countdownTime of 0 stops the countdown timer entirely.
    • Precision: The system checks countdowns approximately every 10 milliseconds. Do not set the countdown time to be too precise or too small; ensure sufficient redundancy.
    • Rate Limit: 10 requests per 10 seconds per IP.
  6. Authenticate SIGNED endpoints using HMAC-SHA256

    master

    For TRADE and USER_DATA endpoints, you must sign your request.

    1. Headers: Pass your API key in the X-APIKEY header. The signature can be passed in the Sign request header, as a signature field in the request body, or as a signature query parameter.
    2. Signature Construction: Concatenate the query string and the request body (if any). Encrypt this string using HMAC-SHA256 with your secretKey.
    3. Timing: Include a timestamp (milliseconds). The server will reject the request if timestamp < serverTime - recvWindow or if the request is too far in the future.

    Note: X-APIKEY and secretKey are case-sensitive, but the signature value itself is not case-sensitive.

    if (( timestamp >= serverTime + 1000 || serverTime - timestamp > recvWindow )); then
        # Reject request
        echo "Request rejected"
    else
        # Process request
        echo "Request processed"
    fi
  7. Request parameter requirements for TAPI v2

    master

    All TAPI v2 requests must include either a nonce or a timestamp to be valid. If both are provided, the timestamp takes precedence.

    • nonce: An incrementing integer. It must be greater than the nonce used in the previous request (e.g., if the last nonce was 1000, the next must be 1001 or higher).
    • timestamp: A millisecond timestamp representing when the request was generated.
    • recvWindow (optional): A validity window in milliseconds. It defines how long after the timestamp the request remains valid. The default is 5000 ms.
    | **Parameter** | **Mandatory** | **Description** | **Value** |
    | --- | --- | --- | --- |
    | `nonce` | yes | An increment integer. | Must be greater than the nonce of the last request. |
    | `timestamp` | yes | Millisecond timestamp when the request was generated. | Timestamp in milliseconds (ms) |
    | `recvWindow` | no | Validity window for request in milliseconds (ms). | Default: `5000 ms` |
  8. How to sign SIGNED (TRADE and USER_DATA) requests

    master

    Endpoints categorized as SIGNED (such as those for trading or user data) require an additional Sign header.

    Signing Process:

    1. Algorithm: Use HMAC SHA512.
    2. Key: Use your secretKey.
    3. Value (totalParams): Concatenate the query string with the request body (e.g., method=val&timestamp=val).
    4. Header: The resulting signature is sent in the Sign header. The signature itself is not case sensitive.

    Timing Security: SIGNED endpoints require a timestamp (in milliseconds). To prevent replay attacks or issues with network latency, use the recvWindow parameter (defaults to 5000ms). A request is rejected if:

    • The timestamp is too far in the future (timestamp >= serverTime + 1000).
    • The request is too old (serverTime - timestamp > recvWindow).
  9. Connect to the Private WebSocket

    master

    To use the Private WebSocket, connect to the appropriate Base URL depending on your environment.

    EnvironmentBase URLDescription
    Productionwss://pws.indodax.com/ws/?cf_ws_frame_ping_pong=trueProduction access
    Demowss://pws.demo-indodax.com/ws/?cf_ws_frame_ping_pong=trueStaging access

    After establishing the connection, you must authenticate by sending a connect request message containing a token and an id.

    {"connect":{"token": "YOUR_PRIVATE_TOKEN"},"id": 1}
  10. Request a new Private WebSocket token

    master

    Private WebSocket tokens are valid for only 24 hours. You must request a new token each time you connect and continue to request them regularly to maintain connectivity.

    To request a token, perform a POST request to https://indodax.com/api/private_ws/v1/generate_token with the following requirements:

    • Body: client=tapi&tapi_key=<your_tapi_key> (Content-Type: application/x-www-form-urlencoded)
    • Header: Sign must contain an HMAC-SHA512 signature of the request body using your tapi_secret as the key.

    The response contains connToken and channel which are required for the WebSocket connection.

    // JavaScript implementation for requesting a token
    const crypto = require("crypto");
    
    function generateHMAC(requestBody, secret) {
      const key = Buffer.from(secret, "utf-8");
      const hmac = crypto.createHmac("sha512", key);
      hmac.update(requestBody, "utf-8");
      return hmac.digest("hex");
    }
    
    async function RequestToken() {
      const url = "https://indodax.com/api/private_ws/v1/generate_token";
      const secret = <tapi_secret>;
      const key = <tapi_key>;
    
      const requestBody = `client=tapi&tapi_key=${key}`;
      const sign = generateHMAC(requestBody, secret);
    
      const opt = {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Sign": sign,
        },
        body: requestBody,
      };
    
      const response = await fetch(url, opt);
      const responseData = await response.json();
      return responseData;
    }
    
    RequestToken().then((data) => {
      console.log("token:", data.return.connToken);
      console.log("channel:", data.return.channel);
    });
  11. Recover missed data using offset and recover flag

    master

    If a connection problem occurs, you can retrieve missed data by subscribing to a channel with the recover parameter set to true and providing the last received offset. The server response will contain a publications array containing data starting from the next offset, and you will automatically be re-subscribed to receive live messages.

    {
        "method": 1,
        "params": {
            "channel": "chart:tick-usdtidr",
            "recover": true,
            "offset": 820574
        },
        "id": 2
    }
  12. Authenticate with the Market Data WebSocket

    master

    After establishing a connection, send an authentication request containing the static token for your environment within the params object. Use a unique id to track the request.

    Request Format:

    {
        "params": {
            "token": "YOUR_STATIC_TOKEN"
        },
        "id": 1
    }
    {
        "params": {
            "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5NDY2MTg0MTV9.UR1lBM6Eqh0yWz-PVirw1uPCxe60FdchR8eNVdsskeo"
        },
        "id": 1
    }