MT4 client gRPC NodeJS example
Table of Contents
Do package installation before app running
npm install
This example has a dynamic code generation
You can find satic code generation in the typescript example.
Example:
'use strict';
const PROTO_PATH = __dirname + '/mt4.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 mt4grpc = grpc.loadPackageDefinition(packageDefinition).mt4grpc;
function main() {
const connection = new mt4grpc.Connection(
"mt4grpc.mtapi.io",
grpc.credentials.createSsl()
);
const mt4 = new mt4grpc.MT4(
"mt4grpc.mtapi.io",
grpc.credentials.createSsl()
);
const subscriptions = new mt4grpc.Subscriptions(
"mt4grpc.mtapi.io",
grpc.credentials.createSsl()
);
const streams = new mt4grpc.Streams(
"mt4grpc.mtapi.io",
grpc.credentials.createSsl()
);
connection.Connect({ user: 500476959, password: "ehj4bod", host: "mt4-demo.roboforex.com", port: 443 }, function (err, response) {
const error = err;
const token = response.result;
console.log('id:', token);
mt4.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');
},
2 Responses
I have been surfing online more than 2 hours today, yet I never
found any interesting article like yours.
It’s pretty worth enough for me. Personally, if all website owners and bloggers made good content as you did, the internet will be much more useful than ever before.
Ken, thank you for your response