Skip to Content
Welcome to Level2 Help Center
APIAuthentication

Authentication

Accessing Broker APIs requires JWT (JSON Web Token) Authentication. To ensure a secure and stable connection, brokers must adhere to the following token management protocols.


JWT Generation Requirements

Brokers are responsible for generating a valid JSON Web Token for every session.

  • Mandatory Parameter: Each JWT must include a token_expiry parameter within the payload.
  • Parameter Function: This specifies the exact duration for which the token remains valid.

Token Expiry Policies

To maintain system security and performance, the following limits are strictly enforced:

PolicyRequirement
Recommended Expiry180 minutes (3 hours).
Automatic InvalidationTokens set with a validity exceeding 180 minutes will be automatically invalidated by the system.
Renewal ProtocolUpon expiration, a new JWT must be generated with a fresh 180-minute token_expiry value.

Implementation Note

Ensure your authentication logic handles the “Unauthorized” (401) error response by automatically triggering the generation of a new token. This prevents strategy interruptions during live market deployments.

Security Tip: Never share your private keys used for JWT signing. All token generation should occur in a secure, server-side environment.

from datetime import datetime, timezone, timedelta import jwt token_expiry = datetime.now(timezone.utc) + timedelta(minutes=180) user_data = {"domain": "to be shared separately", "token_expiry": token_expiry.timestamp()} token_string = jwt.encode(user_data, "secret token to be shared separately", algorithm="HS256") print(token_string) # use this token to authenticate the subsequent APIs

Here is a sample JWT token

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiJhbnRvc3RyYXRlZ3kudHJ5bGV2ZWwyLmNvbSIsInRva2VuX2V4cGlyeSI6MTc0MzE2OTkyMi43MzIzNzR9.LOTUbmvDgGiMqV_hcWM9BJguJkFABRNZu6vlObKmedo
Last updated on