A1:
不,您不需要为此 API 使用代理文件
如果尝试 API 调用,使用已发布的 Quandl 语法:
<pragma>://<URL.ip>/<relative.URL>[?<par.i>=<val.i>[&<par.j>=<val.j>[&...]]]
服务器端将向您推送以下内容:
Date,Value
2013-12-31,4.0
因此,您的代码可能会像这样使用 Quandl API:
void OnStart()
{
string cookie = NULL,
headers;
char post[],
result[];
int res;
/* TODO: *
* Must allow MT4 to access the server URL, *
* you should add URL "https://www.quandl.com/api/v3/datasets/ADB/LAB_UNEMP_JPN.csv" *
* in the list of allowed URLs *
* ( MT4 -> Tools -> Options -> [Tab]: "Expert Advisors" ): */
string aDataSOURCE_URL = "https://www.quandl.com/api/v3/datasets/ADB/LAB_UNEMP_JPN.csv";
string aDataSOURCE_API = "rows = 1&api_key=<My_API_Key>";
//-- Create the body of the POST request for API specifications and API-authorization
ArrayResize( post,
StringToCharArray( aDataSOURCE_API, // string text |--> [in] String to copy.
post, // uchar &array[] <--| [out] Array of uchar type.
0, // int start = 0 |--> [in] Position from which copying starts. Default - 0.
WHOLE_ARRAY, // int count = -1 |--> [in] Number of array elements to copy. Defines length of a resulting string. Default value is -1, which means copying up to the array end, or till terminating '\0'. Terminating zero will also be copied to the recipient array, in this case the size of a dynamic array can be increased if necessary to the size of the string. If the size of the dynamic array exceeds the length of the string, the size of the array will not be reduced.
CP_UTF8 // uint cp = CP_ACP |--> [in] The value of the code page. For the most-used code pages provide appropriate constants.
)
- 1
);
//-- Reset the last error code
ResetLastError();
//-- Loading a html page from Quandl
int timeout = 5000; //-- Timeout below 1000 (1 sec.) is not enough for slow Internet connection
res = WebRequest( "POST", // const string method |--> [in] HTTP method.
aDataSOURCE_URL, // const string URL |--> [in] URL.
cookie, // const string cookie |--> [in] Cookie value.
NULL, // const string referrer |--> [in] Value of the Referer header of the HTTP request.
timeout, // int timeout |--> [in] Timeout in milliseconds.
post, // const char &data |--> [in] Data array of the HTTP message body
ArraySize( post ), // int data_size |--> [in] Size of the data[] array.
result, // char &result <--| [out] An array containing server response data.
headers // string &result_headers <--| [out] Server response headers.
);
//-- Check errors
if ( res == -1 )
{ Print( "WebRequest Error. Error code = ", GetLastError() ); //-- Perhaps the URL is not listed, display a message about the necessity to add the address
MessageBox( "Add the address '" + aDataSOURCE_URL + "' in the list of allowed URLs on tab 'Expert Advisors'", "Error", MB_ICONINFORMATION );
}
else //-- Load was successfull
{
PrintFormat( "The data has been successfully loaded, size = %d bytes.", ArraySize( result ) );
//-- parse the content ---------------------------------------
/*
"Date,Value
2013-12-31,4.0"
*/
//-- consume the content -------------------------------------
//...
}
}
有4个主要项目需要照顾:
0:
MT4
使用给定API设置的权限 - API组件。API长度计算URL
1:
URL
<pragma>://<URL.ip>/<relative.URL>
2:
const char &data[]
[?<par.i>=<val.i>[&<par.j>=<val.j>[&...]]]
3:
int data_size
附录:这更多是一个原因列表,为什么要避免使用New -MQL4.56789
WebRequest()
函数变体:
尽管MQL4
文档承诺简单使用WebRequest()
函数变体,(cit.:) “1.key=value
使用标头发送类型为“”的简单请求Content-Type: application/x-www-form-urlencoded
。”,但现实远非承诺的简单用例:
0:
完成:MT4 管理步骤(弱点:不能强制 MT4{ http | https }
通过默认端口以外的协议进行通信~{ :80 | :443 }
1:
URL
由两个(三个,如果使用:port
说明符,这在(参考 0:右上方)中不起作用)部分组成。MT4
<URL.ip_address>
是第一个,可以用规范的 IPv4 形式 ( 10.38.221.136
) 或 DNS 可翻译的形式 ( MT4_APAC_PRIMARY.broker.com
) 表示。第二部分,<relative.URL>
,指定 HttpServer 本身,定位文件的位置(它是 HttpServer--相对文件位置)。已发布的 WebRequest 允许使用连接在一起的两个部分,参考。aDataSOURCE_URL
.
3:
WebServer API,如果这样构建,可以允许添加一些额外的参数,这些参数可以被指定并呈现给 WebServer。表示取决于是否在{ HTTP GET | HTTP POST }
呼叫方选择了协议选项。
4:
每次调用 MT4WebRequest()
还需要调用者指定内容参数的长度(参考使用)data
ArraySize( post ), // int data_size