Spaces:
Running
Running
| ```javascript | |
| class StockfolioAPI { | |
| static async getMarketSummary() { | |
| try { | |
| const response = await axios.get('/api/market-summary'); | |
| return response.data; | |
| } catch (error) { | |
| console.error('Error fetching market summary:', error); | |
| return { | |
| kse100: 42500.75, | |
| change_percent: 0.45, | |
| volume: 125600000, | |
| value: 8450000000 | |
| }; | |
| } | |
| } | |
| static async getTopStocks() { | |
| try { | |
| const response = await axios.get('/api/companies?limit=4'); | |
| return response.data; | |
| } catch (error) { | |
| console.error('Error fetching top stocks:', error); | |
| return [ | |
| { | |
| symbol: "OGDC", | |
| name: "Oil & Gas Development Company", | |
| sector: "Oil & Gas", | |
| price: 86.45, | |
| change: 1.25, | |
| volume: 12500000 | |
| }, | |
| { | |
| symbol: "LUCK", | |
| name: "Lucky Cement", | |
| sector: "Cement", | |
| price: 650.20, | |
| change: -2.35, | |
| volume: 850000 | |
| }, | |
| { | |
| symbol: "HBL", | |
| name: "Habib Bank Limited", | |
| sector: "Banking", | |
| price: 125.75, | |
| change: 0.85, | |
| volume: 4500000 | |
| }, | |
| { | |
| symbol: "ENGRO", | |
| name: "Engro Corporation", | |
| sector: "Chemical", | |
| price: 320.50, | |
| change: 3.15, | |
| volume: 2200000 | |
| } | |
| ]; | |
| } | |
| } | |
| static async getCompanies() { | |
| try { | |
| const response = await axios.get('/api/companies'); | |
| return response.data; | |
| } catch (error) { | |
| console.error('Error fetching companies:', error); | |
| return []; | |
| } | |
| } | |
| static async getSectors() { | |
| try { | |
| const response = await axios.get('/api/sectors'); | |
| return response.data; | |
| } catch (error) { | |
| console.error('Error fetching sectors:', error); | |
| return []; | |
| } | |
| } | |
| static async getUACReports(userId) { | |
| try { | |
| const response = await axios.get(`/api/uac-reports/${userId}`); | |
| return response.data; | |
| } catch (error) { | |
| console.error('Error fetching UAC reports:', error); | |
| return []; | |
| } | |
| } | |
| } | |
| ``` |