我如何通过一个 API,如谷歌财经得到货币兑换率?

现在,我确实找到了 谷歌财经 API,并开始查看它,但我发现了很多关于投资组合、交易、头寸和其他我一无所知的东西的信息。

我看错文件了吗?我需要做什么才能从 GF 获得汇率信息?这有可能吗?

剪辑

为了让事情更清楚一点,我对技术性的东西不感兴趣,也不想要任何代码。

685298 次浏览

据我所知,欧洲央行(ECB)也拥有最可靠的免费供应。它包含约28种货币,并至少每天更新。

Http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml

有关更多格式和工具,请参阅欧洲央行参考页: Http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html

谢谢你的回答。

自由货币兑换率:

  • 利率每30分钟更新一次
  • 免费服务器现在需要 API 密钥。

一个示例转换 URL 是: http://free.currencyconverterapi.com/api/v5/convert?q=EUR_USD&compact=y


对于子孙后代来说,这些问题还有其他可能的答案:

  1. 雅虎财经 API 2017-11-06终止

从2017年11月6日起停止使用

我们注意到这项服务正被用于 违反了雅虎的服务条款。因此,该服务是 对于所有未来市场和股票数据的研究, 请参阅 finance.yahoo.com。

请求: http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=USDINR=X
这个 CSV 由一个名为 咖喱的 jQuery 插件使用。由于稳定性问题,Curry 从2017年8月29日起改用 fixer.io。 如果你需要的不仅仅是一辆 CSV 的话可能会有用。

  1. (多亏了 Keyo) 雅虎查询语言允许您以 XML 或 JSON 格式同时获得一系列货币。数据会在第二天更新(而欧洲央行(ECB)的数据是第一天更新的) ,并在周末停止。不需要任何注册。

来自雅虎的 http://query.yahooapis.com/v1/public/yql?q=select。金融。在哪里交换对在哪里交换对(“ USDEUR”,“ USDJPY”,“ USDDBGN”,“ USDCZK”,“ USDDKK”,“ USDGBP”,“ USDHUF”,“ USDLTL”,“ USDLVL”,“ USDPLN”,“ USDRON”)“ USDSEK”,“ USDCHF”,“ USDDNOK”,“ USDHRK”,“ USDRUB”,“ USDTRY”,“ USDDAUD”,“ USDBRL”“ USDCAD”,“ USDCNY”,“ USDHKD”,“ USDIDR”,“ USDILS”,“ USDINR”,“ USDKRW”,“ USDMXN”,“ USDMYR”,“ USDNZD”,“ USDPHP”,“ USDSGD”,“ USDTHB”,“ USDZAR”,“ USDISK”)& env = store:// datatables.org/alltableswithkeys

这是 YQL 查询生成器,您可以在其中测试查询并复制 url: (NO LONGER AVAILABLE)

Http://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22usdmxn%22%2c%20%22usdchf%22%29

yql console no longer available

  1. 开源汇率 API

免费供个人使用 (每月1000次点击)
在免费帐户中不允许更改“基础”(从“美元”)
需要注册。
请求: http://openexchangerates.org/latest.json
回应:

   <!-- language: lang-js -->


{
"disclaimer": "This data is collected from various providers ...",
"license": "all code open-source under GPL v3 ...",
"timestamp": 1323115901,
"base": "USD",
"rates": {
"AED": 3.66999725,
"ALL": 102.09382091,
"ANG": 1.78992886,
// 115 more currency rates here ...
}
}
  1. 货币层空气污染指数

每月250次点击的免费计划
免费帐户不允许更改“来源”(从“美元”)
需要注册。
文档:
Currencylayer.com/documentation < br > < br > JSON 回应:

   <!-- language: lang-js -->


{
[...]
"timestamp": 1436284516,
"source": "USD",
"quotes": {
"USDAUD": 1.345352401,
"USDCAD": 1.27373397,
"USDCHF": 0.947845302,
"USDEUR": 0.91313905,
"USDGBP": 0.647603397,
// 168 world currencies
}
}
  1. 流通怪胎 API

免费计划 (每月1000次点击)
在免费帐户中不允许更改“ Base”(由“ USD”改为“ Base”)
需要注册
数据每60秒更新一次。
全球179种货币,包括货币、金属和加密货币
支持 Shell,Node.JS,Java,Python,PHP,Ruby,JS,C # ,C,Go,Swift。
文档: https://currencyfreaks.com/documentation.html < br > < br > 终点:

$ curl 'https://api.currencyfreaks.com/latest?apikey=YOUR_APIKEY'

JSON 回应:

