我正在尝试从数据源网站Quandl
获取一个值,以便在MetaTrader4
脚本中使用。数据源网站提供了通过API formats
导出数据的方法,包括.csv
、.json
或.xml
。我选择了.csv
。然后数据源网站提供一个API call
供我使用,格式如下:
https://www.quandl.com/api/v3/datasets/ADB/LAB_UNEMP_JPN.csv?rows=1&api_key=my_api_key
通过使用上面API call
中的rows=1
参数,我可以选择只导出一个值(即latest value
)。
问题1:我可以直接从Quandl获取值吗?还是必须将数据集保存为.csv文件?
因为Quandl
提供了API call
(如上所示),假设我可以从他们的网站上获取value
,而不必将数据集作为.csv
文件保存到我的计算机上,我更喜欢从Quandl
直接**获取value
,而不保存任何文件。
问题2:如何获取要在MT4脚本中使用的值?
我尝试过使用FileOpen()
访问站点上的数据,但没有成功**,然后尝试print
它,以便我可以比较value
与其他。是FileOpen()
只为.csv
文件只保存到我的计算机?我'我希望能够在我的脚本中print
value
一旦检索,以便我可以使用它。以下是我目前所拥有的:
int start() {
while (!IsStopped()) {
Sleep(2000);
int handle;
int value;
handle=FileOpen("https://www.quandl.com/api/v3/datasets/ADB/LAB_UNEMP_JPN.csv?rows=1&api_key=my_api_key", FILE_CSV, ';');
if(handle>0)
{
value=FileReadNumber(handle);
Print(handle);
FileClose(handle);
}
}
如果有人能帮助我获取这个值并将其打印在我的脚本中,这将是一个巨大的帮助。
1条答案
按热度按时间eit6fx6z1#
A1:
否,您不需要为此API使用代理文件如果使用已发布的Quandl语法尝试API调用:
<pragma>://<URL.ip>/<relative.URL>[?<par.i>=<val.i>[&<par.j>=<val.j>[&...]]]
服务器端将向您推送以下内容:
因此,您的代码可以使用Quandl API,如下所示:
有4个主要项目需要注意:
**
0:
使用给定URL
**的MT4权限**
1:
**一个APIURL
设置-<pragma>://<URL.ip>/<relative.URL>
一个API**组件
**
3:
一个APIint data_size
**长度计算附录:这是避免使用*新 *-
MQL4.56789
WebRequest()
函数变体的更多原因列表:尽管MQL 4文档承诺了
WebRequest()
函数变体的简单使用,(cit.:)“1.使用头部Content-Type: application/x-www-form-urlencoded
发送类型“key=value
“的简单请求。",但实际情况远非承诺的简单用例:**
0:
**完成日期:MT4管理步骤(**弱点:无法强制MT4通过默认端口~{ :80 | :443 }
以外的其他端口与{ http | https }
协议通信1:
URL
由两个(三个,如果使用:port
说明符,在MT4中不起作用(引用0:))部分。<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
的使用)