mt4manager
v0.1.7
Published
Node.js native addon starter for MetaTrader 4 Manager API
Downloads
85
Maintainers
Readme
mt4manager
TypeScript-friendly Node.js bindings for the MetaTrader 4 Manager API.
mt4manager lets you use the MT4 Manager API from JavaScript/TypeScript without writing C++ directly.
Built as a native Node.js addon using Node-API (node-addon-api), it provides a modern async API for brokerages, internal tools, and MT4 infrastructure services.
Features
- Native Node.js addon powered by Node-API
- TypeScript-first developer experience
- Runtime DLL loading (
mtmanapi64.dll) - Async MT4 connection lifecycle
- Real-time pumping/event updates
- User management
- Symbol management
- Transactions API
- Positions API
- Event subscriptions
- One MT4 native client per manager instance
- Windows-focused MT4 integration
Status
Beta — APIs may change before
v1.0.0.
This project is actively under development and intended for:
- brokerages
- prop firms
- internal tooling
- automation systems
- MT4 infrastructure services
Installation
npm install mt4managerRequirements
Operating System
- Windows x64
Runtime
- Node.js
>=20 - Recommended: Node.js
22
MetaTrader Manager DLL
This package does not include:
mtmanapi.dllmtmanapi64.dll
You must provide your own licensed MT4 Manager API DLL.
Example:
./dll/mtmanapi64.dllDevelopment Requirements
Building the native addon from source requires:
- Windows
- Node.js >= 20
- Python 3
- Visual Studio 2022 Build Tools
- Desktop development with C++
- MSVC v143 toolset
- Windows SDK
- node-gyp
Install node-gyp:
npm install -g node-gypQuick Start
import { createMT4Manager } from "mt4manager";
const manager = await createMT4Manager({
dllPath: "./dll/mtmanapi64.dll",
server: "server.com:443",
login: 9707,
password: "password",
pump: true,
});
// listen for user updates
manager.users.on("update", (user) => {
console.log("User updated:", user);
});
try {
// get user
const user = await manager.users.get(123456);
// update user
await manager.users.update(123456, {
name: "New Name",
});
} finally {
// cleanup
await manager.close();
}API Overview
Users
Get User
const user = await manager.users.get(123456);Update User
await manager.users.update(123456, {
name: "Updated Name",
});Create User
const user = await manager.users.create({
group: "demotest",
name: "John Doe",
email: "[email protected]",
});User Updates (Pump Events)
manager.users.on("update", (user) => {
console.log(user);
});Symbols
Get Symbol
const symbol = await manager.symbols.get("EURUSD");Get All Symbols
const symbols = await manager.symbols.getAll();Subscribe to Tick Updates
await manager.symbols.subscribe("EURUSD");
manager.symbols.watch("EURUSD", (symbol) => {
console.log(symbol.bid, symbol.ask);
});Transactions
Deposit
const tx = await manager.transactions.deposit({
login: 123456,
amount: 100,
comment: "Initial deposit",
});Withdrawal
const tx = await manager.transactions.withdrawal({
login: 123456,
amount: 50,
comment: "Client withdrawal",
});Credit In
const tx = await manager.transactions.creditIn({
login: 123456,
amount: 25,
comment: "Bonus credit",
});Credit Out
const tx = await manager.transactions.creditOut({
login: 123456,
amount: 25,
comment: "Remove bonus",
});Get Transaction
const tx = await manager.transactions.get(100000);Positions
Open Market Position
import { TradeCommand } from "mt4manager";
const trade = await manager.positions.open({
login: 123456,
symbol: "EURUSD",
cmd: TradeCommand.Buy,
volume: 1,
comment: "open-position",
price: 1.17,
});Close Position
await manager.positions.close({
id: trade.id,
volume: trade.volume,
price: trade.openPrice,
});Modify Position
await manager.positions.modify({
id: trade.id,
sl: 1.1,
tp: 1.2,
price: 1.17,
});Modify Position Comment
await manager.positions.modifyComment(trade.id, "updated-comment");Open Pending Order
const pending = await manager.positions.open({
login: 123456,
symbol: "EURUSD",
cmd: TradeCommand.BuyLimit,
volume: 1,
comment: "buy-limit",
price: 1.0,
});Cancel Pending Order
await manager.positions.cancel(pending.id, pending.cmd);Close Opposite Positions By Ticket
const buy = await manager.positions.open({
login: 123456,
symbol: "EURUSD",
cmd: TradeCommand.Buy,
volume: 1,
price: 1.17,
});
const sell = await manager.positions.open({
login: 123456,
symbol: "EURUSD",
cmd: TradeCommand.Sell,
volume: 1,
price: 1.17,
});
await manager.positions.closeBy(buy.id, sell.id);Close Multiple Opposite Positions
await manager.positions.closeMultipleBy(123456, "EURUSD");Listen For Pumped Trade Events
manager.positions.on("add", (trade) => {
console.log("Position opened:", trade);
});
manager.positions.on("update", (trade) => {
console.log("Position updated:", trade);
});
manager.positions.on("delete", (trade) => {
console.log("Position closed:", trade);
});Pumping
Pumping mode enables real-time updates from the MT4 server.
Example:
const manager = await createMT4Manager({
pump: {
ticks: true,
},
});Real-time updates are automatically emitted through module event handlers.
Environment Variables
Only needed for local development and tests. Consumers can pass config directly in code.
Example .env:
MT4_SERVER=server.com:443
MT4_LOGIN=9707
MT4_PASSWORD=abc123
MT4_DLL_PATH=./dll/mtmanapi64.dll
MT4_USER_LOGIN=100010
MT4_TEST_GROUP=demotestDevelopment
Install Dependencies
npm installBuild
npm run buildRebuild
npm run rebuildRun Tests
npm testProject Structure
src/
native/
include/
build/
dist/
test/Native Architecture
mt4manager is built using:
- Node-API (
node-addon-api) - C++
- TypeScript
node-gyp
The project uses:
- thread-safe JS callback bridges
- native MT4 client wrappers
- async-safe event forwarding
- runtime DLL loading
- modular MT4 service wrappers
Example native wrapper:
bridge_->CallJs(UserPayload{*user, type}, BuildUserArgs);This architecture allows MT4 pump events to safely propagate from native C++ threads into JavaScript event handlers.
Important Notes
MT4 Licensing
Review MetaQuotes licensing terms before deploying or redistributing MT4 Manager API components.
Live Trading Warning
This package can perform:
- deposits
- withdrawals
- credits
- user modifications
- position operations
Use carefully on production MT4 servers.
Publishing
Before publishing:
npm run clean
npm run build
npm test
npm run pack:check
npm version patch
npm publishCurrent Coverage
- Users
- Symbols
- Transactions
- Positions
- Pumping/event updates
- Native async wrappers
- TypeScript support
License
MIT
Repository
GitHub:
https://github.com/GilSokolov/mt4manager