What is the method to link Python with Coinex API version 2?

I found several resources, but they all reference the v1 API while I want to implement the v2 API instead.

I’m using the following Python 3 code based on the v2 API documentation:

import time
import requests
import hmac
import hashlib
base_url = 'https://api.coinex.com'
request_path = '/v2/account/info'
timestamp = int(time.time() * 1000)
prepared_message = "GET" + request_path + str(timestamp)
api_key = '???'
secret = '???'
signature = hmac.new(bytes(secret, 'latin-1'), bytes(prepared_message, 'latin-1'), hashlib.sha256).hexdigest().lower()
params = {'X-COINEX-KEY': api_key,
          'X-COINEX-SIGN': signature,
          'X-COINEX-TIMESTAMP': timestamp}
response = requests.get(base_url + request_path, params=params)
response.json()

However, I encounter this error:

{‘code’: 11003, ‘data’: {}, ‘message’: ‘Access ID does not exist’}

The error code 11003 is not listed in the Coinex API error handling document.

Why am I receiving the message stating that my Access ID does not exist? I have verified that both the api_key and secret are correct, and I am able to access public data from Coinex without any issues, such as market information like /futures/ticker?market=BTCUSDT.

Hey Alex, here's a quick fix for your issue. The error 'Access ID does not exist' often means the api_key might be entered incorrectly or not authorized correctly.

Ensure you have:

  • Created an API key with the required permissions for the v2 endpoint you're using.
  • Checked if the api_key and secret are copied correctly and contain no trailing spaces or typos.

If those check out, update your request headers like this:

headers = {
    'X-COINEX-KEY': api_key,
    'X-COINEX-SIGNATURE': signature,
    'X-COINEX-TIMESTAMP': str(timestamp)
}

response = requests.get(base_url + request_path, headers=headers)

Make sure the timestamp is fresh and retry. Hope this helps!

To connect to the Coinex API version 2 with Python, you'll want to ensure that you're utilizing the correct API key and secret, as this is likely causing the 'Access ID does not exist' error. It seems you've already verified the key and secret, but let's dive deeper into other possible issues and solutions.

Here’s a checklist and a revised Python code example that might help resolve your issue:

  • Ensure that the API key has the necessary permissions for accessing the specific endpoints of the v2 API. Double-check this in your Coinex account settings.
  • Verify that the API key and secret do not have any spaces before or after their strings. Copy-pasting issues sometimes add such hidden spaces.
  • Check that you’re forming the HMAC signature correctly. Any slight change in message formats, like missing a component or adding extra spaces, can lead to invalid signatures.

Let’s try a slightly modified approach:

import time
import requests
import hmac
import hashlib

base_url = 'https://api.coinex.com'
request_path = '/v2/account/info'
timestamp = int(time.time() * 1000)
prepared_message = "GET" + request_path + str(timestamp)

api_key = 'YOUR_API_KEY'
secret = 'YOUR_SECRET'

# Creating the signature
signature = hmac.new(bytes(secret, 'utf-8'), bytes(prepared_message, 'utf-8'), hashlib.sha256).hexdigest()

# Defining headers correctly
headers = {
    'X-COINEX-KEY': api_key,
    'X-COINEX-SIGNATURE': signature,
    'X-COINEX-TIMESTAMP': str(timestamp)
}

# Making the request with headers
response = requests.get(base_url + request_path, headers=headers)

try:
    data = response.json()
    print(data)
except ValueError:
    print("Failed to get JSON response")

Ensure the time difference between your server and Coinex servers is minimal. Timestamp issues can also result in authentication errors. Consider using a library like ntplib to sync time if this becomes necessary. With these adjustments, your connection to the v2 API should function correctly.

The persistent 'Access ID does not exist' error in your Coinex API connection indicates specific areas to verify in your setup. Here’s a broader perspective and some adjustments you can consider:

  • Ensure API Key Validity: Double-check that your API key is activated and authorized for the Coinex API version 2 endpoints. If necessary, regenerate the keys and ensure they are stored securely without any external modification during the copy-paste process.
  • Verify Secret and Key Format: Any invisible characters or byte-encoding mismatches introduced during manual entry can disrupt authentication. Ensure you’re using the correct format and encoding matching the server requirements.
  • Adjust for Potential Rate Limits: While not mentioned, ensure that you're not hitting API rate limits, as this could indirectly cause permission-related errors.

