> For the complete documentation index, see [llms.txt](https://rwaperp-1.gitbook.io/rwaperp-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rwaperp-1.gitbook.io/rwaperp-docs/rwa-perp-b2b-api/authentication/request-signing.md).

# Request signing

|                | REST                                                                                                             | Private WS                                                        |
| -------------- | ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| String to sign | `{timestamp}{METHOD}{path}{body}`                                                                                | `{timestamp}`                                                     |
| Sent as        | `RWA-*` headers                                                                                                  | `rwa_api_key` / `rwa_timestamp` / `rwa_sign` query parameters     |
| Notes          | `path` includes the query string; body is `""` for GET/DELETE; the POST body must match the signed bytes exactly | On receiving `{"event":"ping"}` you must reply `{"event":"pong"}` |

```python
import base64, json, time, urllib.parse, urllib.request, base58, websocket
from nacl.signing import SigningKey

ACCOUNT_ID, SECRET_B58 = "0x...", "..."
BASE = "https://api-trade.rwaperp.xyz"

signing = SigningKey(base58.b58decode(SECRET_B58))
pub = "ed25519:" + base58.b58encode(signing.verify_key.encode()).decode()

def signed_request(method: str, path: str, body: str = ""):
    ts = str(int(time.time() * 1000))
    sig = base64.urlsafe_b64encode(
        signing.sign(f"{ts}{method.upper()}{path}{body}".encode()).signature
    ).decode().rstrip("=")
    req = urllib.request.Request(
        BASE + path,
        data=body.encode() if body and method.upper() in ("POST", "PUT") else None,
        headers={"RWA-Account-Id": ACCOUNT_ID, "RWA-Api-Key": pub,
                 "RWA-Timestamp": ts, "RWA-Signature": sig, "Content-Type": "application/json"},
        method=method.upper(),
    )
    with urllib.request.urlopen(req, timeout=30) as resp:
        return json.loads(resp.read())

def private_ws_url(account_id: str) -> str:
    ts = str(int(time.time() * 1000))
    sign = base64.urlsafe_b64encode(signing.sign(ts.encode()).signature).decode().rstrip("=")
    q = urllib.parse.urlencode({"rwa_api_key": pub, "rwa_timestamp": ts, "rwa_sign": sign})
    return f"wss://api-trade.rwaperp.xyz/ws/private/v2/ws/private/stream/{account_id}?{q}"

# signed_request("GET", "/v1/client/info")
# ws = websocket.create_connection(f"wss://api-trade.rwaperp.xyz/ws/public/ws/stream/{ACCOUNT_ID}")
# ws.send(json.dumps({"event": "subscribe", "topic": "PERP_ETH_USDC@ticker"}))
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://rwaperp-1.gitbook.io/rwaperp-docs/rwa-perp-b2b-api/authentication/request-signing.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
