Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/MiguelNavas19/miapibcv/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Mi API BCV collects USD/VES exchange rates from four major Venezuelan financial institutions. Each source uses a different method for data extraction, but all provide reliable rate information.

BCV (Banco Central de Venezuela)

About

The Banco Central de Venezuela is the official central bank of Venezuela. Their published rate is considered the official government reference rate.

Data Source

  • URL: https://www.bcv.org.ve/
  • Method: Web scraping
  • Update Frequency: Daily (typically updated in the morning)

Scraping Implementation

app/Strategies/Url/UrlBcv.php
class UrlBcv implements UrlStrategy
{
    protected $scraper;

    public function __construct($scraper)
    {
        $this->scraper = $scraper;
    }

    public function getValue(): float
    {
        $url = 'https://www.bcv.org.ve/';
        $value = $this->scraper->scrapeData($url, 'bcv');
        return $value;
    }
}

Parsing Logic

app/Services/ScraperService.php
private function parseBCVData($crawler)
{
    $element = $crawler->filter('#dolar');
    if ($element->count() === 0) {
        throw new \Exception('No se encontró el elemento esperado en BCV');
    }

    $text = $element->text();

    if (preg_match('/USD\s+(.*)/', $text, $matches)) {
        if (preg_match_all('/[0-9]+,[0-9]+/', $matches[1], $coincidencias)) {
            $valor = trim($coincidencias[0][0]);
        }
    }

    return $this->cleanValue($valor);
}
CSS Selector: #dolar - Targets the element with ID “dolar” containing the USD rate Extraction Pattern: Looks for “USD” followed by a number in format “XX,XX”
The BCV website structure may change occasionally. If scraping fails, check if the #dolar selector is still valid.

Banplus

About

Banplus is a major Venezuelan commercial bank. They display their exchange rate prominently on their homepage for transparency.

Data Source

  • URL: https://www.banplus.com/
  • Method: Web scraping
  • Update Frequency: Multiple times daily

Scraping Implementation

app/Strategies/Url/UrlBanplus.php
class UrlBanplus implements UrlStrategy
{
    protected $scraper;

    public function __construct($scraper)
    {
        $this->scraper = $scraper;
    }

    public function getValue(): float
    {
        $url = 'https://www.banplus.com/';
        $value = $this->scraper->scrapeData($url, 'banplus');
        return $value;
    }
}

Parsing Logic

app/Services/ScraperService.php
private function parseBanplusData($crawler)
{
    $element = $crawler->filter('.awb-news-ticker-link');
    if ($element->count() === 0) {
        throw new \Exception('No se encontró el elemento esperado en Banplus');
    }

    $text = $element->text();

    $valor = null;
    if (preg_match('/tasa de cambio\s+(.*)/', $text, $matches)) {
        if (preg_match_all('/[0-9]+,[0-9]+/', $matches[1], $coincidencias)) {
            $valor = trim($coincidencias[0][0]);
        }
    }

    if ($valor === null) {
        $valor = $text;
    }

    return $this->cleanValue($valor);
}
CSS Selector: .awb-news-ticker-link - Targets the news ticker element Extraction Pattern: Searches for “tasa de cambio” (exchange rate) followed by the numeric value
Banplus displays rates in a news ticker format, making it easy to identify and extract.

BNC (Banco Nacional de Crédito)

About

Banco Nacional de Crédito is one of Venezuela’s largest banks. They publish their exchange rates on their online banking portal.

Data Source

  • URL: https://www.bncenlinea.com/
  • Method: Web scraping
  • Update Frequency: Daily

Scraping Implementation

app/Strategies/Url/UrlBnc.php
class UrlBnc implements UrlStrategy
{
    protected $scraper;

    public function __construct($scraper)
    {
        $this->scraper = $scraper;
    }

    public function getValue(): float
    {
        $url = 'https://www.bncenlinea.com/';
        $value = $this->scraper->scrapeData($url, 'bnc');
        return $value;
    }
}

Parsing Logic

