NEWIncluded in every planMetaTrader 4MetaTrader 5

MTsocketAPI SDK

A native library that connects your program directly to your broker's MetaTrader 4 or MetaTrader 5 server. No terminal, several accounts at once, on Windows and Linux.

Free with demo accounts, no license key needed.

  • No terminalnothing to install or keep open
  • 5 typed languagesC#, Python, Java, C++ and Rust
  • Windows and LinuxPC, VPS or Docker
  • Many accountsin one program

Check your broker first

The SDK works with the MetaTrader 5 brokers that offer the MetaTrader 5 web terminal, and with the MetaTrader 4 servers available in the MetaTrader 4 web terminal of MetaQuotes: not with all brokers. Before you buy, download the SDK and run the example with a demo account of your broker: demo accounts work without a license.

MetaTrader 5: you will need the address of your broker's web terminal (it starts with wss://). This video shows how to find it.

MetaTrader 4: you will need the name of your broker's server, as shown in MetaTrader 4 (for example MetaQuotes-Demo). You can check that it is available in the MetaTrader 4 web terminal.

Is your broker not available? The MTsocketAPI EA works with any MT4/MT5 broker, and it is included in the same subscription.

Why the SDK

The terminal's features, inside your program

No terminal

Your program connects straight to your broker's MetaTrader 4 or 5 server. Nothing to install, update or keep open.

Many accounts, one program

Open as many connections as you need in the same process: copy trading, hedging, monitoring, account managers.

Typed in 5 languages

C#, Python, Java, C++ and Rust, with typed models and auto-completion in your IDE. No JSON to parse.

Windows and Linux

The same code runs on your PC, on a Linux VPS or inside a Docker container.

Real-time prices

Ticks (and market depth in MT5) pushed to your code as events, with very low latency and low CPU usage.

Orders

Market, limit and stop orders, modify SL/TP, partial and full close, with the broker's result code.

History and candles

Deals, orders and positions history, and OHLC candles in any timeframe from M1 to MN1.

Economic calendar

The MQL5 economic calendar with actual, forecast and previous values, in UTC.

How it works

Your code is the terminal

With the EA, your code talks to a MetaTrader terminal. With the SDK, your program logs in to the MT4 or MT5 server itself, using the same secure WebSocket connection as the MetaTrader web terminal.

WITH THE EA Your programany language REST / WebSocketsTCP 81 MetaTrader terminal+ MTsocketAPI EA Broker serverMT4 / MT5WITH THE SDK Your program + MTsocketAPI SDKC#, Python, Java, C++, Rust · Windows or Linux secure WebSocket, no terminal Broker serverMT4 / MT5
Your language, typed

The same example in five languages

Connect, read the balance, stream EURUSD and send an order. The download includes a complete example for MetaTrader 5 and for MetaTrader 4 in each language.

connect · balance · ticks · order
using MtSocketApi;

var client = new MT5WebClient("wss://web.metatrader.app/terminal",
    new MT5WebClientOptions { LicenseKey = "YOUR-LICENSE-KEY" });
await client.ConnectAsync();
await client.LoginAsync(111111, "mypass");

Account account = await client.AccountInfoAsync();
Console.WriteLine($"Balance:  ");

var symbols = await client.LoadSymbolsAsync();
SymbolEntry eurusd = symbols.Find(s => s.Name == "EURUSD")!;
client.TickReceived += (_, t) => Console.WriteLine($"EURUSD  / ");
await client.SubscribeAsync(eurusd);

TradeResult r = await client.OpenMarketOrderAsync(eurusd, Side.Buy, 0.01);
Console.WriteLine($"  at ");
from mtsocketapi import MT5WebClient, MT5WebClientOptions, Side

client = MT5WebClient("wss://web.metatrader.app/terminal",
                      MT5WebClientOptions(license_key="YOUR-LICENSE-KEY"))
client.connect()
client.login(111111, "mypass")

account = client.account_info()
print(f"Balance:  ")

eurusd = next(s for s in client.load_symbols() if s.name == "EURUSD")
client.on_tick = lambda t: print("EURUSD", t.bid, t.ask)
client.subscribe([eurusd])

