Skip to content

Incorrect Timestamp Format in 'OK-ACCESS-TIMESTAMP' Header When use_server_time=True is Used #55

Closed

Description

@grzhan

Description:

In the python-odx library, when creating an API instance (e.g., AccountAPI) with the use_server_time=True parameter, the OkxClient._get_timestamp method retrieves the server time as a Unix millisecond timestamp (e.g., "1607417337715"). However, the OKX API expects the 'OK-ACCESS-TIMESTAMP' request header to be in ISO 8601 format (e.g., "2020-12-08T09:08:57.715Z"). Due to this mismatch in the timestamp format, requests to the OKX API fail with error code 50102, indicating an expired timestamp.

Steps to Reproduce:

import okx.Account as Account

API_KEY = 'xxxxx'
SECRET_KEY = 'xxxxxx'
PASSPHRASE = 'xxxxxx'

flag = '0' 
accountAPI = Account.AccountAPI(API_KEY, SECRET_KEY, PASSPHRASE, flag=flag, use_server_time=True)

result = accountAPI.get_account_balance()
print(result)
  1. Initialize an AccountAPI instance with use_server_time=True.
  2. Perform any API request that requires the 'OK-ACCESS-TIMESTAMP' header.
  3. Observe that the OKX API returns an error code 50102, indicating that the request timestamp is expired.

Expected Behavior:

The OkxClient._get_timestamp method should correctly format the server time as an ISO 8601 timestamp to match the OKX API's expectations, ensuring that API requests with use_server_time=True succeed without timestamp-related errors.

Actual Behavior:

API requests fail with error code 50102 due to a mismatch in the expected timestamp format in the 'OK-ACCESS-TIMESTAMP' request header.

Possible Solution:

Adjust the OkxClient._get_timestamp method to convert the Unix millisecond timestamp to an ISO 8601 formatted string before including it in the 'OK-ACCESS-TIMESTAMP' header. This conversion should account for the necessary precision and timezone (UTC) to ensure compatibility with OKX API requirements.

Environment:

  • Library version: 0.2.8
  • Python version: 3.11.8
  • Operating System: Windows 11 Professional Edition

Additional Context:

This issue prevents all python-odx users from successfully making API requests with use_server_time=True, affecting operations that rely on accurate server time synchronization.

Activity

  1. added a commit that references this issue on Mar 17, 2024
    d4623fd
  2. mzaeemnasir commented on Apr 2, 2024

    @mzaeemnasir

    Please commit this, I got the same issue.

  3. standyyyy commented on Apr 6, 2024

    @standyyyy

    me too , please commit it

  4. added a commit that references this issue on Jul 28, 2024
    26956b9
  5. added a commit that references this issue on Sep 1, 2026
    3c74180
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions