Receive real-time HTTP notifications when events occur in your account
Webhooks allow your application to receive real-time notifications when certain events occur in your StockAlert.pro account. Instead of polling the API for changes, webhooks push data to your endpoint as soon as an event happens.
Tip: You can have up to 5 webhook endpoints per account, allowing you to send different events to different services.
Event | Description | Status |
---|---|---|
alert.triggered | Alert condition has been met and notification sent | Available |
alert.created | New alert created via API or dashboard | Coming Soon |
alert.updated | Alert settings changed (paused/reactivated) | Coming Soon |
alert.deleted | Alert permanently removed | Coming Soon |
Note: Additional events will be added based on user demand. Let us know which events you'd like to see!
{
"id": "evt_1234567890",
"type": "alert.triggered",
"created": "2024-01-05T10:30:00Z",
"data": {
"alert": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"symbol": "AAPL",
"company_name": "Apple Inc.",
"condition": "price_above",
"threshold": 200,
"triggered_value": 201.50,
"notification": "email",
"created_at": "2024-01-01T00:00:00Z",
"triggered_at": "2024-01-05T10:30:00Z"
},
"user": {
"id": "user_123",
"email": "user@example.com"
}
}
}
/api/public/v1/webhooks
Get a list of all configured webhooks.
{
"success": true,
"data": [
{
"id": "wh_1234567890",
"url": "https://your-app.com/webhook",
"events": ["alert.triggered"],
"is_active": true,
"created_at": "2024-01-01T00:00:00Z",
"last_success": "2024-01-05T10:00:00Z",
"last_failure": null
}
]
}
/api/public/v1/webhooks
Register a new webhook endpoint.
{
"url": "https://your-app.com/webhook",
"events": ["alert.triggered"] // Currently the only available event
}
url
- The HTTPS endpoint that will receive webhook eventsevents
- Array of event types to subscribe to/api/public/v1/webhooks/{id}
Remove a webhook endpoint.
curl -X DELETE https://stockalert.pro/api/public/v1/webhooks/wh_1234567890 \
-H "X-API-Key: sk_your_api_key"
Every webhook request includes a signature that you should verify to ensure the request came from StockAlert.pro.
X-StockAlert-Signature: sha256=a1b2c3d4e5f6...
X-StockAlert-Event: alert.triggered
X-StockAlert-Timestamp: 2024-01-05T10:30:00Z
The signature is calculated using HMAC-SHA256 with your webhook secret (found in your dashboard).
const crypto = require('crypto');
function verifyWebhookSignature(payload, signature, secret) {
const expected = crypto
.createHmac('sha256', secret)
.update(payload, 'utf8')
.digest('hex');
return signature === 'sha256=' + expected;
}
// Express.js example
app.post('/webhook', express.raw({type: 'application/json'}), (req, res) => {
const signature = req.headers['x-stockalert-signature'];
const payload = req.body;
if (!verifyWebhookSignature(payload, signature, process.env.WEBHOOK_SECRET)) {
return res.status(401).send('Invalid signature');
}
// Process webhook...
res.status(200).send('OK');
});
import hmac
import hashlib
def verify_webhook_signature(payload, signature, secret):
expected = hmac.new(
secret.encode('utf-8'),
payload.encode('utf-8'),
hashlib.sha256
).hexdigest()
return signature == f'sha256={expected}'
# Flask example
@app.route('/webhook', methods=['POST'])
def webhook():
signature = request.headers.get('X-StockAlert-Signature')
payload = request.get_data(as_text=True)
if not verify_webhook_signature(payload, signature, os.environ['WEBHOOK_SECRET']):
return 'Invalid signature', 401
# Process webhook...
return 'OK', 200
During development, you can use services like ngrok or webhook.site to test webhook deliveries:
# 1. Start your local server
npm run dev # Runs on http://localhost:3000
# 2. Expose it with ngrok
ngrok http 3000
# 3. Use the HTTPS URL from ngrok as your webhook endpoint
https://abc123.ngrok.io/api/webhook
Note: Webhook endpoints must use HTTPS. HTTP URLs will be rejected for security reasons.