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 getPortfolioCompanyData($companyName)
Retrieves historical stock price data including open, high, low, close, adjusted close, and volume for a specified company.

Parameters

companyName
string
required
The ticker symbol of the company (e.g., “BOBU”, “DFCU”)

Return value

Returns a JSON-encoded string (via echo) containing historical stock data, or a JSON error object if the request fails.

Response examples

{
  "stock": "BOBU",
  "data": [
    {
      "date": "2024-01-15 00:00:00",
      "timestamp": 1705276800000,
      "open": 1250,
      "high": 1275,
      "low": 1240,
      "close": 1260,
      "adjusted_close": 1260,
      "volume": 15000
    },
    {
      "date": "2024-01-16 00:00:00",
      "timestamp": 1705363200000,
      "open": 1260,
      "high": 1280,
      "low": 1255,
      "close": 1270,
      "adjusted_close": 1270,
      "volume": 18500
    }
  ],
  "latestSharePrice": 1270
}

Usage example

<?php

$portfolioManager = new PortfolioManager();

// Get historical data for BOBU
$portfolioManager->getPortfolioCompanyData('BOBU');
// Data is echoed directly

?>

How it works

1

Build data URL

Constructs the API endpoint: https://www.use.or.ug/data.php?stock={companyName}&callback=?
2

Fetch JSON data

Retrieves the data using file_get_contents() and strips the JSONP callback wrapper
3

Transform data

Converts numeric array indices to named keys (timestamp, open, high, low, close, adjusted_close, volume) and adds human-readable dates
4

Build result

Creates a result array with stock symbol, data array, and latest share price
5

Output JSON

Sets appropriate headers (Content-Type: application/json and CORS header) and echoes the result

HTTP headers

The method sets the following HTTP headers:
  • Content-Type: application/json
  • Access-Control-Allow-Origin: * (enables CORS)
On error, it sets:
  • Content-Type: application/json
  • HTTP/1.1 500 Internal Server Error

Notes

This method uses echo to output the result directly, rather than returning it. Use output buffering (ob_start() and ob_get_clean()) if you need to capture the result as a variable.
  • The data source is the USE API endpoint at data.php
  • Timestamps are converted from milliseconds to human-readable format
  • The latest share price is extracted from the last data point in the array
  • CORS is enabled by default, allowing cross-origin requests

Build docs developers (and LLMs) love