# API Authentication | Secure Access to PowerTrade Trading API

All private endpoints require a valid access token.

## Generate an API Key and Private Key[​](https://api-docs-5180b.web.app/docs/authentication#generate-an-api-key-and-private-key)

* Create an account on the [Power Trade's web application](https://app.power.trade/api-keys).
* In the account profile menu in the top right and choose `API Keys`
* The resulting API Key `api_key` and Private key `private_key` can be used to generate a JWT.

## Generate an access token - JWT[​](https://api-docs-5180b.web.app/docs/authentication#generate-an-access-token---jwt) <a href="#generate-an-access-token---jwt" id="generate-an-access-token---jwt"></a>

Use the `ES256` algorithm and add `{client: "api"}` to the payload when generating the token `jwt_token`.

**Example in python**

Using [PyJWT](https://pyjwt.readthedocs.io/en/stable/)

```python
def generate_access_token(api_key, private_key):
    now = utils.time.time_s()
    return jwt.encode({"exp": now + 60, "iat": now,
                       "sub": api_key, "client": "api"}, private_key, algorithm="ES256")
```

**Example in Node.js**

Using [jsrsasign](https://github.com/kjur/jsrsasign)

```javascript
import rs from "jsrsasign";

const header = { alg: "ES256", typ: "JWT" };

const payload = {
  sub: api_key,
  iat: rs.KJUR.jws.IntDate.get("now"),
  exp: getUnixTime(add(Date.now(), { days: 10 })),
  client: "api",
  nonce: getUnixTime(Date.now()),
};

const headerString = JSON.stringify(header);
const payloadString = JSON.stringify(payload);

return rs.KJUR.jws.JWS.sign("ES256", headerString, payloadString, private_key);
```

**Web Based JWT builder**

If you want a quick way to verify that your API Key is working, you can also use our web based jwt builder:

<https://app.power.trade/jwt-builder>

## Still have questions?

**Email Support:** <support@power.trade>

**Telegram:** <https://t.me/power_trade>

\\


---

# Agent Instructions: 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:

```
GET https://support.power.trade/api/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