r = client.open_market_order(eurusd, Side.BUY, 0.01)
print(r.retcode, r.retcode_text, "at", r.price)
import com.mtsocketapi.*;

MT5WebClient client = new MT5WebClient("wss://web.metatrader.app/terminal",
        new MT5WebClientOptions().licenseKey("YOUR-LICENSE-KEY"));
client.connect();
client.login(111111L, "mypass");

Account account = client.accountInfo();
System.out.println("Balance: " + account.getBalance() + " " + account.getCurrency());

SymbolEntry eurusd = client.loadSymbols().stream()
        .filter(s -> s.getName().equals("EURUSD")).findFirst().get();
client.setOnTick(t -> System.out.println("EURUSD " + t.getBid() + " / " + t.getAsk()));
client.subscribe(eurusd);

TradeResult r = client.openMarketOrder(eurusd, Side.BUY, 0.01);
System.out.println(r.getRetcode() + " " + r.getRetcodeText() + " at " + r.getPrice());
#include <mtsocketapi/mtsocketapi.hpp>
#include <iostream>
using namespace mtsocketapi;

int main() {
    MT5WebClientOptions options;
    options.license_key = "YOUR-LICENSE-KEY";
    MT5WebClient client("wss://web.metatrader.app/terminal", options);
    client.connect();
    client.login(111111, "mypass");

    Account account = client.account_info();
    std::cout << "Balance: " << account.balance << " " << account.currency << "\n";

    for (const SymbolEntry& s : client.load_symbols())
        if (s.name == "EURUSD") );
            TradeResult r = client.open_market_order(s, Side::Buy, 0.01);
            std::cout << r.retcode << " " << r.retcode_text << " at " << r.price << "\n";
        }
}
use mtsocketapi::*;

fn main() -> Result<()> {
    let options = MT5WebClientOptions { license_key: Some("YOUR-LICENSE-KEY".into()), ..Default::default() };
    let client = MT5WebClient::new("wss://web.metatrader.app/terminal", options)?;
    client.connect()?;
    client.login(111111, "mypass")?;

    let account = client.account_info()?;
    println!("Balance: 0 0", account.balance, account.currency);

    let eurusd = client.load_symbols()?.into_iter().find(|s| s.name == "EURUSD").unwrap();
    client.on_tick(|t| println!("EURUSD  / ", t.bid, t.ask));
    client.subscribe(std::slice::from_ref(&eurusd))?;

    let r = client.open_market_order(&eurusd, Side::Buy, 0.01, None, None, "", None)?;
    println!("0 0 at 0", r.retcode, r.retcode_text, r.price);
    Ok(())
}

MetaTrader 4: create an MT4WebClient with the name of the server, for example new MT4WebClient("MetaQuotes-Demo"), instead of an MT5WebClient with the address of the web terminal. The rest of the code is the same.

Many accounts, one program

One connection per client, as many as you need

Different accounts, different brokers, all in the same process.

  • Copy trading and hedging between brokers
  • Risk monitoring and account management
  • No more one terminal per account

Several live accounts at once need the Unlimited plan.

three accounts
using MtSocketApi;

const string Key = "YOUR-LICENSE-KEY";   // Unlimited plan
var accounts = new[] {
    ("wss://web.metatrader.app/terminal", 111111L, "pass1"),
    ("wss://web.metatrader.app/terminal", 222222L, "pass2"),
    ("wss://web.metatrader.app/terminal", 333333L, "pass3"),
};

var clients = new List<MT5WebClient>();
foreach (var (url, login, password) in accounts)
);
    await c.ConnectAsync();
    await c.LoginAsync(login, password);
    clients.Add(c);
}

foreach (var c in clients)                   // one program, three live accounts
{
    Account a = await c.AccountInfoAsync();
    Console.WriteLine($"  ");
}
from mtsocketapi import MT5WebClient, MT5WebClientOptions

KEY = "YOUR-LICENSE-KEY"   # Unlimited plan
accounts = [("wss://web.metatrader.app/terminal", 111111, "pass1"),
            ("wss://web.metatrader.app/terminal", 222222, "pass2"),
            ("wss://web.metatrader.app/terminal", 333333, "pass3")]

