File size: 1,636 Bytes
f6e40df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
```json
[
    {"name": "Banking", "weightage": 35.0, "change_percent": 0.85, "top_stock": "HBL"},
    {"name": "Oil & Gas", "weightage": 20.0, "change_percent": 1.25, "top_stock": "OGDC"},
    {"name": "Cement", "weightage": 15.0, "change_percent": -2.35, "top_stock": "LUCK"},
    {"name": "Chemical", "weightage": 10.0, "change_percent": 3.15, "top_stock": "ENGRO"},
    {"name": "Power", "weightage": 8.0, "change_percent": 0.45, "top_stock": "KAPCO"},
    {"name": "Textile", "weightage": 7.0, "change_percent": -0.75, "top_stock": "NML"},
    {"name": "Technology", "weightage": 5.0, "change_percent": 2.15, "top_stock": "TRG"}
]
```

This implementation:

1. Creates a SQLite database with tables for:
   - Users
   - PSX Companies
   - Sectors
   - User Portfolios
   - Transactions
   - UAC Reports

2. Sets up a Node.js/Express server to:
   - Serve the frontend files
   - Provide API endpoints for data access
   - Initialize the database with sample data

3. Updates the frontend to:
   - Use a centralized API service class
   - Connect to our local API instead of mock endpoints
   - Handle errors gracefully with fallback data

4. Includes sample data for:
   - 10 PSX companies across major sectors
   - 7 market sectors with weightage and performance data

To use this:

1. Install dependencies:
```bash
npm install express sqlite3
```

2. Start the server:
```bash
node server.js
```

3. The site will be available at http://localhost:3000

The database will be automatically created and populated with sample data on first run. All frontend pages will now use real data from our SQLite database via the API endpoints.