bukku-accounting/open-exchange-rates-php

Open Exchange Rates PHP SDK

dev-master 2023-01-18 08:43 UTC

This package is auto-updated.

Last update: 2024-09-18 12:40:29 UTC


README

关于Open Exchange Rates API

Open Exchange Rates提供了一个简单、轻量级且可移植的JSON API,提供了200多种全球和数字货币的实时和历史汇率。通过简单的API进行集成,以JSON格式提供服务。数据通过多个可靠来源的算法跟踪和混合,确保公平和无偏的一致性。

通过Open Exchange Rates API发布的汇率是从多个可靠的提供商收集的,混合在一起并以JSON格式提供给所有人使用。没有复杂的查询、复杂的认证方法或长期合同。

特性

  • 最新的汇率
  • 从1999年1月1日起的历史汇率
  • 特定时间段的时序汇率
  • 货币转换
  • 历史开盘、最高、最低和收盘价

网站: https://openexchangerates.org/

安装

使用Composer

composer require bukku-accounting/open-exchange-rates-php

入门

将其作为类使用

use BukkuAccounting\OpenExchangeRates\OerClient;
$oerClient = new OerClient('YOUR_APP_ID');

可用函数

示例:通过"latest"端点请求最新汇率

$res = $oerClient
    ->base('SGD')
    ->symbols('USD,EUR,GBP')
    ->latest();

示例:通过"historical"端点请求历史汇率

$res = $oerClient
    ->date('2022-01-01')
    ->base('SGD')
    ->symbols('USD,EUR,GBP')
    ->historical();

示例:通过"currencies"端点请求可用货币符号列表

$res = $oerClient
    ->currencies();

示例:通过"time_series"端点请求特定时间段的时序汇率

$res = $oerClient
    ->start('2000-01-01')
    ->end('2000-12-31')
    ->base('SGD')
    ->symbols('USD,EUR,GBP')
    ->time_series();

示例:通过"convert"端点将任意价值从一种货币转换为另一种货币

$res = $oerClient
    ->value(10000)
    ->from('SGD')
    ->to('MYR')
    ->convert();

示例:通过"ohlc"端点请求特定时间段的开放式、最高价、最低价和收盘价

$res = $oerClient
    ->start_time('2017-07-17T00:00:00Z')
    ->period('1w')
    ->base('SGD')
    ->symbols('USD,EUR,GBP')
    ->ohlc();

示例:通过"usage"端点请求计划信息和使用统计

$res = $oerClient
    ->usage();

参考API文档

访问https://docs.openexchangerates.org/reference/api-introduction获取每个函数的详细信息