PHP code example of aicrion / ir-currency-rate-scraper

1. Go to this page and download the library: Download aicrion/ir-currency-rate-scraper 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/ */

    

aicrion / ir-currency-rate-scraper example snippets


use Aicrion\IrCurrencyRateScraper\CurrencyScraper;
use Aicrion\IrCurrencyRateScraper\Enums\RateCategory;
use Aicrion\IrCurrencyRateScraper\Enums\AggregationStrategy;

// 1. Initialize with 5-minute File Cache
$scraper = CurrencyScraper::create();
$scraper->enableFileCache(__DIR__ . '/cache', 300);

// 2. High-Speed Preload / Warmup (0ms latency for subsequent requests)
$scraper->warmup();

// 3. Fetch Rates
$usd = $scraper->getUsd();
echo "USD: " . number_format($usd->getPrice()) . " Rial (" . number_format($usd->getPriceInTomans()) . " Toman)\n";

$gold18k = $scraper->getGold18k();
$coinEmami = $scraper->getCoinEmami();

// 4. Convert Currency
$tomans = $scraper->convert(100, 'USD', 'TOMAN');
echo "100 USD = " . number_format($tomans) . " Tomans\n";

// 5. Calculate Gold Jewelry Price (4.5g 18K with 10% wage, 7% profit, 9% VAT)
$goldCalc = $scraper->calculateGold(4.5, 18, 10.0, 7.0, 9.0);
echo "Gold Total: " . number_format($goldCalc['total_price_toman']) . " Tomans\n";

// 6. Multi-Source Aggregation (Bitcoin Average)
$btc = $scraper->aggregate('BTC', RateCategory::CRYPTO, AggregationStrategy::AVERAGE);
echo "Average BTC: $" . number_format($btc->getAveragePrice(), 2) . "\n";
bash
# View live rate
php bin/currency rate USD

# Display market table
php bin/currency table gold

# Currency conversion
php bin/currency convert 100 USD TOMAN

# Gold breakdown
php bin/currency gold 5 18 10

# Search
php bin/currency search دلار

# Cache warmup
php bin/currency warmup