已完成美股和港股IPO数据源的自动同步系统集成,支持从 Finnhub API 获取美股IPO数据,从 HKEX FINI API 获取港股IPO数据,并自动插入到数据库中。
This implementation provides automated IPO data synchronization from two major sources:
- Finnhub API: US market IPO data
- HKEX FINI API: Hong Kong market IPO data
-
Finnhub API (US Market)
- Real-time IPO calendar data
- 60 API calls per minute (free tier)
- Price ranges, share offerings, and listing dates
- Automatic status mapping
-
HKEX FINI API (Hong Kong Market)
- Digital IPO settlement platform
- T+2 settlement timeline
- OAuth2 authentication
- End-to-end settlement process data
- Intelligent Deduplication: Prevents duplicate entries based on symbol+market
- Data Validation: Comprehensive validation before database insertion
- Rate Limiting: Built-in rate limiting for API calls
- Error Handling: Robust error handling with detailed logging
- Incremental Updates: Only updates records when data has actually changed
src/
├── lib/
│ ├── external-apis.ts # API service classes and data transformers
│ └── data-sync.ts # Main synchronization service
├── app/api/sync/
│ ├── route.ts # General sync endpoints
│ ├── finnhub/route.ts # US market specific endpoints
│ ├── hkex/route.ts # HK market specific endpoints
│ └── scheduled/route.ts # Scheduled sync endpoint
├── app/sync/
│ └── page.tsx # Data sync management page
└── components/
└── DataSyncManager.tsx # Frontend sync management component
GET /api/sync- Get synchronization statusPOST /api/sync- Trigger full sync (both markets)POST /api/sync/finnhub- Sync US IPOs onlyPOST /api/sync/hkex- Sync Hong Kong IPOs onlyPOST /api/sync/scheduled- Endpoint for scheduled tasks
{
"success": true,
"data": {
"us": {
"success": true,
"processed": 25,
"added": 5,
"updated": 3,
"skipped": 17,
"errors": []
},
"hk": {
"success": true,
"processed": 12,
"added": 2,
"updated": 1,
"skipped": 9,
"errors": []
}
},
"message": "Data synchronization completed",
"timestamp": "2025-08-23T02:45:00.000Z"
}Add these to your .env file:
# Finnhub API Configuration
FINNHUB_API_KEY="your-finnhub-api-key"
FINNHUB_BASE_URL="https://finnhub.io/api/v1"
# HKEX FINI API Configuration
HKEX_FINI_CLIENT_ID="your-hkex-client-id"
HKEX_FINI_CLIENT_SECRET="your-hkex-client-secret"
HKEX_FINI_BASE_URL="https://api.hkex.com.hk/fini"
# Scheduled Tasks Security
CRON_SECRET_TOKEN="your-secret-cron-token"- Visit finnhub.io
- Create a free account
- Get your API key from the dashboard
- Free tier: 60 calls/minute, sufficient for IPO calendar data
- Visit HKEX FINI Platform
- Complete registration process
- Obtain client credentials (requires business registration)
- Download API documentation from HKEX website
{
symbol: finnhubData.symbol,
companyName: finnhubData.name,
market: 'US',
expectedPrice: parsedPrice,
priceRange: finnhubData.price,
sharesOffered: finnhubData.numberOfShares,
ipoDate: new Date(finnhubData.date),
status: mapFinnhubStatus(finnhubData.status)
}{
symbol: hkexData.symbol,
companyName: hkexData.companyName,
market: 'HK',
expectedPrice: hkexData.offerPrice,
sharesOffered: hkexData.sharesOffered,
ipoDate: new Date(hkexData.listingDate),
status: mapHkexStatus(hkexData.status),
sector: hkexData.sector
}- Use the web interface at
/sync - Call API endpoints directly
- Trigger via curl or external scripts
# Daily sync at 9 AM
0 9 * * * curl -X POST \
-H "Authorization: Bearer YOUR_CRON_TOKEN" \
http://localhost:3000/api/sync/scheduled
# US market sync every 4 hours during weekdays
0 */4 * * 1-5 curl -X POST \
-H "Authorization: Bearer YOUR_CRON_TOKEN" \
http://localhost:3000/api/sync/finnhub- Vercel: Use Vercel Cron Jobs
- Netlify: Use Netlify Scheduled Functions
- AWS: Use EventBridge with Lambda
- Railway: Use Railway Cron
- Heroku: Use Heroku Scheduler
// Trigger full sync
const response = await fetch('/api/sync', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});
// Sync specific market
const usSync = await fetch('/api/sync/finnhub', {
method: 'POST'
});# Get sync status
curl http://localhost:3000/api/sync
# Trigger US IPO sync
curl -X POST http://localhost:3000/api/sync/finnhub
# Trigger HK IPO sync
curl -X POST http://localhost:3000/api/sync/hkex- API Authentication: Bearer tokens for scheduled endpoints
- Rate Limiting: Built-in protection against API abuse
- Input Validation: All external data validated before database insertion
- Error Boundaries: Graceful handling of API failures
- Logging: Comprehensive logging for debugging and monitoring
- View sync history in the web interface
- Check API endpoint responses
- Monitor database record counts
- Review error logs
- API Key Issues: Check environment variables
- Rate Limits: Monitor API call frequency
- Network Issues: Check API endpoint availability
- Data Validation: Review error logs for validation failures
- Real-time Webhooks: Immediate updates when new IPOs are announced
- Email Notifications: Alert users about new IPO listings
- Data Analytics: Advanced metrics and reporting
- Mobile App: React Native or Flutter integration
- AI Insights: ML-powered IPO performance predictions
- Database Optimization: Indexing for large datasets
- Caching: Redis for frequently accessed data
- Load Balancing: Multiple API instances
- Microservices: Separate sync services
- Regular data validation checks
- Monitoring for stale data
- Cross-validation between sources
- Manual review for significant discrepancies
- Batch processing for large datasets
- Async processing for non-blocking operations
- Database connection pooling
- API response caching
- Retry logic for failed API calls
- Backup data sources
- Regular health checks
- Monitoring and alerting
The IPO data integration system is now fully functional with:
✅ Finnhub API Integration - US market IPO data
✅ HKEX FINI API Integration - Hong Kong market IPO data
✅ Automated Synchronization - Smart deduplication and updates
✅ Web Interface - Easy management and monitoring
✅ API Endpoints - Programmatic access and control
✅ Scheduled Tasks - Automated daily updates
✅ Comprehensive Documentation - Setup and usage guides
Ready for production deployment and can be extended with additional features as needed!