Skip to main content

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.

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

<?php

$portfolioManager = new PortfolioManager();

// Get exchange rate details
$exchangeRates = $portfolioManager->getExchangeRateDetails();

// Output the JSON result
echo $exchangeRates;

?>

How it works

1

Record start time

Captures the current microtime to measure execution duration
2

Configure HTTP request

Sets up user agent headers to mimic a browser request for proper data access
3

Scrape currency page

Fetches HTML content from African Financials currency page for UGX
4

Extract rate data

Parses the HTML to extract exchange rate values using CSS class selectors
5

Build response

Compiles all data including values, disclaimer, source URL, and execution time
6

Return JSON

Sets Content-Type: application/json header and returns the formatted JSON response

HTTP headers

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."

Performance

  • 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

Build docs developers (and LLMs) love