Documentation Index Fetch the complete documentation index at: https://mintlify.com/jessebyarugaba/Unofficial-Uganda-Securities-Exhange-API/llms.txt
Use this file to discover all available pages before exploring further.
Method signature
public function getExchangeRateDetails ()
Retrieves current Uganda Shilling (UGX) exchange rate information, including the current value, daily change, yearly change, and 52-week range.
Parameters
This method takes no parameters.
Return value
Returns a JSON-encoded string containing exchange rate details and metadata.
Exchange rate metrics: Current UGX to USD exchange rate
Change in exchange rate for the current day
Change in exchange rate over the past year
Lowest and highest exchange rates over the past 52 weeks
HTML content containing legal disclaimer from the data source
URL of the data source (African Financials)
Time taken to execute the request in seconds (precise float value)
Human-readable execution time rounded to 4 decimal places
Response example
{
"values" : {
"VALUE/US$" : "3,750" ,
"TODAY'S CHANGE" : "+5.00 (+0.13%)" ,
"1 YEAR CHANGE" : "-125.00 (-3.23%)" ,
"52 WEEK RANGE" : "3,650 - 3,875"
},
"disclaimer" : "<p>Exchange rates are for informational purposes only...</p>" ,
"source" : "https://africanfinancials.com/currency/ug-ugx/" ,
"execution_time" : 1.2345 ,
"time in seconds" : "1.2345 seconds"
}
Usage example
Basic usage
Parse and display rates
Convert amounts
<? php
$portfolioManager = new PortfolioManager ();
// Get exchange rate details
$exchangeRates = $portfolioManager -> getExchangeRateDetails ();
// Output the JSON result
echo $exchangeRates ;
?>
How it works
Record start time
Captures the current microtime to measure execution duration
Configure HTTP request
Sets up user agent headers to mimic a browser request for proper data access
Scrape currency page
Fetches HTML content from African Financials currency page for UGX
Extract rate data
Parses the HTML to extract exchange rate values using CSS class selectors
Build response
Compiles all data including values, disclaimer, source URL, and execution time
Return JSON
Sets Content-Type: application/json header and returns the formatted JSON response
The method sets the following HTTP headers:
Content-Type: application/json
For scraping, it uses:
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36...
Data source
Exchange rate data is sourced from:
URL : https://africanfinancials.com/currency/ug-ugx/
Provider : African Financials
Update frequency : Real-time scraping on each request
Error handling
The method includes error handling for:
If the HTML fails to load, the method returns: "Error: Couldn't load the HTML." If the target data element is not found, it returns: "Error: Couldn't find the target ul."
Execution time is tracked and included in the response
Typical execution time ranges from 0.5 to 2 seconds depending on network conditions
The DOM object is explicitly cleaned up after parsing to free memory
Notes
Exchange rate data is scraped in real-time from African Financials
The disclaimer field contains HTML markup and may include legal terms from the source
All numeric values are returned as strings and may include formatting (commas, percentage signs)
The method measures its own execution time for performance monitoring