clients = []
for url, login, password in accounts:
    c = MT5WebClient(url, MT5WebClientOptions(license_key=KEY))
    c.connect()
    c.login(login, password)
    clients.append(c)

for c in clients:                     # one program, three live accounts
    a = c.account_info()
    print(a.name, a.balance, a.currency)
import com.mtsocketapi.*;
import java.util.*;

String key = "YOUR-LICENSE-KEY";   // Unlimited plan
String url = "wss://web.metatrader.app/terminal";
long[] logins = ;
String[] passwords = { "pass1", "pass2", "pass3" };

List<MT5WebClient> clients = new ArrayList<>();
for (int i = 0; i < logins.length; i++) 

for (MT5WebClient c : clients) {      // one program, three live accounts
    Account a = c.accountInfo();
    System.out.println(a.getName() + " " + a.getBalance() + " " + a.getCurrency());
}
#include <mtsocketapi/mtsocketapi.hpp>
#include <iostream>
#include <memory>
#include <vector>
using namespace mtsocketapi;

int main() ;
    std::vector<Login> accounts = {
        {"wss://web.metatrader.app/terminal", 111111, "pass1"},
        {"wss://web.metatrader.app/terminal", 222222, "pass2"},
        {"wss://web.metatrader.app/terminal", 333333, "pass3"},
    };
    MT5WebClientOptions options;
    options.license_key = "YOUR-LICENSE-KEY";   // Unlimited plan

    std::vector<std::unique_ptr<MT5WebClient>> clients;
    for (const auto& acc : accounts) 

    for (auto& c : clients) {         // one program, three live accounts
        Account a = c->account_info();
        std::cout << a.name << " " << a.balance << " " << a.currency << "\n";
    }
}
use mtsocketapi::*;

fn main() -> Result<()> {
    let accounts = [
        ("wss://web.metatrader.app/terminal", 111111, "pass1"),
        ("wss://web.metatrader.app/terminal", 222222, "pass2"),
        ("wss://web.metatrader.app/terminal", 333333, "pass3"),
    ];

    let mut clients = Vec::new();
    for (url, login, password) in accounts {
        let options = MT5WebClientOptions { license_key: Some("YOUR-LICENSE-KEY".into()), ..Default::default() }; // Unlimited plan
        let c = MT5WebClient::new(url, options)?;
        c.connect()?;
        c.login(login, password)?;
        clients.push(c);
    }

    for c in &clients {               // one program, three live accounts
        let a = c.account_info()?;
        println!("0 0 0", a.name, a.balance, a.currency);
    }
    Ok(())
}
What you download

One zip, ready to run

The compiled library for Windows and Linux, the bindings for each language and ready-to-run MT5 and MT4 examples for each one.

mtsocketapi-sdk.zip
├── README.md            setup guide for each language
├── native/
│   ├── win-x64/         mtsocketapi_native.dll
│   └── linux-x64/       libmtsocketapi_native.so
├── bindings/
│   ├── csharp/          Visual Studio solution + ExampleMT5, ExampleMT4
│   ├── python/          package + example_mt5.py, example_mt4.py
│   ├── java/            classes + ExampleMT5.java, ExampleMT4.java
│   ├── cpp/             header-only C++17 + CMake examples (mt5, mt4)
│   └── rust/            crate + example_mt5, example_mt4
├── include/             mtsocketapi.h (C API)
└── selectors.default.json   web terminal selectors (Browser mode)
Requirements

What you need

Operating systemWindows 10/11 or Linux, 64-bit
C#.NET 8 (Visual Studio 2022)
Python3.8 or later, no extra packages
Java8 or later + JNA
C++C++17 compiler + CMake
Ruststable toolchain
BrokerMT5: brokers that offer the MetaTrader 5 web terminal. MT4: servers available in the MetaTrader 4 web terminal
Browser and Hybrid modesMT5 only: Microsoft Edge, Google Chrome or Chromium (optional: the default Direct mode needs nothing)
LicenseDemo accounts work without a key. Live accounts need a Retail, Professional or Unlimited plan.
EA or SDK?

