End-user Onboarding

Learn how to use StockRepublic API to enhance the user experience by enabling profile creation, post interactions, member connections, and group discovery, fostering a thriving social trading community.

End-User Experience Integration

After completing the End-user Data Integration, our focus shifts to elevating the end-user experience. This includes enabling users to write and read posts, follow other members, discover groups to join, and more.

Obtaining an End-User Token

The end-user token is employed when making API calls on behalf of users, either directly from your customers or proxied via your backend, depending on your individual requirements.

To secure an end-user access token:

  1. Use the same End-User ID you've received when completing End-user Data Integration.
  2. Create a new exchange token using your Client ID as the issuer and the user as the subject, and sign it with your private key.
  3. Submit the exchange token to our user login endpoint, which returns an end-user token specific to that user.

Creating a Profile

Before accessing most end-user endpoints, users need to establish a Profile. This is generally the first step after obtaining the access token. The sole requirement is for users to select a unique username, but they can also opt to upload a profile picture or add a brief bio for self-description. Profiles store additional settings and consents, such as notification preferences.

For an in-depth guide on the token exchange flow, consult our onboarding recipe:

Token Exchange Process

Step 1: Prepare Exchange Token

Create an exchange token using the following key components:

  • Issuer: Your Client ID
  • Subject: End-user's unique identifier
  • Signing: Use your private RSA key
# Example exchange token preparation
exchange_token = create_jwt_token(
    issuer=client_id,
    subject=user_id,
    private_key=rsa_private_key
)

Step 2: Request End-User Token

Submit the exchange token to the user login endpoint:

curl -X POST https://api.stockrepublic.io/v1/users/token \
     -H "Content-Type: application/json" \
     -d '{
         "exchange_token": "'$EXCHANGE_TOKEN'"
     }'

Step 3: Use End-User Token

Once received, use the end-user token in API request headers:

curl -X GET https://api.stockrepublic.io/v1/users/profile \
     -H "Authorization: Bearer $END_USER_TOKEN"

Best Practices

  • Keep exchange tokens short-lived
  • Securely store private keys
  • Rotate keys periodically
  • Implement proper error handling for token exchanges