{
"date": "2020-10-08 12:29:00+00",
"base": "USD",
"rates": {
"FJD": "2.139",
"MXN": "21.36942",
"STD": "21031.906016",
"LVL": "0.656261",
"SCR": "18.106031",
"CDF": "1962.53482",
"BBD": "2.0",
"GTQ": "7.783265",
"CLP": "793.0",
"HNL": "24.625383",
"UGX": "3704.50271",
"ZAR": "16.577611",
"TND": "2.762",
"CUC": "1.000396",
"BSD": "1.0",
"SLL": "9809.999914",
"SDG": 55.325,
"IQD": "1194.293591",
.
.
.
[179 currencies]
}
}
  1. Io API (欧洲央行数据)

每月1000次点击的免费计划
免费帐户不允许更改“来源”(从“美元”) 需要注册

这个 API 端点将于2018年6月1日停止工作。如欲了解更多信息,请浏览: https://github.com/fixerapi/fixer#readme )


网址: http://fixer.io/
示例请求: [ http://api.fixer.io/latest?base=usd ][7]
每天只收集一个值
  1. 欧洲央行提供的饲料

文件: Http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html#dev
请求: http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml < br > < br > XML 响应:

   <!-- language: lang-xml -->


<Cube>
<Cube time="2015-07-07">
<Cube currency="USD" rate="1.0931"/>
<Cube currency="JPY" rate="133.88"/>
<Cube currency="BGN" rate="1.9558"/>
<Cube currency="CZK" rate="27.100"/>
</Cube>
  1. Exchangeratesapi.io

据网站介绍,汇率空气污染指数是欧洲中央银行发布的一项免费服务,提供当前和历史汇率 这个服务与 fixer.io 兼容,并且非常容易使用: 不需要 API 密钥-UPDATE: 现在需要 API 密钥,空闲层为250个请求/周。
例如(它使用 CURL,但是您可以使用您最喜欢的请求工具) :

    > curl https://api.exchangeratesapi.io/latest?base=GBP&symbols=USD&apikey=YOUR_KEY
{"base":"GBP","rates":{"USD":1.264494191},"date":"2019-05-29"}
  1. CurrencyApi.net

每月1250次点击的免费计划
150种加密货币和实物货币-实时更新
基础货币为免费账户上的美元
需要注册。
文档:
Currencyapi.net/documentation < br > < br > JSON 回应:

    {
"valid": true,
"updated": 1567957373,
"base": "USD",
"rates": {
"AED": 3.673042,
"AFN": 77.529504,
"ALL": 109.410403,
// 165 currencies + some cryptos
}
}
  1. 来自 LabStack 的货币

网址: https://labstack.com/currency
文档: < a href = “ https://labstack.com/docs/api/currency/Convert”rel = “ norefrer”> https://labstack.com/docs/api/currency/convert
定价: < a href = “ https://labstack.com/price”rel = “ norefrer”> https://labstack.com/Pricing
请求: < a href = “ https://currency.labstack.com/api/v1/change/1/USD/INR”rel = “ norefrer”> https://currency.labstack.com/api/v1/convert/1/usd/inr
回应: < br >

```js
{
"time": "2019-10-09T21:15:00Z",
"amount": 71.1488
}
```

1 : 来自雅虎的 http://query.yahooapis.com/v1/public/yql?q=select * 。金融。在哪里交换对在哪里交换对(“ USDEUR”,“ USDJPY”,“ USDDBGN”,“ USDCZK”,“ USDDKK”,“ USDGBP”,“ USDHUF”,“ USDLTL”,“ USDLVL”,“ USDPLN”,“ USDRON”)“ USDSEK”,“ USDCHF”,“ USDDNOK”,“ USDHRK”,“ USDRUB”,“ USDTRY”,“ USDDAUD”,“ USDBRL”“ USDCAD”,“ USDCNY”,“ USDHKD”,“ USDIDR”,“ USDILS”,“ USDINR”,“ USDKRW”,“ USDMXN”,“ USDMYR”,“ USDNZD”,“ USDPHP”,“ USDSGD”,“ USDTHB”,“ USDZAR”,“ USDISK”)& env = store:// datatables.org/alltableswithkeys

  1. 货币联盟

  • 快速响应使用 CDN
  • 无利率上限
  • 150多种货币,包括通用加密货币
  • 每日更新

文件: 林克
请求: https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/eur/jpy.json
请求(撤退) : https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/eur/jpy.min.json
回应:

{
"date": "2021-10-03",
"jpy": 128.798673
}

如果你正在为这个问题寻找一个基于红宝石的解决方案,我建议使用谷歌计算器的方法类似于下面的解决方案: http://j.mp/QIC564

require 'faraday'
require 'faraday_middleware'
require 'json'


# Debug:
# require "pry"




country_code_src = "USD"
country_code_dst = "INR"
connection = Faraday.get("http://www.google.com/ig/calculator?hl=en&q=1#{country_code_src}=?#{country_code_dst}")


currency_comparison_hash = eval connection.body #Google's output is not JSON, it's a hash


dst_currency_value, *dst_currency_text = *currency_comparison_hash[:rhs].split(' ')
dst_currency_value = dst_currency_value.to_f
dst_currency_text = dst_currency_text.join(' ')


puts "#{country_code_dst} -> #{dst_currency_value} (#{dst_currency_text} to 1 #{country_code_src})"

下面是一个简单的 PHP 脚本,它得到 GBP 和美元之间的兑换率

<?php
$amount = urlencode("1");
$from_GBP0 = urlencode("GBP");
$to_usd= urlencode("USD");
$Dallor = "hl=en&q=$amount$from_GBP0%3D%3F$to_usd";
$US_Rate = file_get_contents("http://google.com/ig/calculator?".$Dallor);
$US_data = explode('"', $US_Rate);
$US_data = explode(' ', $US_data['3']);
$var_USD = $US_data['0'];
echo $to_usd;
echo $var_USD;
echo '<br/>';
?>

谷歌汇率不准谷歌自己说谷歌不能保证计算器使用的汇率的准确性。在进行任何可能受汇率变动影响的交易之前,您应该确认现行汇率。花旗银行提供的外币兑换率会在牌照下显示。费率只供参考之用,如有更改,恕不另行通知。实际交易的利率可能会有所不同,花旗银行不会提出以任何显示的利率进行任何交易。

对于所有新手寻找一些关于货币转换的提示,看看这个链接

对我自己的 C # 项目帮助很大。为了防止网站消失,我将在下面添加代码。只需将下面的步骤添加到您自己的项目中。不好意思,格式有点问题。

const string fromCurrency = "USD";
const string toCurrency = "EUR";
const double amount = 49.95;
// For other currency symbols see http://finance.yahoo.com/currency-converter/
// Clear the output editor //optional use, AFAIK
Output.Clear();


// Construct URL to query the Yahoo! Finance API
const string urlPattern = "http://finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=l1";
string url = String.Format(urlPattern, fromCurrency, toCurrency);


// Get response as string
string response = new WebClient().DownloadString(url);


// Convert string to number
double exchangeRate =
double.Parse(response, System.Globalization.CultureInfo.InvariantCulture);


// Output the result
Output.Text = String.Format("{0} {1} = {2} {3}",
amount, fromCurrency,
amount * exchangeRate, toCurrency);

下面是一些用 PHP 实现的交换 API 示例。

[ 公开汇率 API]

每月免费提供1000个请求。您必须注册并获取应用程序 ID。免费账户的基础货币美元。检查 支持货币文件

// open exchange URL // valid app_id * REQUIRED *
$exchange_url = 'https://openexchangerates.org/api/latest.json';
$params = array(
'app_id' => 'YOUR_APP_ID'
);


// make cURL request // parse JSON
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $exchange_url . '?' . http_build_query($params),
CURLOPT_RETURNTRANSFER => true
));
$response = json_decode(curl_exec($curl));
curl_close($curl);


