Version: 1.0
Base URL: http://localhost:5000/api
Date: January 9, 2026
The Pine Script Library API provides a RESTful interface for managing TradingView Pine Script files with metadata tracking, version control, and automated code quality validation.
- ✅ Full CRUD operations for scripts
- ✅ Version control with history tracking
- ✅ Automated code review based on official standards
- ✅ Auto-fix capabilities for common issues
- ✅ LLM-powered smart fixes
- ✅ Backup and restore functionality
- Protocol: HTTP/REST
- Data Format: JSON
- CORS: Enabled for all origins
- Authentication: None (local development)
- Rate Limiting: None (consider adding for production)
Current: No authentication required (local development only)
Production Recommendations:
- Implement API key authentication
- Add JWT tokens for session management
- Consider OAuth2 for third-party integrations
{
"id": "string", // Unique identifier
"name": "string", // Display name (required)
"type": "string", // "indicator", "strategy", or "study" (required)
"version": "string", // Semantic version (e.g., "1.0.0")
"currentVersion": "string", // Active version number
"pineVersion": number, // Pine Script version (5 or 6)
"description": "string", // Script description
"author": "string", // Author name
"tags": ["string"], // Searchable tags
"timeframes": ["string"], // Recommended timeframes
"status": "string", // "active", "testing", "deprecated", or "archived"
"filePath": "string", // Path to script file (required)
"dateCreated": "string", // ISO 8601 timestamp
"dateModified": "string", // ISO 8601 timestamp
"parameters": [ // Input parameters
{
"name": "string",
"type": "string",
"default": any,
"description": "string"
}
],
"backtest": { // Backtest metrics (for strategies)
"symbol": "string",
"timeframe": "string",
"startDate": "string",
"endDate": "string",
"initialCapital": number,
"netProfit": number,
"netProfitPercent": number,
"totalTrades": number,
"winningTrades": number,
"losingTrades": number,
"winRate": number,
"profitFactor": number,
"maxDrawdown": number,
"avgTrade": number,
"avgWinningTrade": number,
"avgLosingTrade": number,
"sharpeRatio": number,
"notes": "string"
},
"versions": [ // Version history
{
"version": "string",
"filePath": "string",
"dateCreated": "string",
"changelog": "string",
"author": "string",
"isActive": boolean
}
]
}{
"scriptName": "string",
"reviewedVersion": "string",
"summary": {
"totalIssues": number,
"critical": number,
"high": number,
"medium": number,
"warning": number,
"passed": number
},
"issues": [
{
"category": "string",
"check": "string",
"severity": "string", // "CRITICAL", "HIGH", "MEDIUM", "WARNING", "PASS"
"message": "string",
"line": number,
"code": "string",
"quickfix": { // Optional
"type": "string",
"old_name": "string",
"new_name": "string"
}
}
],
"recommendations": [
{
"category": "string",
"message": "string"
}
]
}{
"version": "string", // Semantic version
"filePath": "string", // Path to versioned file
"dateCreated": "string", // ISO 8601 timestamp
"changelog": "string", // Change description
"author": "string", // Author of this version
"isActive": boolean // Is this the current version?
}GET /api/scriptsDescription: Retrieve all scripts with metadata
Response: 200 OK
{
"scripts": [Script]
}Example:
curl http://localhost:5000/api/scriptsGET /api/scripts/:idDescription: Retrieve a specific script by ID
Parameters:
id(path, required) - Script unique identifier
Response: 200 OK
{Script}Errors:
404 Not Found- Script not found
Example:
curl http://localhost:5000/api/scripts/abc123POST /api/scriptsDescription: Create a new script with initial version
Request Body: (application/json)
{
"name": "My Strategy", // Required
"type": "strategy", // Required: "indicator", "strategy", or "study"
"version": "1.0.0", // Optional: defaults to "1.0.0"
"filePath": "scripts/strategies/my-strategy/my-strategy.pine", // Required
"description": "Strategy description",
"author": "Your Name",
"tags": ["trend", "momentum"],
"timeframes": ["1h", "4h"],
"status": "active",
"parameters": [...]
}Response: 201 Created
{Script}Features:
- ✅ Automatically generates ID if not provided
- ✅ Creates version directory structure
- ✅ Generates initial Pine Script template
- ✅ Initializes version control
Errors:
400 Bad Request- Missing required fields409 Conflict- Script ID already exists500 Internal Server Error- Server error
Example:
curl -X POST http://localhost:5000/api/scripts \
-H "Content-Type: application/json" \
-d '{
"name": "My Indicator",
"type": "indicator",
"filePath": "scripts/indicators/my-indicator/my-indicator.pine"
}'PUT /api/scripts/:idDescription: Update script metadata (not code)
Parameters:
id(path, required) - Script unique identifier
Request Body: (application/json)
{
"name": "Updated Name",
"description": "New description",
"status": "testing",
... any other fields to update
}Response: 200 OK
{Script}Features:
- ✅ Automatically updates
dateModified - ✅ Preserves
dateCreated - ✅ Merges with existing data
Errors:
404 Not Found- Script not found500 Internal Server Error- Server error
Example:
curl -X PUT http://localhost:5000/api/scripts/abc123 \
-H "Content-Type: application/json" \
-d '{"status": "testing"}'DELETE /api/scripts/:idDescription: Delete a script (soft delete - preserves files)
Parameters:
id(path, required) - Script unique identifier
Response: 200 OK
{
"message": "Script deleted successfully"
}Note: Files are NOT deleted from disk, only metadata is removed
Errors:
404 Not Found- Script not found500 Internal Server Error- Server error
Example:
curl -X DELETE http://localhost:5000/api/scripts/abc123GET /api/scripts/:id/codeDescription: Retrieve Pine Script code for current or specific version
Parameters:
id(path, required) - Script unique identifierversion(query, optional) - Specific version to retrieve
Response: 200 OK
{
"code": "string", // Pine Script code
"version": "string", // Version number
"filePath": "string" // File path
}Errors:
404 Not Found- Script or version not found500 Internal Server Error- Server error
Examples:
# Get current version
curl http://localhost:5000/api/scripts/abc123/code
# Get specific version
curl http://localhost:5000/api/scripts/abc123/code?version=1.0.0GET /api/scripts/:id/reviewDescription: Perform comprehensive code quality review
Parameters:
id(path, required) - Script unique identifierversion(query, optional) - Version to review (defaults to current)
Response: 200 OK
{CodeReviewResult}Validation Categories:
- Script structure (version declaration, organization)
- Naming conventions (camelCase, SNAKE_CASE)
- Formatting (spacing, indentation)
- Pine Script syntax (ternary, line continuation)
- Performance (plot limits, loop efficiency)
- Logic errors (OHLC, division by zero, strategy API)
- Platform limitations
Errors:
404 Not Found- Script or file not found500 Internal Server Error- Server error
Example:
curl http://localhost:5000/api/scripts/abc123/reviewPOST /api/scripts/:id/save-codeDescription: Save edited code and create new version
Parameters:
id(path, required) - Script unique identifier
Request Body: (application/json)
{
"code": "string", // Updated Pine Script code
"newVersion": "string", // New version number (e.g., "1.0.1")
"changelog": "string", // Description of changes
"author": "string" // Author of this version (optional)
}Response: 200 OK
{
"message": "Code saved successfully",
"script": {Script},
"newVersion": {Version}
}Features:
- ✅ Creates new version file
- ✅ Injects version metadata into code header
- ✅ Deactivates previous version
- ✅ Updates script metadata
Errors:
400 Bad Request- Missing required fields404 Not Found- Script not found500 Internal Server Error- Server error
Example:
curl -X POST http://localhost:5000/api/scripts/abc123/save-code \
-H "Content-Type: application/json" \
-d '{
"code": "//@version=5\nindicator(\"My Indicator\")\nplot(close)",
"newVersion": "1.0.1",
"changelog": "Fixed bug in calculation"
}'POST /api/scripts/:id/autofixDescription: Automatically fix a single code issue
Parameters:
id(path, required) - Script unique identifier
Request Body: (application/json)
{
"issue": { // Issue object from code review
"quickfix": {
"type": "string",
"old_name": "string",
"new_name": "string"
}
},
"version": "string" // Version to fix (optional)
}Response: 200 OK
{
"success": true,
"message": "Issue fixed successfully",
"fixedCode": "string",
"newVersion": "string"
}Supported Fix Types:
rename_input_variable- Rename input to add "Input" suffixadd_version- Add missing version declarationfix_operator_spacing- Add spaces around operators
Errors:
400 Bad Request- Missing required fields or unsupported fix type404 Not Found- Script not found500 Internal Server Error- Server error
POST /api/scripts/:id/auto-fix-allDescription: Automatically fix all fixable issues
Parameters:
id(path, required) - Script unique identifier
Request Body: (application/json)
{
"issues": [{Issue}], // Array of issues with quickfix
"version": "string" // Version to fix (optional)
}Response: 200 OK
{
"success": true,
"fixedCode": "string",
"fixesApplied": number,
"newVersion": "string"
}Features:
- ✅ Applies all quick-fixes in sequence
- ✅ Creates new version after fixes
- ✅ Validates code after fixes
Errors:
400 Bad Request- Missing required fields404 Not Found- Script not found500 Internal Server Error- Server error
POST /api/scripts/:id/smart-autofixDescription: Use LLM to intelligently fix code issues
Parameters:
id(path, required) - Script unique identifier
Request Body: (application/json)
{
"issue": {Issue}, // Issue to fix
"code": "string", // Current code
"scriptName": "string"
}Response: 200 OK
{
"success": true,
"fixedCode": "string",
"explanation": "string",
"newVersion": "string"
}Requirements:
- OpenAI or Anthropic API key configured
DEFAULT_LLM_PROVIDERenvironment variable set
Features:
- ✅ Context-aware fixes
- ✅ Preserves code functionality
- ✅ Follows Pine Script standards
- ✅ Provides explanation of changes
Errors:
400 Bad Request- Missing API key404 Not Found- Script not found500 Internal Server Error- LLM error
GET /api/scripts/:id/versionsDescription: Get all versions of a script
Parameters:
id(path, required) - Script unique identifier
Response: 200 OK
{
"currentVersion": "string",
"versions": [{Version}]
}Features:
- ✅ Sorted by date (newest first)
- ✅ Indicates active version
- ✅ Includes changelogs
Errors:
404 Not Found- Script not found500 Internal Server Error- Server error
Example:
curl http://localhost:5000/api/scripts/abc123/versionsPOST /api/scripts/:id/versions/:version/restoreDescription: Restore a previous version as the current version
Parameters:
id(path, required) - Script unique identifierversion(path, required) - Version to restore (e.g., "1.0.0")
Response: 200 OK
{
"message": "Version restored successfully",
"restoredVersion": "string",
"newActiveVersion": "string",
"script": {Script}
}Features:
- ✅ Creates new version from restored code
- ✅ Preserves version history
- ✅ Updates active version pointer
Errors:
404 Not Found- Script or version not found500 Internal Server Error- Server error
Example:
curl -X POST http://localhost:5000/api/scripts/abc123/versions/1.0.0/restoreGET /api/backupsDescription: Get list of all backup files
Response: 200 OK
{
"backups": [
{
"filename": "scripts_20260108_120000.json",
"date": "2026-01-08T12:00:00Z",
"size": 245678
}
]
}Features:
- ✅ Sorted by date (newest first)
- ✅ Includes file size
- ✅ Auto-created on every save operation
Example:
curl http://localhost:5000/api/backupsPOST /api/backups/:filenameDescription: Restore scripts from a backup file
Parameters:
filename(path, required) - Backup filename
Response: 200 OK
{
"message": "Backup restored successfully",
"scriptsCount": number
}Warning: This operation replaces current scripts.json
Errors:
404 Not Found- Backup file not found500 Internal Server Error- Server error
Example:
curl -X POST http://localhost:5000/api/backups/scripts_20260108_120000.jsonGET /api/debug/api-key-statusDescription: Check if LLM API keys are configured
Response: 200 OK
{
"openai": {
"configured": boolean,
"model": "string"
},
"anthropic": {
"configured": boolean,
"model": "string"
},
"defaultProvider": "string"
}Example:
curl http://localhost:5000/api/debug/api-key-status{
"error": "string" // Error message
}| Code | Meaning | Description |
|---|---|---|
| 200 | OK | Successful request |
| 201 | Created | Resource created successfully |
| 400 | Bad Request | Invalid request parameters |
| 404 | Not Found | Resource not found |
| 409 | Conflict | Resource already exists |
| 500 | Internal Server Error | Server error |
curl -X POST http://localhost:5000/api/scripts \
-H "Content-Type: application/json" \
-d '{
"name": "RSI Divergence Indicator",
"type": "indicator",
"filePath": "scripts/indicators/rsi-divergence/rsi-divergence.pine",
"description": "Detects RSI divergences",
"author": "John Doe",
"tags": ["RSI", "divergence", "momentum"]
}'curl http://localhost:5000/api/scripts/{id}/codecurl http://localhost:5000/api/scripts/{id}/reviewcurl -X POST http://localhost:5000/api/scripts/{id}/autofix \
-H "Content-Type: application/json" \
-d '{
"issue": {
"quickfix": {
"type": "rename_input_variable",
"old_name": "length",
"new_name": "lengthInput"
}
}
}'curl -X POST http://localhost:5000/api/scripts/{id}/save-code \
-H "Content-Type: application/json" \
-d '{
"code": "...",
"newVersion": "1.0.1",
"changelog": "Fixed naming conventions"
}'curl http://localhost:5000/api/scripts/{id}/versionsCurrent: No rate limiting implemented
Production Recommendation:
# Example using Flask-Limiter
@app.route('/api/scripts', methods=['POST'])
@limiter.limit("10 per minute")
def create_script():
...Current: Enabled for all origins (*)
Production Recommendation:
CORS(app, resources={
r"/api/*": {
"origins": ["https://yourdomain.com"],
"methods": ["GET", "POST", "PUT", "DELETE"],
"allow_headers": ["Content-Type"]
}
})-
Always include Content-Type header for POST/PUT
-H "Content-Type: application/json" -
Handle errors gracefully
try { const response = await fetch('/api/scripts'); if (!response.ok) throw new Error(await response.json()); } catch (error) { console.error('API error:', error); }
-
Use proper HTTP methods
- GET: Read operations
- POST: Create operations
- PUT: Update operations
- DELETE: Delete operations
-
Validate data before sending
- Check required fields
- Validate data types
- Sanitize inputs
Current: Not implemented
Future Consideration: Real-time updates for collaborative editing
API Version: 1.0
Compatibility: Stable (no breaking changes planned)
Future Versions:
- v1.1: Add pagination
- v2.0: Add authentication (breaking change)
For issues and questions:
- Check the README.md
- Review CODE_REVIEW_REPORT.md
- Consult PINE_SCRIPT_STANDARDS.md
Last Updated: January 9, 2026
Maintained By: Pine Script Library Team