Here’s an alternative version of the code with additional synchronization checks:

import time
import requests
import hmac
import hashlib

base_url = 'https://api.coinex.com'
request_path = '/v2/account/info'
timestamp = int(time.time() * 1000)
prepared_message = "GET" + request_path + str(timestamp)

api_key = 'YOUR_API_KEY'
secret = 'YOUR_SECRET'

# Create signature
signature = hmac.new(bytes(secret, 'utf-8'), bytes(prepared_message, 'utf-8'), hashlib.sha256).hexdigest().lower()

# Define headers
headers = {
    'X-COINEX-KEY': api_key,
    'X-COINEX-SIGNATURE': signature,
    'X-COINEX-TIMESTAMP': str(timestamp)
}

# Send request
response = requests.get(base_url + request_path, headers=headers)

# Ensure proper JSON response
try:
    data = response.json()
    print(data)
except ValueError:
    print("Failed to receive a valid JSON response")

Ensure System Time Accuracy: Any drift in your server’s clock can lead to authentication failures. Using the ntplib to sync the time could help if you suspect time discrepancies. With this holistic approach, you should achieve a successful integration into the Coinex API v2.

Hey Alex_Brave, I understand how tricky these API integrations can get especially when jumping to a new version. Let's troubleshoot the 'Access ID does not exist' error you're encountering with some practical and efficient steps.

First, it's crucial to ensure your API key is correctly set up for v2 access. Here's a quick rundown to help optimize and fix potential issues:

  • Verify API Permissions: Double-check that your API key has the necessary permissions enabled within your Coinex account. It must have the right access to the v2 endpoints.
  • Eliminate Spaces: When copying the api_key and secret, ensure no extra spaces exist before or after these strings. These whitespace errors can lead to failures in authentication.
  • HMAC Generation: Be precise with signature generation. Any discrepancies in the prepared message, such as missing characters or additional spaces, can cause invalid authentication.

Here's a refined version of your code with a slight improvement for creating the headers:

import time
import requests
import hmac
import hashlib

base_url = 'https://api.coinex.com'
request_path = '/v2/account/info'
timestamp = int(time.time() * 1000)
prepared_message = "GET" + request_path + str(timestamp)

api_key = 'YOUR_API_KEY'
secret = 'YOUR_SECRET'

# Create signature
signature = hmac.new(bytes(secret, 'utf-8'), bytes(prepared_message, 'utf-8'), hashlib.sha256).hexdigest()

# Headers setup
headers = {
    'X-COINEX-KEY': api_key,
    'X-COINEX-SIGNATURE': signature,
    'X-COINEX-TIMESTAMP': str(timestamp)
}

# Execute API request
response = requests.get(base_url + request_path, headers=headers)

try:
    data = response.json()
    print(data)
except ValueError:
    print("Failed to get JSON response")

The server clock drift can also affect authentication. Ensure your system time is in sync—using libraries like ntplib for time synchronization might be advantageous if you continue experiencing time-related issues. Addressing these areas should facilitate smoother integration with Coinex API v2.

To connect Python with Coinex API v2, the 'Access ID does not exist' error suggests an issue with your api_key. Verify:

  • Your API key has permissions for v2 endpoints.
  • There's no extra whitespace around the api_key or secret.
  • HMAC signature generation is precise without missing/extra spaces.

Use this modified code:

import time
import requests
import hmac
import hashlib

base_url = 'https://api.coinex.com'
request_path = '/v2/account/info'
timestamp = int(time.time() * 1000)
prepared_message = "GET" + request_path + str(timestamp)

api_key = 'YOUR_API_KEY'
secret = 'YOUR_SECRET'

signature = hmac.new(bytes(secret, 'utf-8'), bytes(prepared_message, 'utf-8'), hashlib.sha256).hexdigest()

headers = {
    'X-COINEX-KEY': api_key,
    'X-COINEX-SIGNATURE': signature,
    'X-COINEX-TIMESTAMP': str(timestamp)
}

response = requests.get(base_url + request_path, headers=headers)

try:
    data = response.json()
    print(data)
except ValueError:
    print("Failed to get JSON response")

Ensure server time sync if clock drift is an issue. This should resolve the integration problem.