PHP code example of juniorov / bccr-sdde-exchange-rate
1. Go to this page and download the library: Download juniorov/bccr-sdde-exchange-rate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
juniorov / bccr-sdde-exchange-rate example snippets
$client = new BccrClient($token, BccrClient::BASE_URL, 317, 318);
// compra venta
'bccr' => ['token' => env('BCCR_SDDE_TOKEN')],
use Bccr\Sdde\BccrClient;
public function register(): void
{
$this->app->singleton(BccrClient::class, fn () => new BccrClient(
config('services.bccr.token')
));
}
use Bccr\Sdde\BccrClient;
use Illuminate\Support\Facades\Cache;
public function show(BccrClient $bccr)
{
$rates = Cache::remember('bccr.usd.rates', now()->addHour(),
fn () => $bccr->dollarRates()
);
return response()->json($rates);
}
define('BCCR_SDDE_TOKEN', 'su_token_real');
use Bccr\Sdde\BccrException;
try {
$rates = $client->dollarRates();
} catch (BccrException $error) {
if ($error->statusCode === 401) {
// Token ausente, inválido o vencido.
} elseif ($error->statusCode === 429) {
// Demasiadas solicitudes: use caché y reintente más tarde.
}
error_log($error->getMessage()); // Nunca registre el token.
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.