Skip to content

Instantly share code, notes, and snippets.

@Quantaindew
Created August 26, 2024 21:07
Show Gist options
  • Save Quantaindew/09c0443e1cf935d774204d47815d6e1b to your computer and use it in GitHub Desktop.
Save Quantaindew/09c0443e1cf935d774204d47815d6e1b to your computer and use it in GitHub Desktop.

Certainly! I'll create a user-friendly version of the documentation for CoinDCX's futures trading API. This version will be simplified and focus on the key aspects that users need to get started and perform common operations.

CoinDCX Futures Trading API Documentation

Introduction

Welcome to the CoinDCX Futures Trading API! This guide will help you integrate futures trading functionality into your applications. Our API allows you to place orders, manage positions, and access market data for futures contracts.

Base URL

All API requests should be made to:

https://api.coindcx.com

Authentication

To use the API, you need to include your API key and signature in the request headers:

  1. X-AUTH-APIKEY: Your API key
  2. X-AUTH-SIGNATURE: HMAC SHA256 signature of the request payload

To generate the signature:

  1. Create a JSON string of your request body
  2. Use HMAC SHA256 to hash this string with your API secret as the key
  3. The resulting hash is your signature

Example (Python):

import hmac
import hashlib
import json

secret = "your_api_secret"
body = {"timestamp": 1612345678000, "side": "buy", "market": "BTCUSDT"}
json_body = json.dumps(body)
signature = hmac.new(secret.encode(), json_body.encode(), hashlib.sha256).hexdigest()

Common Operations

1. Place a New Order

Endpoint: POST /exchange/v1/derivatives/futures/orders/create

Parameters:

  • timestamp: Current timestamp in milliseconds
  • side: "buy" or "sell"
  • pair: Trading pair (e.g., "B-BTC_USDT")
  • order_type: "market", "limit", "stop_limit", "stop_market", "take_profit_limit", "take_profit_market"
  • price: Order price (for limit orders)
  • total_quantity: Order quantity
  • leverage: Leverage value

Example Request:

import requests

url = "https://api.coindcx.com/exchange/v1/derivatives/futures/orders/create"
headers = {
    'Content-Type': 'application/json',
    'X-AUTH-APIKEY': 'your_api_key',
    'X-AUTH-SIGNATURE': 'your_signature'
}
body = {
    "timestamp": 1612345678000,
    "side": "buy",
    "pair": "B-BTC_USDT",
    "order_type": "limit",
    "price": 50000,
    "total_quantity": 0.1,
    "leverage": 5
}

response = requests.post(url, json=body, headers=headers)
print(response.json())

2. Get Open Positions

Endpoint: POST /exchange/v1/derivatives/futures/positions

Parameters:

  • timestamp: Current timestamp in milliseconds
  • page: Page number
  • size: Number of records per page

Example Request:

url = "https://api.coindcx.com/exchange/v1/derivatives/futures/positions"
body = {
    "timestamp": 1612345678000,
    "page": "1",
    "size": "10"
}

response = requests.post(url, json=body, headers=headers)
print(response.json())

3. Cancel an Order

Endpoint: POST /exchange/v1/derivatives/futures/orders/cancel

Parameters:

  • timestamp: Current timestamp in milliseconds
  • id: Order ID to cancel

Example Request:

url = "https://api.coindcx.com/exchange/v1/derivatives/futures/orders/cancel"
body = {
    "timestamp": 1612345678000,
    "id": "order_id_here"
}

response = requests.post(url, json=body, headers=headers)
print(response.json())

Error Handling

If an error occurs, the API will return an error response with a status code and message. Common error codes include:

  • 400: Bad Request
  • 401: Unauthorized
  • 404: Not Found
  • 429: Too Many Requests
  • 500: Internal Server Error

Always check the response status and handle errors appropriately in your application.

Rate Limits

Be aware of rate limits to avoid being temporarily blocked. If you exceed the limit, you'll receive a 429 error. Implement proper error handling and consider adding delays between requests if necessary.

Best Practices

  1. Always use HTTPS for secure communication.
  2. Store your API key and secret securely and never share them.
  3. Implement proper error handling in your code.
  4. Test your integration thoroughly before going live.
  5. Stay updated with the latest API changes and updates from CoinDCX.

For more detailed information on specific endpoints or advanced features, please refer to the full API documentation or contact CoinDCX support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment