Getting Started

We provide accurate and reliable forex data via easy-to-use delivery methods. We use WSS and WebSockets which make it easier to receive data. Authentication is over a secure WSS protocol and responses are in JSON Format.

Following are a few simple steps to start receiving the market data.

  1. Sign up for API : Sign Up

  2. Start your Socket trial : Start Trial.

  3. Get your Streaming API key : Get your Streaming Data key.

  4. Start getting data : Connect to API


Quick Start Guide

We have created several of tutorials to help you get started with our Forex Websocket API. Our tutorials cover various topics, such as Golang, Python, NodeJS, C#.

See our quick start tutorials on getting started : How to start a WebSocket Trial


Authentication

You need to include your Forex API key with the initial request when you start your connection. You can find your API key under your account once you log in.

Our streaming data API documentation is extensive, and you can see below all the available routes and currencies to help you integrate our data within your applications. If you are new to WebSockets and SocketIO, visit our Tutorial page that explains sockets in greater detail.

Available Currencies For WebSockets and SocketIO

We support over 60+ currency pairs on our Websockets. To access a list of currencies available, visit our websocket currencies list page.

See the complete list of global Market CFDs we provide via WebSockets. You need to add USD at the end of each CFD code for Websockets. For example. TSLA should be TSLAUSD.

Websocket

WebSocket is a bidirectional protocol to get real-time data to help you build applications that require low-latency data. The TraderMade WebSocket API provides a simple implementation with easy setup in minutes.

URL Protocol Description
marketdata.tradermade.com/feedadv wss Connect using the above url and once open send JSON including streaming API key(userKey) and comma-separated symbol string to login and subscribe (as shown below).
Events Type Description
On open Connection Event / Send Send user key and comma seperated symbol string in JSON format - example:
{"userKey":"user_api_key", "symbol":"EURUSD,GBPUSD"}

If you want to receive SSV or CSV format just add fmt in above json to get that format - example:
{"userKey":"user_api_key", "symbol":"EURUSD,GBPUSD", "fmt":"CSV"}
On message Connection Event / Receive Will receive a JSON for the currencies subscribed with symbol, bid, ask, mid, and timestamp" (Optional). If you provide fmt parameters on open, then CSV or SSV will be returned.
On disconnect Connection Event On disconnect, you will receive a response if there is a reason for the disconnection.

SEND JSON ON OPEN (TO RECV JSON)

{"userKey":"user_api_key", "symbol":"EURUSD,GBPUSD"}

RECV JSON ON MESSAGE

{
    "symbol": "EURUSD",
    "ts": "1614076641",
    "bid": 1.21469,
    "ask": 1.2147,
    "mid": 1.214695
}

SEND JSON ON OPEN (TO RECV SSV)

{"userKey":"user_api_key", "symbol":"EURUSD,GBPUSD", "fmt":"SSV"}

RECV SSV ON MESSAGE

EURUSD 1614692703994 1.20232 1.20232
GBPUSD 1614692849259 1.38971 1.38974

SocketIO

SocketIO is a wrapper for websocket protocol implementation to get real-time data to help you build applications that require low-latency data. The TraderMade SocketIO API can be connected in minutes using our simple implementation documentation. Our SocketIO is currently compatible with version 2 only.

URL Protocol Description
marketdata.tradermade.com https Connect using the above url and emit streaming API key (userKey) on login and listen on handshake for successful login.
Events Type Description
login Connection Event / Send Login by sending JSON - example:
handshake Connection Event / Receive Successful connection will receive a response, "Welcome to the TMS Data Feed."
symbolSub Data Event / Send Subscribe to a new currency pair by sending JSON - example: {symbol: "USDJPY"}. Send multiple requests to subscribe to more than one symbol.
subResponse Data Event / Receive On subscribing to a new currency pair will receive the "Subscribed to symbol" message.
price Data event / Receive If a symbol is subscribed will receive "symbol bid ask mid date time" string, which is space delimited
disconnect Connection Event On disconnect, you will receive a response if there is a reason for disconnection.

EMIT JSON ON LOGIN

{userKey: "user_api_key"}

RECV STRING ON HANDSHAKE

Welcome to the TMS Data Feed

EMIT JSON ON SYMBOLSUB

{symbol: "USDJPY"}

RECV STRING ON SUBRESPONSE

Subscribed to symbol

RECV CSV ON PRICE

USDJPY 105.265 105.265 105.264999 20201015-15:18:15.215

Examples

Your Streaming API Key is included in all the sample codes when logged in. So you can use any example right away. Only you can see this key.

Select Language

Websocket Example

require_once("vendor/autoload.php");

$client = new WebSocket\Client("wss://marketdata.tradermade.com/feedadv");

$message =  $client->receive();
echo $message;

$client->text("{\"userKey\":\"user_api_key\", \"symbol\":\"GBPUSD,EURUSD\"}");

while(true){
        $message =  $client->receive();

        if(strcmp($message,"connected") !== 0){
                $decoded_json = json_decode($message);
                echo $decoded_json->symbol, " ", $decoded_json->ts, " ", $decoded_json->bid, " ", $decoded_json->ask, "\n";
        }
}

SocketIO Example

// using the ElephantIO library
// composer require elephantio/elephant.io

<?php
require_once 'vendor/autoload.php';

use ElephantIO\Client;
use ElephantIO\Engine\SocketIO\Version2X;

// Create Socket.IO client
$client = new Client(new Version2X('https://marketdata.tradermade.com'));

try {
    // Connect to server
    $client->initialize();
    echo "I'm connected!\n";

    // Send login message
    $client->emit('login', ['userKey' => 'user_api_key']);

    // Listen for events in a loop
    while (true) {
        // Read incoming messages
        $message = $client->read();

        if ($message) {
            $eventName = $message['name'] ?? '';
            $data = $message['args'][0] ?? [];

            switch ($eventName) {
                case 'connect':
                    echo "Connected successfully!\n";
                    break;

                case 'connect_error':
                    echo "The connection failed!\n";
                    break;

                case 'message':
                    echo "I received a message!\n";
                    print_r($data);
                    break;

                case 'handshake':
                    echo "HandShake: ";
                    print_r($data);

                    // Subscribe to symbols
                    $client->emit('symbolSub', ['symbol' => 'USDJPY']);
                    $client->emit('symbolSub', ['symbol' => 'GBPUSD']);
                    $client->emit('symbolSub', ['symbol' => 'EURUSD']);
                    break;

                case 'price':
                    echo "Price Data: ";
                    print_r($data);
                    break;

                default:
                    if ($eventName) {
                        echo "Received event '$eventName': ";
                        print_r($data);
                    }
                    break;
            }
        }

        // Small delay to prevent excessive CPU usage
        usleep(100000); // 0.1 seconds
    }

} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
} finally {
    // Close connection
    $client->close();
}
?>