2017-02-12 39 views
-1

基本上我希望我的本地MetaTrader 5終端在每次歐元/美元對的BID費率變化時都執行POST請求。如何使MetaTrader 5終端腳本在端口443上向我的nodejs服務器發送EURUSD BID費率?

而且我要console.log它在我的服務器的NodeJS:

const express = require('express'); 
const app = express(); 
const http = require('http').Server(app); 
const io = require('socket.io')(http); 
const path = require('path'); 
const mongoose = require('mongoose'); 
const bodyParser = require('body-parser'); 

let env = process.env.NODE_ENV || 'development'; 

const port = 443; 
const connection = 'mongodb://localhost:27017/db'; 

app.use(bodyParser.urlencoded({extended: true})); 
app.use(bodyParser.json()); 
app.use(express.static(path.join(__dirname, 'public'))); 

mongoose.connect(connection) 
    .then((db) => { 
     console.log('MongoDB up and running!'); 

     app.post('/fxrates', (req, res) => { 
      console.log(req); 
     }); 
     // MY ROUTES for the client 
    }) 
    .catch(console.log); 

http.listen(port,() => { 
    console.log(`listening on ${port}`); 
}); 

這裏是一個無錯編譯我的MQ5腳本。 但是當我運行它時,我沒有看到任何記錄在我的nodejs服務器終端中的任何東西。

而且我看到Print("Test:",b);腳本元操盤手裏面打印Experts Tab

我還添加了MetaTrader 5的終端 - >工具 - >選項 - >智能交易

http://localhost:443/fxrates 

http://localhost/fxrates 
http://localhost 

MQ5腳本

//+------------------------------------------------------------------+ 
//|              fxrates.mq5 | 
//|      Copyright 2017, MetaQuotes Software Corp. | 
//|            https://www.mql5.com | 
//+------------------------------------------------------------------+ 
#property copyright "Copyright 2017, MetaQuotes Software Corp." 
#property link  "https://www.mql5.com" 
#property version "1.00" 
//+------------------------------------------------------------------+ 
//| Script program start function         | 
//+------------------------------------------------------------------+ 
void OnStart() 
    { 
     //- string headers; 
     string headers; 

     char data[], result[]; 

     string str = "data=value"; // post data variables to send 

     StringToCharArray(str,data); 

     string b = CharArrayToString(data); 

     Print("Test:",b); // just test if good ... it is. 

     WebRequest("POST","http://localhost:443/fxrates",NULL,NULL,3000,data,ArraySize(data),result,headers); 

} 


//+------------------------------------------------------------------+ 
+0

你有沒有至少**嘗試過我以前的建議+源代碼來記錄/顯示在python控制檯中的http-POST-wrapped事務的內容? >>> http://stackoverflow.com/a/39966404/3666197重新運行它+後輸出,記錄什麼,好嗎?** – user3666197

回答

2

爲什麼你認爲一切都會好起來?
作爲一個程序員,你就可以發現錯誤...試試這個:

int res = WebRequest("POST", ...); 
if (res != 200){ 
    Print("failed to send. result=" 
      + (string) res 
      + ", LastError=" 
      + (string) GetLastError() 
      ); 
    return(False);       //+redefine void F(){} into a bool 
} 

那就讓我們看看會發生什麼錯誤。

未來,您可能希望使用另一種通知(即電子郵件)來擴展該塊,以便在發生某些錯誤時進行了解。

至於 - 請檢查WebRequest()函數,您的超時參數是NULL

您需要WebRequest#2POST-方法。

相關問題