🔑Authentication

Endpoint

GET /api/v1/ws-token

Description

This endpoint is designed to provide you with a secure method to authenticate WebSocket connections within your application. By following a simple two-step process, you can obtain a temporary token and use it to establish an authenticated WebSocket connection. Below are the steps you need to follow:

Step 1: Obtain a WebSocket Authentication Token

To initiate a WebSocket connection, you first need to obtain an authentication token by making a GET request to the /api/v1/ws-token endpoint. You must include your API key in the request header as x-api-key. Here's a sample curl command to obtain the token:

curl --location 'https://data.lynxcrypto.app/api/v1/ws-token' \
--header 'x-api-key: YourApiKeyHere'

Upon a successful request, the server will respond with a JSON object containing the token field. This token is valid for a limited time period (10 minutes) to ensure security.

Step 2: Establish a WebSocket Connection

Once you have obtained the authentication token, you can use it to establish a WebSocket connection. Append the token as a query parameter named token to your WebSocket URL. This process authenticates the WebSocket session, enabling secure communication.

Here is how you can modify your WebSocket URL:

let websocketUrl = "wss://data.lynxcrypto.app/ws"; // Your WebSocket endpoint
let token = "ObtainedToken"; // Replace with your obtained token
let websocketUrlWithToken = `${websocketUrl}?token=${token}`;
let websocket = new WebSocket(websocketUrlWithToken);

After establishing the connection, you can use the WebSocket as usual to subscribe to channels.

Reconnecting

In case the WebSocket connection closes and you need to reconnect, ensure to obtain a new authentication token following the same steps above. This practice ensures that each connection is securely authenticated.

Headers

  • x-api-key (required): A valid API key.

Example

curl -X GET 'https://data.lynxcrypto.app/api/v1/ws-token'
-H 'x-api-key: <YOUR_API_KEY>'

Response

{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcGlfa2V5IjoiR1A5cUpSazRpODJPVkZSYXppak5QNW4wT1dVaEhuNmcyR1dKTEF1cyIsImV4cCI6MTcxMDUyNTY4Nn0.yES9q2lQ9C4r9STEabOVD3TvM4TIIBYX5eVVdb-USdM"
}

Response Codes

  • 200: Success. Returns the USD price for the given token.

  • 401: Forbidden. The x-api-key header is not provided or is invalid.

Last updated