This project demonstrates how to interact with a trade server using both REST API and WebSocket protocols. The examples are implemented in JavaScript and include HTML files for testing the functionality in a browser.
├── apiExample.html # Example for interacting with the REST API
├── webSocketExample.html # Example for interacting with the WebSocket API
├── javascript.js # Core JavaScript functions for API and WebSocket communication
├── styles.css # Styling for the HTML pages
├── Readme.md # Project documentation
- Access to a trade server with valid credentials (login, password, and Trade Server Admin API).
- Note that Trade Server API port starts with 2, Web Socket port starts with 3.
The apiExample.html file demonstrates how to authenticate and fetch symbols using the REST API.
- Open
apiExample.htmlin your browser. - Fill in the following fields:
- Login: Your login ID.
- Password: Your password.
- Trade Server Admin API: The URL of the trade server.
- Select the authentication type (
NonceorTimestamp). - Click Login to authenticate.
- Once logged in, click Get Symbols to fetch the list of symbols.
The webSocketExample.html file demonstrates how to connect to the WebSocket API, send requests, and handle responses.
- Open
webSocketExample.htmlin your browser. - Fill in the following fields:
- Login: Your login ID.
- Password: Your password.
- Trade Server Admin API: The URL of the trade server.
- Tarde Server Public WebSocket URL: The tarde server public WebSocket URL.
- Select the authentication type (
NonceorTimestamp). - Click Login to authenticate.
- Click Connect to establish a WebSocket connection.
- Use the following buttons to interact with the WebSocket:
- Ping: Send a ping request.
- Subscribe: Subscribe to a symbol (e.g.,
EURUSD). - Unsubscribe: Unsubscribe from a symbol.
- Close Connection: Close the WebSocket connection.
The javascript.js file contains reusable functions for API and WebSocket communication:
- HMAC Digest Generation:
getHMACDigest(secret, body)generates an HMAC signature using thecrypto.subtleAPI. - Base64 URL Encoding:
toBase64Url(str)converts a Base64 string to a URL-safe format. - Header Generation:
getPOSTHeaders(user, data, authenticationMethod)generates headers for POST requests.getGETHeaders(user)generates headers for GET requests.
- Fetch Data:
fetchData({ url, method, headers, data })sends HTTP requests and handles responses.
The styles.css file provides basic styling for the HTML pages, ensuring a clean and user-friendly interface.
- Ensure that the server URLs and credentials are correct before testing.
- The examples may require adjustments.

