Authentication
Most of the API functionality requires the client to be authenticated.
Here is how to get an API Key and authenticate with both APIs:
Generate an API Key and Private Key
Create an account on the Power Trade's web application.
Click on the account profile menu in the top right and choose
API Keys
Click New API Key
Make sure the API Key type is set to Market Proxy
- The resulting API Key
api_key
and Private keyprivate_key
can be used to generate a JWT.
Generate an access token - jwt
Use the ES256
algorithm and add {client: "api"}
to the payload when generating the token jwt_token
.
Example in python
Using PyJWT
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
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
Use the JWT to authenticate with the API
WebSocket
Send the following message once the Web Socket connection is open
{
"authenticate": {
"credentials_secret": "jwt_token",
"user_tag": "unique_request_id"
}
}
HTTP Request
Add a credentials_secret: jwt_token
header to the request