博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
实时获取汇率_Currencylayer实时汇率
阅读量:2507 次
发布时间:2019-05-11

本文共 5990 字,大约阅读时间需要 19 分钟。

实时获取汇率

Ever wanted an accurate and reliable currency data that can be easily integrated into your business; be it CRM, ERP, accounting applications etc., built in any programming languages? Then say hello to currencylayer.

曾经想过可以将其轻松集成到您的业务中的准确可靠的货币数据; 以任何编程语言构建的CRM,ERP,会计应用程序等? 然后向currencylayer打个招呼。

In this article, I will show you how to use two of currencylayer’s services: live exchange rates and historical exchange rates.

在本文中,我将向您展示如何使用currencylayer的两项服务:实时汇率和历史汇率。

( )

provides a reliable exchange rates and currency conversion for your business. It does these by providing an easy to integrate REST API with real-time and historical exchange rates for 168 world currencies and precious metals, delivered in universally usable and easily parseable JSON format, and compatible with any application.

为您的业务提供可靠的汇率和货币换算。 它通过提供一种易于集成的REST API和168种世界货币和贵金属的实时和历史汇率来实现这些目标,它们以通用且易于解析的JSON格式提供,并且与任何应用程序兼容。

The universal real-time exchange rate data solution

通用实时汇率数据解决方案

In addition to providing update to date real-time exchange rates, currencylayer also provides historical exchange rates for all of their supported 168 world currencies. They provide historical exchange rates for way back as the past 16 years.

除了提供最新的实时汇率之外,currencylayer还提供其支持的所有168种世界货币的历史汇率。 他们提供了过去16年的历史汇率。

So what makes currencylayer perfect for your business? Well, here are some reasons:

那么,什么使currencylayer适合您的业务呢? 好吧,这是一些原因:

  • Reliable forex rates

    可靠的外汇汇率
  • Easy-to-integrate API

    易于集成的API
  • 256-bit HTTPS

    256位HTTPS
  • Advanced data coverage

    先进的数据覆盖
  • Real-time updates

    实时更新
  • Extended usage statistics

    扩展使用情况统计
  • Easy on your budget

    轻松节省预算
  • Interactive documentation

    互动文件

Did I mention that you can use most of these services completely for free? Sure you can! currencylayer has a free plan. With the free plan, you can make update to 1,000 API requests and the data are updated every hour.

我是否提到您可以完全免费使用其中大多数服务? 你当然可以! currencylayer有免费计划。 使用免费计划,您可以更新到1,000个API请求,并且每小时更新一次数据。

( )

To start using the services provided by currencylayer, you need to first create an account with them. So head over to the and signup for a free plan.

要开始使用currencylayer提供的服务,您需要首先使用它们创建一个帐户。 因此,请转到并注册免费计划。

Once you have signed up, you will be presented with a 3-step quickstart guide. Step 1 contains your Access Key, which you will use to interact with ****the currencylayer API. In step 2, you are presented with the base URL of the currencylayer API:

注册后,将为您提供3个步骤的快速入门指南。 第1步包含您的访问密钥 ,您将使用该访问密钥与currencylayer API进行交互。 在第2步中,向您显示currencylayer API的基本URL:

http://apilayer.net/api/

Take note of your access key and the base URL as we’ll be using them in the next section.

记下您的访问密钥和基本URL,因为我们将在下一部分中使用它们。

( )

To get live exchange rates, we need to make request to the live endpoint of the currencylayer API. That is:

要获取实时汇率,我们需要向currencylayer API的live端点发出请求。 那是:

http://apilayer.net/api/live

We need to pass our access key to the above URL.

我们需要将访问密钥传递到上述URL。

The sample code in this article will be in Node.js and using Axios as the HTTP client:

本文中的示例代码将位于Node.js中,并将Axios用作HTTP客户端:

const axios = require('axios')const ACCESS_KEY = 'YOUR_ACCESS_KEY'axios.get(`http://apilayer.net/api/live?access_key=${
ACCESS_KEY}&currencies=USD,EUR,GBP,AUD,NGN`).then(response => {
console.log(response.data)})

Here, we specify we want to get the exchange rates for five currencies: USD, EUR, GBP, AUD, and NGN. By default, USD will be used as the source. That is, the currency to which all exchange rates are relative. We can as well specify as different source:

