MT5 Manager gRPC example for Node.js

easy direct connection to any MT4 and MT5 server

MT5 Manager gRPC example for Node.js

Methods browser:

https://doc.gendocu.com/mtapiio/api/mng5grpc

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/mt5mng/protos/mt5mng.proto?inline=false

After that you can run this simple example:

'use strict';

const PROTO_PATH = __dirname + '/mt5mng.proto';

const parseArgs = require('minimist');

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 mng5grpc = grpc.loadPackageDefinition(packageDefinition).mng5grpc;

function main() {
    const main = new mng5grpc.Main(
        "mng5grpc.mtapi.io:443",
        grpc.credentials.createSsl()
    );

    const streams = new mng5grpc.Streams(
        "mng5grpc.mtapi.io:443",
        grpc.credentials.createSsl()
    );

    main.Connect({ user: 1002, password: "pqcbkl7j", server: "13.41.64.21" }, function (err, response) {
        const token = response.result;
        console.log('id:', token);

        main.AccountsList({ id: token }, function (err, response) {
            console.log('AccountsList:', response.result);
        });

        main.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("end:");
        });

    });
}

main();
setTimeout(function () {
    console.log('Done');
}, 10000);

Leave a Reply