houseofapis/currencyapi
Composer 安装命令:
composer require houseofapis/currencyapi
包简介
Composer package for the CurrencyApi.net JSON & XML live currency feed
README 文档
README
CurrencyApi.net provides live currency rates via a REST API. A live currency feed for over 166 currencies, including physical (USD, GBP, EUR + more) and cryptos (Bitcoin, Litecoin, Ethereum + more). A JSON and XML currency api updated every 60 seconds.
Features:
- Live exchange rates (updated every 60 seconds).
- 166+ world currencies.
- Popular cryptocurrencies included; Bitcoin, Litecoin etc.
- Convert currencies on the fly with the convert endpoint.
- Historical currency rates back to year 2000.
- OHLC (candlestick) data for technical analysis.
- Easy to follow documentation
Signup for a free or paid account here.
Note: API v1 is deprecated and will be retired on 31st July 2026, at which point all v1 traffic will be redirected to v2. This SDK (v3.0.0+) targets API v2. If you are on an older version of this SDK, please upgrade.
This package is a:
PHP wrapper for CurrencyApi.net endpoints.
Developer Guide
For an easy to following developer guide, check out our PHP Developer Guide.
Alternatively keep reading below.
Prerequisites
- Minimum PHP 8.1+
- Working on PHP 8.5
- Free or Paid account with CurrencyApi.net
- Composer or clone this repo
Test Coverage
- 100% coverage
Installation
Using composer:
composer require houseofapis/currencyapi
then include the package with:
use HouseOfApis\CurrencyApi\CurrencyApi;
Without composer:
require_once('/path/to/currencyapi/src/CurrencyApi.php'); $currencyApi = new \CurrencyApi\CurrencyApi('API_KEY');
Usage
Live rates:
Returns the latest exchange rates for all supported currencies.
$result = $currencyApi->rates();
Example with all available methods:
$result = $currencyApi ->setBase('USD') ->setOutput('JSON') ->rates();
Available methods for rates endpoint
| Methods | Description |
|---|---|
setBase() |
The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. Default: USD. |
setOutput() |
Response output in either JSON or XML. Default: JSON. |
List of available currencies:
Returns a list of all currencies supported by the API.
$result = $currencyApi->currencies();
Example with all available methods:
$result = $currencyApi ->setOutput('XML') ->currencies();
Available methods for currencies endpoint
| Methods | Description |
|---|---|
setOutput() |
Response output in either JSON or XML. Default: JSON. |
Convert:
Converts an amount from one currency to another using the latest rates.
$result = $currencyApi ->setAmount(100) ->setFrom('BTC') ->setTo('GBP') ->convert();
Available methods for convert endpoint
| Methods | Description |
|---|---|
setAmount() |
The value of the currency you want to convert from. This should be a number and can contain a decimal place. Required. |
setFrom() |
The currency you want to convert. This will be a three letter ISO 4217 currency code from one of the currencies we have rates for. Required. |
setTo() |
The currency you want to convert the amount 'to'. Again this will be a three letter currency code from the ones we offer. Required. |
setOutput() |
Response output in either JSON or XML. Default: JSON. |
Historical:
Returns exchange rates for all currencies on a specific date.
$result = $currencyApi->setDate('2019-01-01')->historical();
Example with all available methods:
$result = $currencyApi ->setDate('2019-01-01') ->setBase('GBP') ->setOutput('JSON') ->historical();
Available methods for historical endpoint
| Methods | Description |
|---|---|
setDate() |
The historical date you wish to receive the currency conversions for. This should be formatted as YYYY-MM-DD. Required. |
setBase() |
The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. Default: USD. |
setOutput() |
Response output in either JSON or XML. Default: JSON. |
Timeframe:
Returns exchange rates for all currencies across a date range, with one entry per day.
$result = $currencyApi->setStartDate('2019-01-01')->setEndDate('2019-01-05')->timeframe();
Example with all available methods:
$result = $currencyApi ->setStartDate('2019-01-01') ->setEndDate('2019-01-05') ->setBase('GBP') ->setOutput('XML') ->timeframe();
Available methods for timeframe endpoint
| Methods | Description |
|---|---|
setStartDate() |
The historical date you wish to receive the currency conversions from. This should be formatted as YYYY-MM-DD. Required. |
setEndDate() |
The historical date you wish to receive the currency conversions until. This should be formatted as YYYY-MM-DD. Required. |
setBase() |
The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. Default: USD. |
setOutput() |
Response output in either JSON or XML. Default: JSON. |
OHLC (Open, High, Low, Close):
Returns candlestick data for a currency pair on a given date, useful for charting and technical analysis.
$result = $currencyApi ->setQuote('EUR') ->setDate('2023-12-25') ->ohlc();
Example with all available methods:
$result = $currencyApi ->setQuote('EUR') ->setDate('2023-12-25') ->setBase('GBP') ->setInterval('1h') ->ohlc();
Available methods for OHLC endpoint
| Methods | Description |
|---|---|
setQuote() |
The quote currency to retrieve OHLC data for. Three letter ISO 4217 currency code. Required. |
setDate() |
The date to retrieve OHLC data for. This should be formatted as YYYY-MM-DD. Required. |
setBase() |
The base currency for the rates. Default: USD. |
setInterval() |
The interval for the OHLC candles. One of: 5m, 15m, 30m, 1h, 4h, 12h, 1d. Default: 1d. |
Example response:
{
"valid": true,
"base": "USD",
"quote": "EUR",
"date": "2023-12-25",
"interval": "1d",
"ohlc": [
{
"start": "2023-12-25T00:00:00Z",
"open": 0.9123,
"high": 0.9187,
"low": 0.9098,
"close": 0.9154
}
]
}
houseofapis/currencyapi 适用场景与选型建议
houseofapis/currencyapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 98 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「currency」 「feed」 「crypto」 「live-rates」 「json currency」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 houseofapis/currencyapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 houseofapis/currencyapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 houseofapis/currencyapi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple RSS generator library for PHP 5.5 or later. clone from Bhaktaraz Bhatta ttps://github.com/bhaktaraz/php-rss-generator
A PSR-7 compatible library for making CRUD API endpoints
Fixer.io data provider for Peso
TCMB Currenct Converter
Google Shopping Feed API (with ns problem fixed)
Immutable PHP currency converter that's data-agnostic.
统计信息
- 总下载量: 98
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-23