Skip to content

Commit 2402534

Browse files
committed
Add GitHub Pages documentation with Cayman theme
1 parent ac68795 commit 2402534

File tree

2 files changed

+359
-0
lines changed

2 files changed

+359
-0
lines changed

docs/_config.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
theme: jekyll-theme-cayman
2+
3+
title: Stock Portfolio Tracker API
4+
description: A modern REST API for real-time stock portfolio management
5+
show_downloads: true
6+
google_analytics:
7+
8+
# Theme settings
9+
markdown: kramdown
10+
highlighter: rouge
11+
12+
# GitHub Pages settings
13+
github:
14+
is_project_page: true
15+
repository_url: https://github.com/HackStyx/portfolio-tracker

docs/index.md

Lines changed: 344 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,344 @@
1+
---
2+
layout: default
3+
title: Stock Portfolio Tracker API
4+
description: A comprehensive guide to integrating with our real-time portfolio management solution
5+
nav_order: 1
6+
permalink: /
7+
---
8+
9+
# Stock Portfolio Tracker API Documentation
10+
11+
A modern REST API for real-time stock portfolio management with Finnhub integration.
12+
13+
[Get Started](#getting-started){: .btn .btn-primary .fs-5 .mb-4 .mb-md-0 .mr-2}
14+
[View on GitHub](https://github.com/HackStyx/portfolio-tracker){: .btn .fs-5 .mb-4 .mb-md-0}
15+
16+
## Overview
17+
18+
The Stock Portfolio Tracker API provides a comprehensive suite of endpoints for managing stock portfolios and watchlists. Built with Node.js and Express, it offers real-time market data integration through Finnhub API.
19+
20+
### Key Features
21+
22+
- 📊 Real-time Portfolio Management
23+
- 👀 Watchlist Functionality
24+
- 💹 Live Market Data
25+
- 📈 Historical Price Tracking
26+
- 🎯 Price Target Monitoring
27+
- 📱 RESTful Architecture
28+
29+
## Getting Started
30+
31+
### Base URL
32+
33+
```
34+
https://portfolio-tracker-backend-y7ne.onrender.com/api
35+
```
36+
37+
### Authentication
38+
39+
Currently, the API is open and doesn't require authentication. This is a limitation noted in the project documentation.
40+
41+
### Rate Limiting
42+
43+
The API uses Finnhub for market data, which has the following limitations:
44+
- **60 API calls per minute** per API key
45+
- Automatic fallback to simulated data when rate limit is reached
46+
- Cached responses for frequently accessed data
47+
48+
## API Reference
49+
50+
### Portfolio Management
51+
52+
#### Get All Stocks
53+
54+
Returns a list of all stocks in the portfolio.
55+
56+
```http
57+
GET /stocks
58+
```
59+
60+
**Response Format:**
61+
62+
```json
63+
[
64+
{
65+
"id": 1,
66+
"name": "Apple Inc.",
67+
"ticker": "AAPL",
68+
"shares": 1,
69+
"buy_price": 175.50,
70+
"current_price": 180.25,
71+
"target_price": 200.00,
72+
"is_in_watchlist": false,
73+
"last_updated": "2024-01-20T12:00:00Z"
74+
}
75+
]
76+
```
77+
78+
| Field | Type | Description |
79+
|-------|------|-------------|
80+
| `id` | integer | Unique identifier for the stock |
81+
| `name` | string | Company name |
82+
| `ticker` | string | Stock symbol |
83+
| `shares` | number | Number of shares owned |
84+
| `buy_price` | number | Purchase price per share |
85+
| `current_price` | number | Current market price |
86+
| `target_price` | number | Target price for alerts |
87+
| `is_in_watchlist` | boolean | Watchlist status |
88+
| `last_updated` | string | Last price update timestamp |
89+
90+
#### Add New Stock
91+
92+
Add a new stock to the portfolio.
93+
94+
```http
95+
POST /stocks
96+
```
97+
98+
**Request Body:**
99+
100+
```json
101+
{
102+
"name": "Apple Inc.",
103+
"ticker": "AAPL",
104+
"shares": 1,
105+
"buy_price": 175.50,
106+
"target_price": 200.00
107+
}
108+
```
109+
110+
| Parameter | Type | Required | Description |
111+
|-----------|------|----------|-------------|
112+
| `name` | string | Yes | Company name |
113+
| `ticker` | string | Yes | Stock symbol |
114+
| `shares` | number | Yes | Number of shares |
115+
| `buy_price` | number | Yes | Purchase price |
116+
| `target_price` | number | No | Target price |
117+
118+
**Response:** Returns the created stock object with a `201 Created` status.
119+
120+
#### Update Stock
121+
122+
Update an existing stock's details.
123+
124+
```http
125+
PUT /stocks/:id
126+
```
127+
128+
**URL Parameters:**
129+
130+
| Parameter | Type | Description |
131+
|-----------|------|-------------|
132+
| `id` | integer | Stock ID to update |
133+
134+
**Request Body:**
135+
136+
```json
137+
{
138+
"shares": 2,
139+
"buy_price": 180.00,
140+
"target_price": 210.00
141+
}
142+
```
143+
144+
**Response:** Returns the updated stock object.
145+
146+
#### Delete Stock
147+
148+
Remove a stock from the portfolio.
149+
150+
```http
151+
DELETE /stocks/:id
152+
```
153+
154+
**Response:** Returns `204 No Content` on success.
155+
156+
### Watchlist Management
157+
158+
#### Get Watchlist
159+
160+
```http
161+
GET /watchlist
162+
```
163+
164+
Returns all stocks in the watchlist.
165+
166+
#### Add to Watchlist
167+
168+
```http
169+
POST /watchlist
170+
```
171+
172+
**Request Body:**
173+
174+
```json
175+
{
176+
"name": "Microsoft Corporation",
177+
"ticker": "MSFT",
178+
"target_price": 400.00
179+
}
180+
```
181+
182+
### Market Data
183+
184+
#### Get Stock Quote
185+
186+
```http
187+
GET /stocks/:ticker/quote
188+
```
189+
190+
Get real-time quote for a specific stock.
191+
192+
**Response Example:**
193+
194+
```json
195+
{
196+
"c": 180.25, // Current price
197+
"h": 182.50, // High price of the day
198+
"l": 179.75, // Low price of the day
199+
"o": 180.00, // Open price
200+
"pc": 179.50 // Previous close price
201+
}
202+
```
203+
204+
#### Get Historical Data
205+
206+
```http
207+
GET /stocks/:ticker/history
208+
```
209+
210+
**Query Parameters:**
211+
212+
| Parameter | Type | Description |
213+
|-----------|------|-------------|
214+
| `resolution` | string | Data resolution (e.g., "D" for daily) |
215+
| `from` | integer | Start timestamp (Unix) |
216+
| `to` | integer | End timestamp (Unix) |
217+
218+
### Portfolio Analytics
219+
220+
#### Get Portfolio Summary
221+
222+
```http
223+
GET /stocks/summary
224+
```
225+
226+
**Response Example:**
227+
228+
```json
229+
{
230+
"totalValue": 10000.00,
231+
"totalGain": 500.00,
232+
"totalGainPercent": 5.00,
233+
"stockCount": 5
234+
}
235+
```
236+
237+
## Error Handling
238+
239+
The API uses standard HTTP status codes and provides detailed error messages.
240+
241+
### Status Codes
242+
243+
| Code | Description |
244+
|------|-------------|
245+
| `200` | Success |
246+
| `201` | Created |
247+
| `400` | Bad Request |
248+
| `404` | Not Found |
249+
| `429` | Too Many Requests |
250+
| `500` | Internal Server Error |
251+
252+
### Error Response Format
253+
254+
```json
255+
{
256+
"error": "Error message description",
257+
"code": "ERROR_CODE",
258+
"details": {
259+
"field": "Additional error context"
260+
}
261+
}
262+
```
263+
264+
## Rate Limiting Strategy
265+
266+
To handle Finnhub API rate limits effectively:
267+
268+
1. **Caching**
269+
- Stock quotes cached for 1 minute
270+
- Historical data cached for 1 hour
271+
- Company information cached for 24 hours
272+
273+
2. **Request Queuing**
274+
- Implements token bucket algorithm
275+
- Prioritizes real-time quote requests
276+
- Queues non-critical updates
277+
278+
3. **Fallback Mechanism**
279+
- Uses simulated data when rate limited
280+
- Clearly indicates simulated vs real data
281+
- Retries failed requests with exponential backoff
282+
283+
## Development Guide
284+
285+
### Local Setup
286+
287+
1. Clone the repository:
288+
```bash
289+
git clone https://github.com/HackStyx/portfolio-tracker.git
290+
cd portfolio-tracker
291+
```
292+
293+
2. Install dependencies:
294+
```bash
295+
npm install
296+
```
297+
298+
3. Configure environment:
299+
```bash
300+
cp .env.example .env
301+
# Edit .env with your credentials
302+
```
303+
304+
4. Start development server:
305+
```bash
306+
npm run dev
307+
```
308+
309+
### Testing
310+
311+
Run the test suite:
312+
```bash
313+
npm test
314+
```
315+
316+
### Deployment
317+
318+
The API is deployed on Render with the following configuration:
319+
320+
1. **Environment Variables**
321+
- `NODE_ENV=production`
322+
- `PORT=5000`
323+
- `DATABASE_URL`
324+
- `FINNHUB_API_KEY`
325+
326+
2. **Build Command**
327+
```bash
328+
npm install && npm run build
329+
```
330+
331+
3. **Start Command**
332+
```bash
333+
npm start
334+
```
335+
336+
## Support & Feedback
337+
338+
- 📝 [Report a Bug](https://github.com/HackStyx/portfolio-tracker/issues/new?template=bug_report.md)
339+
- 💡 [Request a Feature](https://github.com/HackStyx/portfolio-tracker/issues/new?template=feature_request.md)
340+
- 📚 [Documentation Updates](https://github.com/HackStyx/portfolio-tracker/issues/new?template=documentation.md)
341+
342+
## License
343+
344+
This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details.

0 commit comments

Comments
 (0)