MT5 Client gRPC example for Node.JS
Methods browser:
https://doc.gendocu.com/mtapiio/api/mt5grpc
Ready to run example:
https://git.mtapi.io/root/grpc-proto/-/archive/main/grpc-proto-main.zip
Firstly install libraries:
npm i @grpc/grpc-js @grpc/proto-loader minimist nodemon
Download proto file:
https://git.mtapi.io/root/grpc-proto/-/raw/main/mt5/protos/mt5.proto?inline=false
After that you can run this simple example:
'use strict';
const PROTO_PATH = __dirname + '/mt5.proto';
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
});
const mt5grpc = grpc.loadPackageDefinition(packageDefinition).mt5grpc;
function main() {
const connection = new mt5grpc.Connection(
"mt5grpc.mtapi.io",
grpc.credentials.createSsl()
//grpc.credentials.createInsecure()
);
const mt5 = new mt5grpc.MT5(
"mt5grpc.mtapi.io",
grpc.credentials.createSsl()
);
const subscriptions = new mt5grpc.Subscriptions(
"mt5grpc.mtapi.io",
grpc.credentials.createSsl()
);
const streams = new mt5grpc.Streams(
"mt5grpc.mtapi.io",
grpc.credentials.createSsl()
);
connection.Connect({ user: 62333850, password: "tecimil4", host: "78.140.180.198", port: 443 }, function (err, response) {
const token = response.result;
console.log('id:', token);
mt5.AccountSummary({ id: token }, function (err, response) {
console.log('AccountSummary:', response.result);
});
subscriptions.Subscribe({ id: token, symbol: "EURUSD" }, function (err, response) {
console.log('Subscribe:', response.result);
});
var onquote = streams.OnQuote({ id: token });
onquote.on("data", function (st) {
console.log("OnQuote message :", st.result);
});
onquote.on("end", function () {
console.log("OnQuote end:");
});
});
}
main();
setTimeout(function () {
console.log('Done');
}, 30000);