Skip to content

Official PHP SDK for OpenExchangeAPI — fetch currency rates and perform conversions using simple, native PHP code.

License

Notifications You must be signed in to change notification settings

OpenExchangeAPI/sdk-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

OpenExchangeAPI PHP SDK

Minimal, idiomatic PHP client for OpenExchangeAPI

  • All endpoints supported
  • API key is optional
  • Returns associative arrays for all responses
  • Flexible for use in CakePHP, Laravel, Symfony, or any PHP project

Installation

Just copy OpenExchangeApiClient.php into your project, or use Composer:

composer require openexchangeapi/openexchangeapi-php

Usage

use OpenExchangeApi\OpenExchangeApiClient;

$client = new OpenExchangeApiClient('YOUR_API_KEY'); // API key optional

// Get latest rates
$latest = $client->getLatest();

// Convert currency
$result = $client->convert('USD', 'EUR', 100);

// List currencies
$currencies = $client->listCurrencies();

// Get currency details
$eur = $client->getCurrency('EUR');

API Reference

  • getLatest($base = null)
  • getLatestPrecise($base = null)
  • getHistorical($date, $base = null)
  • getHistoricalPrecise($date, $base = null)
  • convert($from, $to, $amount)
  • convertPrecise($from, $to, $amount)
  • listCurrencies($type = null)
  • getCurrency($code)

All methods throw OpenExchangeApiException on error.

Custom HTTP Client

You can inject your own HTTP client (e.g., Guzzle, CakePHP, Laravel, Symfony):

$client = new OpenExchangeApiClient(null, null, function($url, $params) {
    // ...your HTTP logic...
    return $arrayResponse;
});

Error Handling

All errors throw OpenExchangeApiException:

try {
    $data = $client->getLatest();
} catch (OpenExchangeApiException $e) {
    // Handle error
}

License

MIT

About

Official PHP SDK for OpenExchangeAPI — fetch currency rates and perform conversions using simple, native PHP code.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages