<?php
function get_fiat_rates() {
    $fiat_currencies = [
        'USD' => 1.00,
        'EUR' => 0.92,
        'GBP' => 0.79,
        'CNY' => 7.23,
        'HKD' => 7.82,
        'JPY' => 151.45,
        'KRW' => 1350.20,
        'SGD' => 1.35,
        'TWD' => 32.10,
        'THB' => 36.50,
        'VND' => 24800,
        'IDR' => 15850,
        'MYR' => 4.74,
    ];

    $api_url = 'https://api.exchangerate-api.com/v4/latest/USD';
    $ctx = stream_context_create(['http' => ['timeout' => 2]]);
    $json = @file_get_contents($api_url, false, $ctx);
    if ($json) {
        $data = json_decode($json, true);
        if (isset($data['rates'])) {
            foreach ($fiat_currencies as $code => $rate) {
                if (isset($data['rates'][$code])) {
                    $fiat_currencies[$code] = $data['rates'][$code];
                }
            }
        }
    }
    return $fiat_currencies;
}
