├── .gitignore ├── README.md ├── docs ├── MetaTrader.PNG └── Node.PNG ├── mql └── TradingAPI.mq4 ├── npm-debug.log ├── package.json ├── server.js └── src └── ExampleEndpoint.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MetaTrade2NodeJS 2 | Connect your MQL experts with and external API. In this Example based on Express.js 3 | 4 | ## Setup 5 | - execute **"npm install"** inside the project directory 6 | - start the server using **"npm start"** 7 | - copy **TradingAPI.mq4** to your other experts (somewhere under AppData) 8 | - use the **strategietester** or add the expert to a chart and you should see the following 9 | 10 | ![alt text](https://raw.githubusercontent.com/XC3S/MetaTrade2NodeJS/master/docs/Node.PNG) 11 | 12 | ![alt text](https://raw.githubusercontent.com/XC3S/MetaTrade2NodeJS/master/docs/MetaTrader.PNG) 13 | 14 | ## Troubleshoting 15 | 16 | ### Error 4060 17 | Allow your Expert to connect with your URL 18 | _MetaTrader -> Extras -> Optionen -> Experten_ 19 | _1. allow Webrequests_ 20 | _2. add "http://localhost"_ 21 | -------------------------------------------------------------------------------- /docs/MetaTrader.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XC3S/MetaTrade2NodeJS/5a945b7c81ec4b464fbe4fb667bee46f94b0d726/docs/MetaTrader.PNG -------------------------------------------------------------------------------- /docs/Node.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XC3S/MetaTrade2NodeJS/5a945b7c81ec4b464fbe4fb667bee46f94b0d726/docs/Node.PNG -------------------------------------------------------------------------------- /mql/TradingAPI.mq4: -------------------------------------------------------------------------------- 1 | #property copyright "Maximilian Geithe" 2 | #property version "1.00" 3 | #property strict 4 | 5 | int OnInit(){ 6 | string headers; 7 | char post[], result[]; 8 | int res = WebRequest("GET", "http://localhost/init?bid=" + Bid + "&ask=" + Ask, "", NULL, 1000, post, ArraySize(post), result, headers); 9 | if(res != 200){ 10 | Print("Status code: " , res, ", error: ", GetLastError()); 11 | } 12 | else { 13 | Print("Init response: ", CharArrayToString(result)); 14 | } 15 | 16 | return(INIT_SUCCEEDED); 17 | } 18 | 19 | void OnDeinit(const int reason){ 20 | string headers; 21 | char post[], result[]; 22 | int res = WebRequest("GET", "http://localhost/deinit?bid=" + Bid + "&ask=" + Ask, "", NULL, 1000, post, ArraySize(post), result, headers); 23 | if(res != 200){ 24 | Print("Status code: " , res, ", error: ", GetLastError()); 25 | } 26 | else { 27 | Print("DeInit response: ", CharArrayToString(result)); 28 | } 29 | } 30 | 31 | void OnTick(){ 32 | string headers; 33 | char post[], result[]; 34 | int res = WebRequest("GET", "http://localhost/tick?bid=" + Bid + "&ask=" + Ask, "", NULL, 1000, post, ArraySize(post), result, headers); 35 | if(res != 200){ 36 | Print("Status code: " , res, ", error: ", GetLastError()); 37 | } 38 | else { 39 | Print("Tick response: ", CharArrayToString(result)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /npm-debug.log: -------------------------------------------------------------------------------- 1 | 0 info it worked if it ends with ok 2 | 1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe', 3 | 1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', 4 | 1 verbose cli 'start' ] 5 | 2 info using npm@3.10.3 6 | 3 info using node@v6.4.0 7 | 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 8 | 5 info lifecycle tradingapi@1.0.0~prestart: tradingapi@1.0.0 9 | 6 silly lifecycle tradingapi@1.0.0~prestart: no script for prestart, continuing 10 | 7 info lifecycle tradingapi@1.0.0~start: tradingapi@1.0.0 11 | 8 verbose lifecycle tradingapi@1.0.0~start: unsafe-perm in lifecycle true 12 | 9 verbose lifecycle tradingapi@1.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Users\Max\Desktop\Projects\TradingAPI\node_modules\.bin;C:\Program Files\nodejs;C:\Users\Max\bin;C:\Users\Max\AppData\Local\Programs\Git\mingw64\bin;C:\Users\Max\AppData\Local\Programs\Git\usr\local\bin;C:\Users\Max\AppData\Local\Programs\Git\usr\bin;C:\Users\Max\AppData\Local\Programs\Git\usr\bin;C:\Users\Max\AppData\Local\Programs\Git\mingw64\bin;C:\Users\Max\AppData\Local\Programs\Git\usr\bin;C:\Users\Max\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files\Common Files\Autodesk Shared;C:\Program Files (x86)\Autodesk\Backburner;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\Program Files (x86)\Brackets\command;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files (x86)\LLVM\bin;C:\Program Files\nodejs;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Users\Max\AppData\Roaming\npm;C:\Program Files\phantomjs-2.1.1-windows\bin;C:\Users\Max\AppData\Local\Google\Chrome SxS\Application\chrome.exe;C:\Users\Max\AppData\Local\Programs\Git\usr\bin\vendor_perl;C:\Users\Max\AppData\Local\Programs\Git\usr\bin\core_perl 13 | 10 verbose lifecycle tradingapi@1.0.0~start: CWD: C:\Users\Max\Desktop\Projects\TradingAPI 14 | 11 silly lifecycle tradingapi@1.0.0~start: Args: [ '/d /s /c', 'node server.js' ] 15 | 12 silly lifecycle tradingapi@1.0.0~start: Returned: code: 1 signal: null 16 | 13 info lifecycle tradingapi@1.0.0~start: Failed to exec start script 17 | 14 verbose stack Error: tradingapi@1.0.0 start: `node server.js` 18 | 14 verbose stack Exit status 1 19 | 14 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:242:16) 20 | 14 verbose stack at emitTwo (events.js:106:13) 21 | 14 verbose stack at EventEmitter.emit (events.js:191:7) 22 | 14 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14) 23 | 14 verbose stack at emitTwo (events.js:106:13) 24 | 14 verbose stack at ChildProcess.emit (events.js:191:7) 25 | 14 verbose stack at maybeClose (internal/child_process.js:852:16) 26 | 14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5) 27 | 15 verbose pkgid tradingapi@1.0.0 28 | 16 verbose cwd C:\Users\Max\Desktop\Projects\TradingAPI 29 | 17 error Windows_NT 6.1.7601 30 | 18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" 31 | 19 error node v6.4.0 32 | 20 error npm v3.10.3 33 | 21 error code ELIFECYCLE 34 | 22 error tradingapi@1.0.0 start: `node server.js` 35 | 22 error Exit status 1 36 | 23 error Failed at the tradingapi@1.0.0 start script 'node server.js'. 37 | 23 error Make sure you have the latest version of node.js and npm installed. 38 | 23 error If you do, this is most likely a problem with the tradingapi package, 39 | 23 error not with npm itself. 40 | 23 error Tell the author that this fails on your system: 41 | 23 error node server.js 42 | 23 error You can get information on how to open an issue for this project with: 43 | 23 error npm bugs tradingapi 44 | 23 error Or if that isn't available, you can get their info via: 45 | 23 error npm owner ls tradingapi 46 | 23 error There is likely additional logging output above. 47 | 24 verbose exit [ 1, true ] 48 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tradingapi", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Maximilian Geithe", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.15.2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const express = require('express'); 4 | const app = express(); 5 | 6 | const ExampleEndpoint = require("./src/ExampleEndpoint.js"); 7 | let exampleEndpoint = new ExampleEndpoint(); 8 | 9 | app.get('/init', function (req, res) { 10 | const state = exampleEndpoint.onInit(req.query.bid,req.query.ask); 11 | res.send(state); 12 | }) 13 | 14 | app.get('/tick', function (req, res) { 15 | const state = exampleEndpoint.onTick(req.query.bid,req.query.ask); 16 | res.send(state); 17 | }) 18 | 19 | app.get('/deinit', function (req, res) { 20 | const state = exampleEndpoint.onDeInit(req.query.bid,req.query.ask); 21 | res.send(state); 22 | }) 23 | 24 | app.listen(80, function () { 25 | console.log('started Trading API on port 80'); 26 | }) -------------------------------------------------------------------------------- /src/ExampleEndpoint.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const STATE_IDLE = "IDLE"; 4 | const STATE_BUY = "BUY"; 5 | const STATE_SELL = "SELL"; 6 | 7 | module.exports = class ExampleEndpoint{ 8 | onInit(bid,ask){ 9 | console.log("INIT:",{bid: bid,ask: ask}); 10 | 11 | return STATE_BUY; 12 | } 13 | 14 | onTick(bid,ask){ 15 | console.log("TICK:",{bid: bid,ask: ask}); 16 | 17 | return STATE_IDLE; 18 | } 19 | 20 | onDeInit(bid,ask){ 21 | console.log("DEINIT:",{bid: bid,ask: ask}); 22 | 23 | return STATE_SELL; 24 | } 25 | } --------------------------------------------------------------------------------