[Python] OKX error {'msg': 'Invalid OK-ACCESS-TIMESTAMP', 'code': '50112'}

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    Issue with Timestamp Expiry Error

    Hello Forum Members,

    I'm encountering an issue with my Python code while interfacing with the OKEx API. Specifically, I'm receiving a {'msg': 'Invalid OK-ACCESS-TIMESTAMP', 'code': '50112'}. Here's a simplified version of the relevant code snippet:

    class OkexBot:
    def init(self, APIKEY: str, APISECRET: str, PASS: str):
    self.apikey = APIKEY
    self.apisecret = APISECRET
    self.password = PASS
    self.baseURL = 'https://www.okex.com'

    @staticmethod
    def get_time():
    time_cur = dt.datetime.now(dt.timezone.utc).isoformat("T", "milliseconds") + 'Z'
    return time_cur


    @staticmethod
    def signature(timestamp, method, request_path, body, secret_key):
    message = timestamp + method + request_path + body
    mac = hmac.new(bytes(secret_key, encoding='utf8'), bytes(message, encoding='utf-8'), digestmod='sha256')
    output = mac.digest()
    return base64.b64encode(output)

    def get_header(self, request='GET', endpoint='', body=''):
    cur_time = self.get_time()
    header = dict()
    header['CONTENT-TYPE'] = "application/json"
    header['OK-ACCESS-KEY'] = APIKEY
    header['OK-ACCESS-SIGN'] = self.signature(cur_time, request, endpoint, body, APISECRET)
    header['OK-ACCESS-TIMESTAMP'] = str(cur_time)
    header['OK-ACCESS-PASSPHRASE'] = PASS
    return header

    def withdrawal(self, account, amount):
    endpoint = '/api/v5/asset/withdrawal'
    url = self.baseURL + endpoint
    request = 'POST'
    body = {
    "amt": str(amount),
    "fee": "0.0096",
    "dest": "4",
    "ccy": "SOL",
    "chain": "SOL-Solana",
    "toAddr": account
    }
    body = json.dumps(body)
    header = self.get_header(request, endpoint, str(body))
    response = requests.post(url, headers=header, data=body)
    return response


    I changed the way to get the current time

    Continue reading...

Compartilhe esta Página