if (!empty($response->rates)) {
// convert 150 USD to JPY ( Japanese Yen )
echo $response->rates->JPY * 150;
}

150美元 = 18039.09015日元

[ 货币层 API]

每月免费提供1000个请求。您必须注册并获取访问密钥。自定义基础货币是免费帐户支持的 没有。检查 文件

$exchange_url = 'http://apilayer.net/api/live';
$params = array(
'access_key' => 'YOUR_ACCESS_KEY',
'source' => 'USD',
'currencies' => 'JPY',
'format' => 1 // 1 = JSON
);


// make cURL request // parse JSON
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $exchange_url . '?' . http_build_query($params),
CURLOPT_RETURNTRANSFER => true
));
$response = json_decode(curl_exec($curl));
curl_close($curl);


if (!empty($response->quotes)) {
// convert 150 USD to JPY ( Japanese Yen )
echo '150 USD = ' . $response->quotes->USDJPY * 150 . ' JPY';
}

150美元 = 18036.75045日元

你可以试试 地球插件

除了 IP 完成的地理定位(但 IP 是提供者 IP,所以不那么准确) ,它们还返回货币并且有一个货币转换器: 参见示例。

他们更新了111种货币。

如果需要一个免费且简单的 API 来将一种货币转换为另一种货币,请尝试 Free.currencyconverterapi.com

免责声明,我是该网站的作者,我使用它为我的其他网站之一。

这项服务是免费的,甚至用于商业应用,但没有提供担保。由于性能原因,这些值只是每小时更新一次。

一个示例转换 URL 是: http://free.currencyconverterapi.com/api/v6/convert?q=EUR_PHP&compact=ultra&apiKey=sample-api-key,它将返回一个 json 格式的值,例如{“ EUR _ PHP”: 60.849184}