通过 MATLAB 中的 Web 服务进行货币汇率

发布于 2024-11-04 11:24:28 字数 205 浏览 5 评论 0原文

如何在matlab中获取两种给定货币的当前汇率?

我尝试了这个,但是似乎网络服务不再可用的。

是否有另一种简单的方法可以通过 Matlab 中的网络服务获取最新的货币汇率?

How can I obtain the current exchange rate for two given currencies in matlab?

I tried this one, however it seems that the web service is no longer available.

Is there another easy way of obtaining the up-to-date currency exchange rates through a web service in matlab?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心凉 2024-11-11 11:24:28

使用 CREATECLASSFROMWSDL 从货币转换 Web 服务构建本地类。然后,您可以使用 Web 服务的操作来使用类方法进行转换。 http://www.webservicex.net/ 提供了一种货币换算 Web 服务(有多种)货币转换器.asmx?WSDL。下面是它的使用示例:

>> converter = createClassFromWsdl('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');
Retrieving document at 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL'
>> converter = CurrencyConvertor
    endpoint: 'http://www.webservicex.net/CurrencyConvertor.asmx'
        wsdl: 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL'

>> ConversionRate(converter, 'CAD', 'EUR')

ans =

0.7059

>> ConversionRate(converter, 'USD', 'CAD')

ans =

0.953

请注意,ConversionRate 返回一个 char 数组,即如果您想使用汇率进行计算,您仍然需要使用 str2double 转换结果。

货币缩写列表位于 http://www.webservicex.net/ ws/wsdetails.aspx?wsid=10

Build a local class from a currency conversion web service using CREATECLASSFROMWSDL. You can then use the web service's operations to do the conversion using the class methods. One currency conversion web service (there are many) is available at http://www.webservicex.net/CurrencyConvertor.asmx?WSDL. Here's an example of its use:

>> converter = createClassFromWsdl('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');
Retrieving document at 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL'
>> converter = CurrencyConvertor
    endpoint: 'http://www.webservicex.net/CurrencyConvertor.asmx'
        wsdl: 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL'

>> ConversionRate(converter, 'CAD', 'EUR')

ans =

0.7059

>> ConversionRate(converter, 'USD', 'CAD')

ans =

0.953

Note that ConversionRate returns a char array, i.e. you still have to convert the result with str2double if you want to do calculations with the exchange rate.

A list of the currency abbreviations is available at http://www.webservicex.net/ws/wsdetails.aspx?wsid=10.

不必在意 2024-11-11 11:24:28

这是一个老问题,但我想我会更新答案。我在 MATLAB (exchangerate.m) 中制作了这个货币转换器函数,该函数利用openexchangerates.org API,它得到了更好的支持,并且还包含历史数据。以下是其工作原理的描述(非常简单):

该函数返回从 openexchangerates.org 获得的汇率
使用他们的 API。为了正确工作,必须连接到
互联网。默认的app_id是从免费帐户到
openexchangerates.org,每月有 1000 个 API 请求的限制。为了
更灵活,注册您自己的免费或付费帐户并替换
app_id 值与您自己的 id 号。

输入:

1) base:表示基础货币的字符串,设置为具有
值为 1。如果提供空字符串 '',则默认 'USD' 为
用过的。请参阅下面的有效货币缩写列表。

2) 当前:a
表示货币缩写的字符串或字符串元胞数组
与基础货币比较。如果提供“all”或“”作为输入,
然后返回所有可用货币。查看有效列表
下面的货币缩写。

3) 日期:可选字符串,包含
汇率所需的日期(历史数据可能不
始终可用)。输入的格式应为“YYYY-MM-DD”。
要获取最新的汇率数据,请使用日期
= 'latest' 或 '',这是默认值。 1999年及以后的历史数据

输出:

1) 汇率:表示所需货币 curr 与基础货币 base 之间的汇率的数字或向量。

2) 货币:对应货币的元胞数组
费率中的缩写。

3) rate_struct:带有字段名称的结构
等于货币缩写和相关值
费率。该输出仅结合了汇率和货币
方便。

示例:

1) 获取比特币和美元之间的最新汇率(注:m 文件中列出了所有国家缩写)

[rates,currencies,rates_struct] = exchangerate('USD','BTC'); 
>> rates = 1.614e-3 
>> currencies = 'BTC' 
>> rates_struct = 
       BTC: 1.614e-3

2) 获取所有可用货币的最新汇率

[rates,currencies,rates_struct] = exchangerate();

3) 获取兑换使用美国的比特币、印度卢比和欧元汇率
2013年6月5日美元为基础货币

[rates,currencies,rates_struct] = exchangerate('USD',{'BTC','INR','EUR'},'2013-06-05'); 
>> rates = [8.246e-3; 5.672e1; 7.642e-1] 
>> currencies = {'BTC';'INR';'EUR'} 
>> rates_struct = 
      BTC: 8.246e-3 
      INR: 5.672e1 
      EUR: 7.642e-1

This is an old question, but thought I would update the answer. I made this currency converter function in MATLAB (exchangerate.m) that utilizes the openexchangerates.org API, which is better supported and also includes historical data. Here's a description how it works (it's very simple):

This function returns exchange rates obtained from openexchangerates.org
using their API. To work correctly, one must be connected to the
Internet. The default app_id is from a free account to
openexchangerates.org, which has a limit of 1000 API requests/month. For
more flexibility, sign up for your own free or paid account and replace
the app_id value with your own id number.

Inputs:

1) base: a string denoting the base currency, which is set to have a
value of 1. If an empty string '' is provided, the default 'USD' is
used. See list of valid currency abbreviations below.

2) curr: a
string or cell array of strings denoting the currency abbreviation to
compare with the base currency. If 'all' or '' is provided as input,
then all available currencies are returned. See list of valid
currency abbreviations below.

3) date: an optional string containing
the date desired for the exchange rate (historical data may not
always be available). The input should be in the form 'YYYY-MM-DD'.
To get the latest exchange rate data, use date
= 'latest' or '', which is the default value. Historical data from 1999 and onward

Outputs:

1) rates: a number or vector indicating the exchange rate(s) between the desired currency (currencies), curr, and the base currency, base.

2) currencies: a cell array of the corresponding currency
abbreviations in rates.

3) rate_struct: a structure with field names
equal to the currency abbreviations and associated values being the
rates. This output just combines rates and currencies for
convenience.

Examples:

1) Get the latest exchange rate between Bitcoin and the US Dollar (Note: All country abbreviations are listed in the m-file)

[rates,currencies,rates_struct] = exchangerate('USD','BTC'); 
>> rates = 1.614e-3 
>> currencies = 'BTC' 
>> rates_struct = 
       BTC: 1.614e-3

2) Get latest exchange rates for all available currencies

[rates,currencies,rates_struct] = exchangerate();

3) Obtain exchange rates for Bitcoin, Indian rupee, and Euro using the US
Dollar as base currency on June 5, 2013

[rates,currencies,rates_struct] = exchangerate('USD',{'BTC','INR','EUR'},'2013-06-05'); 
>> rates = [8.246e-3; 5.672e1; 7.642e-1] 
>> currencies = {'BTC';'INR';'EUR'} 
>> rates_struct = 
      BTC: 8.246e-3 
      INR: 5.672e1 
      EUR: 7.642e-1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文