Webhook Setup
Webhooks are HTTP endpoints that receive trading signals from external sources. This guide covers everything you need to know about setting up and using webhooks.
Understanding Webhooks
A webhook is a URL that accepts incoming HTTP requests. When your signal source (TradingView, custom script, etc.) sends a request to this URL, TradeStaq processes the signal and executes the trade.
Your Signal Source → HTTP POST → Webhook URL → TradeStaq → Exchange
Your Webhook URL
Each Signal Bot has a unique webhook URL:
https://www.tradestaq.com/api/webhooks/trade/{webhookId}
Finding Your Webhook URL
- Go to Dashboard → Signal Bots
- Click on your bot
- Navigate to the Webhook tab
- Click Copy to copy the URL
Note: Keep your webhook URL private. Anyone with this URL can send signals to your bot.
Signal Templates
Minimum Required (2 fields)
The simplest signal that will work. Uses your bot's configured position size and executes at market price.
{
"ticker": "BTCUSDT",
"position": "long"
}
Recommended
Includes the current price to speed up position size calculations (reduces API calls).
{
"ticker": "BTCUSDT",
"position": "long",
"marketPrice": "97500",
"comment": "RSI oversold entry"
}
Full Control
Override all settings per signal for maximum control.
{
"ticker": "BTCUSDT",
"position": "long",
"size": "0.1",
"marketPrice": "97500",
"tp": "100000",
"sl": "95000",
"leverage": "10",
"comment": "Manual entry",
"exchange": "binance"
}
Field Reference
Required Fields
These fields must be present in every signal.
| Field | Type | Description | Example |
|---|---|---|---|
ticker | string | Trading symbol. Automatically normalized for your exchange. | "BTCUSDT", "BTC/USDT" |
position | string | Trade direction: long (buy), short (sell), or flat (close). Alias: action | "long" |
Optional Fields
These fields customize the trade execution. If omitted, bot settings are used.
| Field | Type | Description | Default |
|---|---|---|---|
action | string | Alias for position. Trade action: buy or sell | - |
size | string/number | Position size (contracts or amount) | Bot's configured size |
price | string/number | Limit order price (omit for market order) | Market order |
marketPrice | string/number | Current market price for sizing calculations | Fetched from exchange |
tp | string/number | Take profit price | None |
sl | string/number | Stop loss price | None |
leverage | string/number | Leverage multiplier | Bot's configured leverage |
comment | string | Note displayed in Telegram notifications | Empty |
exchange | string | Target specific exchange by name or label | All bot exchanges |
timeframe | string | Chart timeframe for validation | No validation |
strategy | string | Strategy name for notification subject & logs | None |
Detailed Field Descriptions
ticker (Required)
The trading symbol for the pair you want to trade.
Accepted formats:
BTCUSDT- Simple formatBTC/USDT- With slash separatorBTC-USDT- With dash separator (auto-converted)
The system automatically normalizes the symbol for your exchange. For example, BTC/USDT becomes BTC/USDT:USDT for futures on most exchanges.
position or action (Required)
Determines the trade action to execute. You can use either position or action as the field name - they work identically.
| Value | Action |
|---|---|
long | Open a long position (buy) |
short | Open a short position (sell) |
flat | Close any open position |
buy | Alias for long |
sell | Alias for short |
close | Alias for flat |
TradingView Tip: Use
{{strategy.market_position}}(outputslong,short,flat) with thepositionfield, or use{{strategy.order.action}}(outputsbuy,sell) with theactionfield.
size (Optional)
Override the bot's configured position size for this specific trade.
Examples:
"0.1"- Trade 0.1 contracts/coins"100"- Trade 100 units"10%"- Trade 10% of available balance (if supported)
If omitted, the bot uses its configured position sizing (percentage of balance or fixed amount).
marketPrice (Optional)
The current market price of the asset. Used internally for:
- Calculating position size when using percentage-based sizing
- Reducing API calls to the exchange
Important: This is different from price (which would trigger a limit order). marketPrice is purely informational for calculations.
tp (Optional)
Take profit price. When set, a take profit order is placed after the entry is filled.
Example: If entering long at $97,500, setting "tp": "100000" places a sell limit at $100,000.
sl (Optional)
Stop loss price. When set, a stop loss order is placed after the entry is filled.
Example: If entering long at $97,500, setting "sl": "95000" places a stop market at $95,000.
leverage (Optional)
Override the leverage for this trade. Only applies to futures/margin trading.
Example: "leverage": "10" sets 10x leverage for this position.
comment (Optional)
A custom note that appears in Telegram notifications. Useful for identifying why a trade was taken.
Examples:
"RSI oversold bounce""TP1 hit""Stop loss triggered"
exchange (Optional)
Target a specific exchange when your bot has multiple exchanges connected.
Matching rules:
- Matches by exchange name:
"binance","bybit" - Matches by account label:
"Main Account","DCA Account" - Case-insensitive partial matching
If omitted, the signal executes on all connected exchanges.
timeframe (Optional)
The chart timeframe the signal came from. Used for timeframe validation if enabled in your subscription tier.
Examples: "1" (1 minute), "60" (1 hour), "D" (daily)
action (Optional)
An alias for position. Use this with TradingView's {{strategy.order.action}} placeholder which outputs buy or sell.
Value mapping:
buy→ Opens a long position (same aslong)sell→ Opens a short position (same asshort)
Note: If both
positionandactionare provided,positiontakes precedence.
strategy (Optional)
The strategy name that generated this signal. Displayed in notification subjects and activity logs.
Use cases:
- Identifying signal source in Telegram notifications
- Filtering and organizing signals in activity logs
- Tracking performance by strategy name
Example: "strategy": "RSI Scalper" or "strategy": "Golden Cross Bot"
price (Optional)
Set a specific price to place a limit order instead of a market order. When omitted, a market order is placed.
Example: "price": "95000" places a limit order at $95,000 instead of executing at market price.
Note: Limit orders may not fill immediately or at all if the price doesn't reach your specified level.
Position Values Explained
| Position | What Happens |
|---|---|
long | Opens a long position. If already short, closes short first then opens long. |
short | Opens a short position. If already long, closes long first then opens short. |
flat | Closes any open position without opening a new one. |
Sending Signals
Using cURL
curl -X POST https://www.tradestaq.com/api/webhooks/trade/YOUR_WEBHOOK_ID \
-H "Content-Type: application/json" \
-d '{"ticker": "BTCUSDT", "position": "long"}'
Using Python
import requests
webhook_url = "https://www.tradestaq.com/api/webhooks/trade/YOUR_WEBHOOK_ID"
signal = {
"ticker": "BTCUSDT",
"position": "long",
"marketPrice": "97500",
"comment": "Python script entry"
}
response = requests.post(webhook_url, json=signal)
print(response.json())
Using JavaScript
const webhookUrl = "https://www.tradestaq.com/api/webhooks/trade/YOUR_WEBHOOK_ID";
const signal = {
ticker: "BTCUSDT",
position: "long",
marketPrice: "97500",
comment: "JS entry"
openGraph: { title: 'Webhook Setup', description: 'How to configure webhooks for signal bot triggers on TradeStaq.' },
};
fetch(webhookUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(signal)
})
.then(res => res.json())
.then(data => console.log(data));
Response Codes
| Code | Meaning |
|---|---|
200 | Signal received and queued for execution |
400 | Invalid payload (check JSON format) |
401 | Invalid webhook ID |
403 | Bot is paused or inactive |
429 | Rate limit exceeded |
500 | Server error |
Success Response
{
"success": true,
"message": "Signal received",
"signalId": "abc123"
}
Error Response
{
"success": false,
"error": "Invalid action specified",
"code": "INVALID_ACTION"
}
Rate Limits
To prevent abuse, webhooks have rate limits:
| Limit Type | Value |
|---|---|
| Per minute | 60 requests |
| Burst | 10 requests/second |
Note: If you hit rate limits, your signals will be rejected. Reduce signal frequency or contact support for higher limits.
Testing Your Webhook
Built-in Test Tool
- Go to your bot's detail page
- Navigate to the Webhook tab
- Your webhook URL is displayed with a copy button
- Use the Signal Logs tab to verify signals are received
Manual Testing
Test with cURL before connecting your actual signal source:
# Test long signal
curl -X POST YOUR_WEBHOOK_URL \
-H "Content-Type: application/json" \
-d '{"ticker": "BTCUSDT", "position": "long"}'
# Test close signal
curl -X POST YOUR_WEBHOOK_URL \
-H "Content-Type: application/json" \
-d '{"ticker": "BTCUSDT", "position": "flat"}'
Webhook Health Monitoring
The bot card shows webhook health based on signal activity:
| Status | Indicator | Meaning |
|---|---|---|
| Healthy | 🟢 | Signal received in last 24h |
| Warning | 🟡 | No signal in 24-48h |
| Stale | 🔴 | No signal in 48+ hours |
| New | ⚪ | Never received a signal |
Note: Monitor webhook health to ensure your signals are being received. A stale webhook may indicate an issue with your signal source.
Common Issues
"Invalid JSON"
Problem: Malformed JSON in request body
Solution: Validate your JSON at jsonlint.com
// Wrong - missing quotes
{ticker: BTCUSDT}
// Correct
{"ticker": "BTCUSDT", "position": "long"}
"Missing ticker or position"
Problem: Required fields not present
Solution: Ensure both ticker and position fields are included
"Bot Not Active"
Problem: Signal sent to paused/stopped bot
Solution: Activate the bot before sending signals
"Rate Limit Exceeded"
Problem: Too many signals in short period
Solution: Reduce signal frequency, implement backoff
Security Best Practices
1. Keep URL Private
- Never share your webhook URL publicly
- Don't commit it to public repositories
- Use environment variables in code
2. Regenerate If Compromised
If your webhook URL is exposed:
- Delete the bot
- Create a new bot
- Update your signal source with new URL
3. Monitor Activity
- Check activity logs regularly
- Set up Telegram alerts for trade notifications
- Review webhook health indicators