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)
Initialize an AccountAPI instance with use_server_time=True.
Perform any API request that requires the 'OK-ACCESS-TIMESTAMP' header.
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.
Description:
In the
python-odx
library, when creating an API instance (e.g.,AccountAPI
) with theuse_server_time=True
parameter, theOkxClient._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:
AccountAPI
instance withuse_server_time=True
.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 withuse_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:
Additional Context:
This issue prevents all
python-odx
users from successfully making API requests withuse_server_time=True
, affecting operations that rely on accurate server time synchronization.