app/Services/ScraperService.php
private function parseBNCData($crawler)
{
    $items = $crawler->filter('.ItemSpace')->each(function (Crawler $node) {
        $text = $node->text();
        return str_contains($text, 'USD $ Compra Bs:') ? $text : null;
    });

    $filteredItems = array_values(array_filter($items));
    if (empty($filteredItems)) {
        throw new \Exception('No se encontró el texto esperado en BNC');
    }

    preg_match_all('/[0-9]+,[0-9]+/', $filteredItems[0], $matches);
    if (empty($matches[0])) {
        throw new \Exception('No se encontró el valor numérico en BNC');
    }

    $value = $matches[0][0];
    return $this->cleanValue($value);
}
CSS Selector: .ItemSpace - Targets item containers, then filters for USD purchase rate Extraction Pattern: Searches for “USD $ Compra Bs:” text and extracts the following numeric value
BNC requires text filtering as they display multiple currency rates. The scraper specifically looks for the USD purchase rate.

BDV (Banco de Venezuela)

About

Banco de Venezuela is a state-owned bank. Unlike the other sources, they provide a JSON API endpoint, making data extraction more reliable.

Data Source

  • URL: https://www.bancodevenezuela.com/files/tasas/tasas2.json
  • Method: API integration (JSON)
  • Update Frequency: Real-time

Implementation

app/Strategies/Url/UrlBdv.php
class UrlBdv implements UrlStrategy
{
    protected string $url = 'https://www.bancodevenezuela.com/files/tasas/tasas2.json';

    public function getValue(): float
    {
        try {
            $response = Http::timeout(10)
                ->withHeaders([
                    'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0',
                    'Accept' => 'application/json',
                ])
                ->get($this->url);

            if ($response->failed()) {
                throw new Exception("Error de conexión con BDV: " . $response->status());
            }

            $data = $response->json();
            $rawRate = data_get($data, 'menudeo.compra.dolares');

            if (!$rawRate) {
                throw new Exception("Estructura de JSON no reconocida o tasa faltante.");
            }

            return $this->formatRate($rawRate);
        } catch (Exception $e) {
            Log::error("Fallo obteniendo tasa BDV: " . $e->getMessage());
            return "0.00";
        }
    }

    private function formatRate(string $rate): float
    {
        $cleanRate = str_replace(',', '.', $rate);
        return (float) preg_replace('/[^0-9.]/', '', $cleanRate);
    }
}
API Endpoint: Direct JSON file access Data Path: menudeo.compra.dolares - Retail dollar purchase rate JSON Structure Example:
{
  "menudeo": {
    "compra": {
      "dolares": "45,26"
    }
  }
}
BDV’s API approach is more reliable than web scraping since JSON structure changes less frequently than HTML.

Data Normalization

All sources use the same normalization function to ensure consistent data format:
app/Services/ScraperService.php
private function cleanValue($value)
{
    // Replace comma with period (Venezuelan format uses comma for decimals)
    // Remove any non-numeric characters except period
    // Convert to float
    return (float) preg_replace('/[^0-9.]/', '', str_replace(',', '.', $value));
}
Input: "45,25" (Venezuelan format) Output: 45.25 (PHP float)

Comparison of Sources

BankMethodReliabilityUpdate SpeedComplexity
BCVScrapingHighMediumMedium
BanplusScrapingMediumFastMedium
BNCScrapingMediumMediumHigh
BDVJSON APIVery HighReal-timeLow

Rate Variations

Exchange rates typically vary slightly between banks:
  • BCV: Official rate, usually the baseline
  • Banplus: Slightly higher (0.05-0.10 above BCV)
  • BNC: Similar to Banplus
  • BDV: Close to BCV (state-owned bank)
Rate differences reflect each bank’s individual market position and operational costs.

Adding New Data Sources

To add a new bank:
1

Create Strategy Class

Create a new class implementing UrlStrategy:
app/Strategies/Url/UrlNewBank.php
class UrlNewBank implements UrlStrategy
{
    protected $scraper;

    public function __construct($scraper)
    {
        $this->scraper = $scraper;
    }

    public function getValue(): float
    {
        $url = 'https://newbank.com/';
        $value = $this->scraper->scrapeData($url, 'newbank');
        return $value;
    }
}
2

Add Parsing Logic

Add a parsing method in ScraperService:
private function parseNewBankData($crawler)
{
    // Your scraping logic here
    $element = $crawler->filter('.rate-display');
    $text = $element->text();
    return $this->cleanValue($text);
}
3

Register Strategy

Add to UrlProviderService:
public function getStrategy(string $identifier): UrlStrategy
{
    return match ($identifier) {
        'newbank' => new UrlNewBank(new ScraperService()),
        // ... existing banks
    };
}
4

Update Command

Add to the banks array in FetchExchangeRates:
protected array $banco = ['bdv', 'banplus', 'bnc', 'bcv', 'newbank'];