You don't have to choose

Your subscription includes both. Use the one that fits each project.

MTsocketAPI EAMTsocketAPI SDK NEW
MetaTrader platformMT4 and MT5MT4 and MT5
BrokersAny MT4/MT5 brokerMT5 brokers that offer the MetaTrader 5 web terminal, and MT4 servers available in the MetaTrader 4 web terminal
MetaTrader terminal neededYes, the EA runs inside it (Windows, or Wine)No
How your code talks to itREST API and WebSockets (TCP port 81)Native library called from your code
LanguagesAny language that speaks HTTPC#, Python, Java, C++ and Rust (typed)
Where your program runsAny system: on the same computer as the terminal, or from Linux, macOS, Android... through the EA's IP (remote connections: Professional plan)Windows and Linux (64-bit): PC, VPS, Docker
Several accountsOne terminal per account. Need many accounts? Contact usMany accounts in one program (Unlimited plan)
Remote accessYes (Professional and Unlimited)Not needed: your program connects from anywhere
Indicators (SMA, ATR, custom...)Yes, from the terminalNo: compute them from the candles
Economic calendarYesYes
Best forExisting terminals, any language, indicatorsServers, VPS, Docker, multi-account, low resources
SDK questions

Good to know before you start

Is the SDK included in my subscription?

Yes. Every plan includes the EA and the SDK. They are two products with their own license: every payment email includes your EA license file, and the first one also includes your SDK license key, which then renews automatically with your subscription. With the Free plan, the SDK works with demo accounts without a license key.

Does the SDK work with MetaTrader 4?

Yes. The SDK works with MetaTrader 4 and MetaTrader 5, with the same license and the same plans: create an MT4WebClient for MT4 and an MT5WebClient for MT5, with the same methods. For MT4 you need the name of your broker's server, as shown in MetaTrader 4, your account number and your password. MetaTrader 4 has no market depth and no stop-limit orders, and it connects in Direct mode.

Which brokers work with the SDK?

Not all of them. With MetaTrader 5, the brokers that offer the MetaTrader 5 web terminal: you need the address of your broker's web terminal (this video shows how to find it). With MetaTrader 4, the servers available in the MetaTrader 4 web terminal of MetaQuotes (metatraderweb.app): you need the name of your broker's server. In both cases you also need your account number and your password. Before you buy, try the SDK with a demo account of your broker: demo accounts work without a license. If your broker is not available, use the EA.

Can I connect several accounts at once?

Yes. The Unlimited plan is designed for that: one program with as many live accounts as you need, connected at the same time. Retail and Professional include one live account. If you need many accounts with the EA, or a custom setup, contact us and we will find the right option for you.

Which connection mode should I use?

That is up to you. The default is Direct, the fastest: the SDK speaks the protocol of the web terminal itself, with every feature and nothing else to install. The SDK also has two modes that run the official web terminal in a hidden browser (Microsoft Edge, Google Chrome or Chromium), so they can keep working if MetaQuotes changes the protocol of the web terminal: Hybrid, which takes longer to start, and Browser, which is also slower in every operation. You choose the mode with one option when you create the client. Browser and Hybrid are for MetaTrader 5; MetaTrader 4 uses the Direct mode. See Connection modes.

How do I use my license key in the SDK?

Pass it when you create the client: LicenseKey in C#, license_key in Python, C++ and Rust, licenseKey(...) in Java. The first run needs an internet connection to activate it.

Why does the SDK ask me to update?

Each version of the SDK works for 3 years from its release. As the SDK comes with a monthly or yearly subscription, this guarantees that everyone runs an up-to-date, supported version, and leaves plenty of time to update. Your program warns you 60 days before; then download the latest version from this website, free with your subscription. Your code does not need to change.

Try it now with a demo account

No license needed for demo accounts: check that the SDK works with your broker before you buy.

Trading involves a high risk of loss. MTsocketAPI is a software tool, not investment advice: always test your programs on a demo account first. You are responsible for the orders your software sends. See the Terms of Service.

© 2020-2026 MTsocketAPI. All rights reserved.

Created with Mobirise ‌

Web Site Maker