The price alert system monitors cryptocurrency prices and automatically sends push notifications to all users when significant price changes occur (5% or more). It also allows sending custom announcements and market updates.
- Go to your OneSignal dashboard: https://onesignal.com/
- Select your app (nexa-prime)
- Go to Settings → Keys & IDs
- Copy the REST API Key (not the App ID)
Replace YOUR_ONESIGNAL_REST_API_KEY in lib/services/price_alert_service.dart:
static const String _oneSignalRestApiKey = "YOUR_ACTUAL_REST_API_KEY_HERE";- Monitors 10 major cryptocurrencies: BTC, ETH, USDT, BNB, SOL, ADA, XRP, DOGE, MATIC, TRX
- Checks prices every 30 minutes
- Sends alerts when price changes ≥5%
- 1-hour cooldown between alerts for the same token
- Smart emoji indicators (📈 for increases, 📉 for decreases)
- Send custom notifications to all users
- Market updates with additional data
- Accessible from Settings → Send Custom Announcement
- Toggle price monitoring on/off in Settings
- "Auto Price Monitoring" switch
- Real-time monitoring status
App Launch → Start Price Monitoring → Check Prices Every 30min →
Compare with Previous → Send Alert if ≥5% change → Update Previous Price
- Price Alerts: Automatic notifications for significant price changes
- Custom Announcements: Manual notifications from app admin
- Market Updates: Market-related notifications with additional data
📈 BTC Price Alert
Bitcoin has increased by 7.2% to $45,230.50
📉 ETH Price Alert
Ethereum has decreased by 5.8% to $2,890.25
🔔 Market Update
New DeFi protocol launched on Ethereum network
// Minimum percentage change to trigger alert
static const double _minPercentageChange = 5.0; // 5%
// Cooldown between alerts for same token
static const Duration _alertCooldown = Duration(hours: 1);
// Price check interval (in Timer.periodic)
Duration(minutes: 30) // Check every 30 minutes
// Tokens to monitor
static const List<String> _tokensToMonitor = [
'BTC', 'ETH', 'USDT', 'BNB', 'SOL', 'ADA', 'XRP', 'DOGE', 'MATIC', 'TRX'
];await PriceAlertService.sendCustomAnnouncement(
title: "🚀 New Feature Available",
message: "Staking rewards are now live! Earn up to 12% APY on your crypto holdings.",
type: "feature_announcement",
);await PriceAlertService.sendMarketUpdate(
title: "📊 Market Analysis",
message: "Bitcoin breaks $50K resistance level with strong volume",
marketData: {
'symbol': 'BTC',
'price': 50000,
'volume': '2.5B',
'change_24h': 8.5
},
);-
Notifications not sending
- Check OneSignal REST API key is correct
- Verify app is connected to internet
- Check OneSignal dashboard for delivery status
-
Price monitoring not working
- Ensure CoinAPI key is valid in
price_service.dart - Check network connectivity
- Verify timer is running (check logs)
- Ensure CoinAPI key is valid in
-
Users not receiving notifications
- Ensure users have granted notification permissions
- Check if users are subscribed to OneSignal
- Verify OneSignal player IDs are being sent to backend
Enable debug mode to see detailed logs:
if (kDebugMode) {
print('Price monitoring logs will appear here');
}- API Key Security: Store OneSignal REST API key securely
- Rate Limiting: Implement rate limiting for manual announcements
- User Permissions: Respect user notification preferences
- Data Privacy: Don't include sensitive user data in notifications
- Price monitoring runs in background
- Minimal battery impact (30-minute intervals)
- Efficient API usage with error handling
- Automatic cleanup on app termination
- Temporarily reduce
_minPercentageChangeto 1% - Reduce
_alertCooldownto 1 minute - Monitor logs for price changes
- Verify notifications appear in OneSignal dashboard
- Go to Settings → Send Custom Announcement
- Enter title and message
- Send notification
- Check OneSignal dashboard for delivery status
- Replace the REST API key in the code
- Test the functionality with a small percentage change
- Monitor OneSignal dashboard for delivery statistics
- Customize notification content as needed
- Add user preferences for notification types (optional)
The system is now ready to automatically monitor prices and send notifications to all your users! 🚀