Skip to content

OKX request sign error #2553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
S3toGreen opened this issue Apr 24, 2025 · 2 comments
Closed

OKX request sign error #2553

S3toGreen opened this issue Apr 24, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@S3toGreen
Copy link

Bug Report

okx request sign error

the original _sign function in nautilus_trader/adapters/okx/http/client.py

    def _sign(self, timestamp: str, method: str, url_path: str, body: str) -> str:
        if body == "{}" or body == "None":
            body = ""
        message = str(timestamp) + method.upper() + url_path + body
        digest = hmac_signature(self._api_secret, message).encode()
        return base64.b64encode(digest).decode()

and _login function in nautilus_trader/adapters/okx/websocket/client.py

    async def _login(self):
        if self._api_secret is None:
            raise ValueError("`api_secret` was `None` for private websocket")

        timestamp = int(self._clock.timestamp())
        message = str(timestamp) + "GET/users/self/verify"
        digest = bytes.fromhex(hmac_signature(self._api_secret, message))
        sign = base64.b64encode(digest).decode()
        payload = {
            "op": "login",
            "args": [
                {
                    "apiKey": self._api_key,
                    "passphrase": self._passphrase,
                    "timestamp": str(timestamp),
                    "sign": sign,
                },
            ],
        }
        await self._send(payload)

result is not expected and get rejected from exchange.
cast to byte string solve the error in both websocket and http

        digest = bytes.fromhex(hmac_signature(self._api_secret, message))
@S3toGreen S3toGreen added the bug Something isn't working label Apr 24, 2025
@cjdsellers cjdsellers changed the title okx request sign error OKX request sign error Apr 25, 2025
@cjdsellers
Copy link
Member

Hi @S3toGreen

Thanks for the report.

The OKX integration is still in building status, and so potentially not in a working state.

I'll make sure to apply your suggested fix though and credit you in the release notes.

@cjdsellers
Copy link
Member

Now fixed from 86b0c0c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

2 participants