雅虎的
如果只是要单纯的汇率转换,对实时性要求不高的话,可以参考
汇率查询api - 数据接口或者说你要的是四大行的外汇牌价,可参考
人民币外汇牌价qyvlik/fiat-exchange-rates ,做了一些封装,支持使用 docker 启动,docker 镜像是 qyvlik/fiat-exchange-rates,需要自己配置 api key。
florianv/swap 有个 php 的法币汇率集成库。可以看看。
Free, Reliable Currency Converter API,免费账户,一天更新一次,一个月免费1000次(PS 到 2019年7月1号,降低为 250 次),免费账户不支持https
Forex API: Realtime Forex Quotes(2019年7月1日起,关闭免费计划。)
Foreign exchange rates and currency conversion JSON API (需要注册,有免费套餐,支持 https,Pricing Plans - Fixer)
雅虎的汇率接口貌似下线了,或者是哪位大佬在评论给个链接。
Open Exchange Rates(免费账户点击这里注册,每月1000次免费调用;收费用户最高可小时更新)
The Reliable Currency Conversion API 每月1000次免费调用,每小时更新
https://ratesapi.io/documentation/
一般来说,法币汇率比较稳定,可以一天获取一次数据,如果你的应用需要依赖高实时性的,那就花些钱,或者是去外汇交易所拉去实时数据。
How do I get currency exchange rates via an API such as Google Finance?
2021-11-08 更新
华尔街日报可以查询一些法币汇率,链接如下,可以自己替换成想要的法币:https://www.wsj.com/market-data/quotes/fx/USDKRW/advanced-chart,点击这个github 链接,可以看看别人是怎么封装华尔街日报的法币汇率查询。
xe.com 可以点击这个链接查询法币汇率,不过 xe.com 返回的数据做了非线性的数值偏移,时间点上也不一定是连续的。去购买 xe.com 的付费服务吧。
用PowerShell写了个脚本放在Profile里,平时用着方便。
function ConvertTo-MyCurrency {
param(
# Default: 1
[Parameter(Mandatory=$false)]
[ValidateScript({$_ -gt 0})]
$Amount = 1,
# Default: USD
[Parameter(Mandatory=$false)]
[ValidateSet("CNY","AED","AFN","ALL","AMD","ANG","AOA","ARS","AUD","AWG","AZN","BAM","BBD","BDT","BGN","BHD","BIF","BMD","BND","BOB","BRL","BSD","BTC","BTN","BWP","BYN","BYR","BZD","CAD","CDF","CHF","CLF","CLP","CNH","COP","CRC","CUP","CVE","CZK","DEM","DJF","DKK","DOP","DZD","EGP","ERN","ETB","EUR","FIM","FJD","FKP","FRF","GBP","GEL","GHS","GIP","GMD","GNF","GTQ","GYD","HKD","HNL","HRK","HTG","HUF","IDR","IEP","ILS","INR","IQD","IRR","ISK","ITL","JMD","JOD","JPY","KES","KGS","KHR","KMF","KPW","KRW","KWD","KYD","KZT","LAK","LBP","LKR","LRD","LSL","LTL","LVL","LYD","MAD","MDL","MGA","MKD","MMK","MNT","MOP","MRO","MUR","MVR","MWK","MXN","MYR","MZN","NAD","NGN","NIO","NOK","NPR","NZD","OMR","PAB","PEN","PGK","PHP","PKG","PKR","PLN","PYG","QAR","RON","RSD","RUB","RWF","SAR","SBD","SCR","SDG","SEK","SGD","SHP","SKK","SLL","SOS","SRD","STD","SVC","SYP","SZL","THB","TJS","TMT","TND","TOP","TRY","TTD","TWD","TZS","UAH","UGX","USD","UYU","UZS","VEF","VND","VUV","WST","XAF","XCD","XDR","XOF","XPF","YER","ZAR","ZMK","ZMW","ZWL")]
[string]$From="USD",
# Default: CNY
[Parameter(Mandatory=$false)]
[ValidateSet("CNY","AED","AFN","ALL","AMD","ANG","AOA","ARS","AUD","AWG","AZN","BAM","BBD","BDT","BGN","BHD","BIF","BMD","BND","BOB","BRL","BSD","BTC","BTN","BWP","BYN","BYR","BZD","CAD","CDF","CHF","CLF","CLP","CNH","COP","CRC","CUP","CVE","CZK","DEM","DJF","DKK","DOP","DZD","EGP","ERN","ETB","EUR","FIM","FJD","FKP","FRF","GBP","GEL","GHS","GIP","GMD","GNF","GTQ","GYD","HKD","HNL","HRK","HTG","HUF","IDR","IEP","ILS","INR","IQD","IRR","ISK","ITL","JMD","JOD","JPY","KES","KGS","KHR","KMF","KPW","KRW","KWD","KYD","KZT","LAK","LBP","LKR","LRD","LSL","LTL","LVL","LYD","MAD","MDL","MGA","MKD","MMK","MNT","MOP","MRO","MUR","MVR","MWK","MXN","MYR","MZN","NAD","NGN","NIO","NOK","NPR","NZD","OMR","PAB","PEN","PGK","PHP","PKG","PKR","PLN","PYG","QAR","RON","RSD","RUB","RWF","SAR","SBD","SCR","SDG","SEK","SGD","SHP","SKK","SLL","SOS","SRD","STD","SVC","SYP","SZL","THB","TJS","TMT","TND","TOP","TRY","TTD","TWD","TZS","UAH","UGX","USD","UYU","UZS","VEF","VND","VUV","WST","XAF","XCD","XDR","XOF","XPF","YER","ZAR","ZMK","ZMW","ZWL")]
[string]$To="CNY"
)
if ($From -eq $To) {
Write-Warning -Message "Idiot! You can't convert $From to $To by yourself?!"
break
}
$url = "https://finance.google.cn/finance/converter?a=$Amount&from=$From&to=$To"
$result = (Invoke-WebRequest -Uri $url).content -replace "(.*\
)*.*bld>|\\s$To.*(.*\
)*"
Write-Host "`t$Amount $From=$result $To"
}
这次尝试用了外国网站: https://www.exchangerate-api.com/
下列为API的Url,CNY的部分为货币代码,如:USD、EUR ,etc.
https:// api.exchangerate-api.com/v4/latest/CNY// 以下为回传的JSON
{
"base": "CNY",
"date": "2020-02-15",
"time_last_updated": 1581725174,
"rates": {
"CNY": 1,
"AED": 0.525723,
"ARS": 8.790734,
"AUD": 0.213046,
"BGN": 0.258199,
"BRL": 0.619876,
"BSD": 0.143173,
"CAD": 0.189726,
"CHF": 0.140383,
"CLP": 113.781956,
"COP": 474.333333,
"CZK": 3.280837,
"DKK": 0.986649,
"DOP": 7.660834,
"EGP": 2.236103,
"EUR": 0.132045,
"FJD": 0.314397,
"GBP": 0.109808,
"GTQ": 1.093564,
"HKD": 1.112071,
"HRK": 0.983405,
"HUF": 44.423993,
"IDR": 1948.539913,
"ILS": 0.490721,
"INR": 10.223288,
"ISK": 18.159971,
"JPY": 15.724386,
"KRW": 169.51805,
"KZT": 53.952607,
"MXN": 2.661942,
"MYR": 0.592797,
"NOK": 1.325096,
"NZD": 0.222418,
"PAB": 0.143173,
"PEN": 0.484272,
"PHP": 7.232829,
"PKR": 22.104854,
"PLN": 0.560941,
"PYG": 948.666667,
"RON": 0.629401,
"RUB": 9.097323,
"SAR": 0.537152,
"SEK": 1.38726,
"SGD": 0.199096,
"THB": 4.462466,
"TRY": 0.866671,
"TWD": 4.297319,
"UAH": 3.484763,
"USD": 0.143181,
"UYU": 5.423535,
"ZAR": 2.12973
}
}
并可以到下方网址去查阅支援的货币种类:
https://www.exchangerate-api.com/docs/supported-currencies用ajax做简单的测试功能,如下:
$.ajax({
url: 'https://api.exchangerate-api.com/v4/latest/CNY',
type: 'GET',
success: function (result) {
console.log(result);
}
});