Gate.io APIv4 AUTH request signature error

Viewed 278

I struggle with Authentication request to gate.io apiv4

Reference: https://www.gate.io/docs/apiv4/en/#api-signature-string-generation

I'm getting this response:

{"label":"INVALID_SIGNATURE","message":"Signature mismatch"}"

My code:

function signature($method, $url, $body, $timestamp) {
        $body = is_array($body) ? json_encode($body) : $body;
        $fullPath = parse_url($this->host, PHP_URL_PATH) . $url;
        $fmt = "%s\n%s\n%s\n%s\n%s";
        $hashedPayload = hash("sha512", $body);
        $signatureString = sprintf(
            $fmt,
            $method,
            $fullPath,
            "",
            $hashedPayload,
            $timestamp
        );

        $signature = hash_hmac("sha512", $signatureString, $this->SECRET_KEY);
        return $signature;
    }

not sure where the error is, does anyone have similar issues?

Thank you

0 Answers
Related