在这里,我们指定要获取五种货币的汇率: USDEURGBPAUDNGN 。 默认情况下, USD将用作来源 。 也就是说,所有汇率都是相对的货币。 我们也可以指定不同的来源:

http://apilayer.net/api/live?access_key=YOUR_ACCESS_KEY&source=GBP

Below is the response gotten from the above request:

以下是从上述请求获得的响应:

{
"success": true, "terms": 'https://currencylayer.com/terms', "privacy": 'https://currencylayer.com/privacy', "timestamp": 1526743687, "source": 'USD', "quotes": {
"USDUSD": 1, "USDEUR": 0.849404, "USDGBP": 0.74245, "USDAUD": 1.331041, "USDNGN": 358.000344 }}

The response is pretty straightforward. The exchange rates are inside the quotes object.

响应非常简单。 汇率在quotes对象内。

( )

We have seen how to get live exchange rates. Now, let’s see how to fetch exchange rates from the past. For this, we make request to the historical of the currencylayer API, passing in our access key and a date in the past:

我们已经看到了如何获取实时汇率。 现在,让我们看看如何获​​取过去的汇率。 为此,我们向currencylayer API的historical记录发出请求,并传递访问密钥和过去的日期:

const axios = require('axios')const ACCESS_KEY = 'YOUR_ACCESS_KEY'axios.get(`http://apilayer.net/api/historical?access_key=${
ACCESS_KEY}&date=2010-05-19&currencies=USD,EUR,GBP,AUD,NGN`).then(response => {
console.log(response.data)})

Here, we specify we want to get the exchange rates for a particular date (2010-05-19) in the past.

在此,我们指定要获取过去特定日期(2010-05-19)的汇率。

Below is the response gotten:

以下是得到的响应:

{
"success": true, "terms": "https://currencylayer.com/terms", "privacy": "https://currencylayer.com/privacy", "historical": true, "date": "2010-05-19", "timestamp": 1274313599, "source": "USD", "quotes": {
"USDUSD": 1, "USDEUR": 0.809694, "USDGBP": 0.69632, "USDAUD": 1.184999, "USDNGN": 152.073107 }}

In addition to the standard result sets, an historical API response contains an historical key with a value of true and the specified date.

除标准结果集外,历史API响应还包含一个具有true值和指定datehistorical键。

( )

In this article, we have seen what currencylayer is, the service it provides and some reasons to use it in your business. Though, we only looked at two of the services currencylayer provides. In addition to live and historical exchange rates, currencylayer can also handle currency conversion and lot more.

在本文中,我们了解了什么是currencylayer,它提供的服务以及在您的业务中使用它的一些原因。 不过,我们只研究了currencylayer提供的两项服务。 除了实时汇率和历史汇率外,currencylayer还可以处理货币换算等。

For more information about currencylayer, do check out their and their easy to understand .

有关currencylayer的更多信息,请查看其和易于理解的 。

翻译自:

实时获取汇率

转载地址:http://esuwd.baihongyu.com/

你可能感兴趣的文章
python自然语言处理学习笔记1
查看>>
java插入排序
查看>>
Django doc summary (4)
查看>>
Object-C——内存管理
查看>>
解决for循环里面产生相同随机数的问题
查看>>
Java常量池详解之一道比较蛋疼的面试题
查看>>
HDU1021
查看>>
剑指Offer——替换空格
查看>>
剑指Offer——数据流中的中位数
查看>>
python模拟用户登录爬取阳光采购平台数据
查看>>
linux 发现交换文件 ".swp"
查看>>
描述Cookie和Session的作用,区别和各自的应用范围,Session工作原理
查看>>
ACM学习历程——POJ3295 Tautology(搜索,二叉树)
查看>>
51nod 1295 XOR key-区间异或最大值-可持久化01Trie树(模板)
查看>>
Object-C-自定义类型归档
查看>>
mysql主从不同步问题 Error_code: 1032
查看>>
josephus(约瑟夫)问题
查看>>
类型“Observable<Response>”上不存在属性“map”
查看>>
bzoj 3874: [Ahoi2014]宅男计划
查看>>
css笔记16:盒子模型的入门案例
查看>>