adamale/nbpfetch

PHP 库,帮助从NBP API获取数据。

1.0 2019-08-30 17:58 UTC

This package is auto-updated.

Last update: 2024-09-08 21:14:19 UTC


README

帮助从NBP API获取数据的PHP库 - http://api.nbp.pl/en.html.
它允许您获取货币汇率、汇率表和金价。

要求

PHP 7.2 或更高版本。

安装

a) 使用Composer

composer require adamale/nbpfetch

b) 不使用Composer
Composer File Loader 包含到您的项目中,以自动加载所有必要的类。

用法

货币汇率

<?php

use NBPFetch\NBPFetch;

require_once "vendor/autoload.php";

$NBPFetch = new NBPFetch();
$NBPFetchCurrencyRate = $NBPFetch->currencyRate();

/**
 * Currency rate examples.
 * Available methods are: current(string $currency), today(string $currency)
 * byDate(string $currency, string $date), byDateRange(string $currency, string $from, string $to)
 * and last(string $currency, int count).
 */
try {
    $currentCurrencyRate = $NBPFetchCurrencyRate->current("EUR");
    $todayCurrencyRate = $NBPFetchCurrencyRate->current("EUR");
    $givenDateCurrencyRate = $NBPFetchCurrencyRate->byDate("EUR", "2019-08-28");
    $givenDateRangeCurrencyRates = $NBPFetchCurrencyRate->byDateRange("EUR", "2019-08-01", "2019-08-31");
    $last10CurrencyRates = $NBPFetchCurrencyRate->last("EUR", 10);
} catch (Exception $e) {
}

汇率表

<?php

use NBPFetch\NBPFetch;

require_once "vendor/autoload.php";

$NBPFetch = new NBPFetch();
$NBPFetchExchangeRateTable = $NBPFetch->exchangeRateTable();

/**
 * Exchange rate table examples.
 * Available methods are: current(string $table), today(string $table),
 * byDate(string $table, string $date), byDateRange(string $table, string $from, string $to)
 * and last(string $table, int count)
 */
try {
    $currentExchangeRateTable = $NBPFetchExchangeRateTable->current("A");
    $todayExchangeRateTable = $NBPFetchExchangeRateTable->today("A");
    $givenDateExchangeRateTable = $NBPFetchExchangeRateTable->byDate("A", "2019-08-28");
    $givenDateRangeExchangeRateTables = $NBPFetchExchangeRateTable->byDateRange("A", "2019-08-01", "2019-08-31");
    $last10ExchangeRateTables = $NBPFetchExchangeRateTable->last("A", 10);
} catch (Exception $e) {
}

金价

<?php

use NBPFetch\NBPFetch;

require_once "vendor/autoload.php";

$NBPFetch = new NBPFetch();
$NBPFetchGoldPrice = $NBPFetch->goldPrice();

/**
 * Gold price examples.
 * Available methods are: current(), today(), byDate(string $date),
 * byDateRange(string $from, string $to) and last(int count)
 */
try {
    $currentGoldPrice = $NBPFetchGoldPrice->current();
    $todayGoldPrice = $NBPFetchGoldPrice->today();
    $givenDateGoldPrice = $NBPFetchGoldPrice->byDate("2019-08-28");
    $givenDateRangeGoldPrices = $NBPFetchGoldPrice->byDateRange("2019-08-01", "2019-08-31");
    $last10GoldPrices = $NBPFetchGoldPrice->last(10);
} catch (Exception $e) {
}

关于

作者

Adam Aleksak kontakt@adamaleksak.pl

许可证

NBPFetch 根据 MIT 许可证授权 - 详细信息请参阅 LICENSE 文件。