Webhook API Reference
Complete reference for the TradeStaq webhook API used to trigger Signal Bot trades.
Overview
The Webhook API allows external services (like TradingView) to send trading signals to your Signal Bots.
┌──────────────┐ POST ┌──────────────┐ Execute ┌──────────────┐
│ TradingView │──────────────▶│ TradeStaq │────────────────▶│ Exchange │
│ or Script │ /webhooks │ Server │ Trade │ (API) │
└──────────────┘ └──────────────┘ └──────────────┘
Endpoint
POST https://www.tradestaq.com/api/webhooks/trade/{webhookId}
| Component | Description |
|---|---|
| Base URL | https://www.tradestaq.com |
| Path | /api/webhooks/trade/{webhookId} |
| Method | POST |
| Content-Type | application/json |
Finding Your Webhook ID
- Go to Signal Bots
- Select your bot
- Click Settings → Webhook
- Copy the webhook URL
- The ID is the last segment of the URL
Request Format
Basic Signal
{
"action": "buy",
"symbol": "BTCUSDT"
}
Full Signal (All Options)
{
"action": "buy",
"symbol": "BTCUSDT",
"price": "50000",
"size": "100%",
"leverage": "10",
"stopLoss": "48000",
"takeProfit": "55000",
"comment": "RSI oversold entry"
}
DCA Signal
{
"action": "buy",
"symbol": "BTCUSDT",
"dca": true,
"dcaLevel": 2,
"size": "25%",
"comment": "DCA Level 2 entry"
}
Request Fields
action (required)
The trading action to execute.
| Value | Aliases | Description |
|---|---|---|
buy | long | Open a long position |
sell | short | Open a short position |
close | exit, flatten | Close all positions |
close_long | exit_long | Close long positions only |
close_short | exit_short | Close short positions only |
symbol (conditional)
The trading pair symbol.
| Format | Example | Exchange |
|---|---|---|
| Without slash | BTCUSDT | All |
| With slash | BTC/USDT | All |
| Lowercase | btcusdt | All |
Note: Symbol is required for
buy/sellactions unless the bot is configured for a fixed pair.
price (optional)
Limit order price. If omitted, a market order is placed.
| Format | Example | Description |
|---|---|---|
| String number | "50000" | Exact price |
| Number | 50000 | Exact price |
size (optional)
Position size for the trade.
| Format | Example | Description |
|---|---|---|
| Percentage | "100%" | Percentage of available balance |
| Percentage | "50%" | Half of available balance |
| Fixed amount | "0.1" | Fixed base currency amount |
| Fixed amount | "1000" | Fixed amount (interpreted contextually) |
Default: Uses bot's configured position size.
leverage (optional)
Leverage for futures trading.
| Format | Example | Description |
|---|---|---|
| String number | "10" | 10x leverage |
| Number | 20 | 20x leverage |
Default: Uses bot's configured leverage.
Note: Only applies to futures exchanges. Ignored for spot trading.
stopLoss (optional)
Stop loss price.
| Format | Example | Description |
|---|---|---|
| Absolute price | "48000" | Exact stop price |
| Percentage | "2%" | 2% below entry (long) or above (short) |
takeProfit (optional)
Take profit price.
| Format | Example | Description |
|---|---|---|
| Absolute price | "55000" | Exact TP price |
| Percentage | "5%" | 5% above entry (long) or below (short) |
comment (optional)
Optional note for logging purposes.
| Format | Max Length |
|---|---|
| String | 200 characters |
DCA Fields
These fields enable Dollar Cost Averaging functionality. DCA must be enabled in bot settings before using these fields.
dca (optional)
Enable DCA for this signal.
| Value | Description |
|---|---|
true | This is a DCA entry |
false | Standard single entry (default) |
Note: DCA must be enabled in bot settings. Signals with
dca: truewill be rejected if DCA is disabled.
dcaLevel (optional)
Specify which DCA level this entry represents.
| Value | Description |
|---|---|
1 | Initial entry (same as not specifying) |
2 | Second DCA entry |
3 | Third DCA entry |
n | Nth DCA entry |
Rules:
- Levels must be sequential (can't send level 3 before level 2)
- Level 1 creates the position, levels 2+ add to it
- Cannot exceed bot's configured max levels
DCA Example Flow
// Level 1 - Initial entry
{"action": "buy", "symbol": "BTCUSDT", "dca": true, "dcaLevel": 1, "size": "25%"}
// Level 2 - Price dropped 3%, add more
{"action": "buy", "symbol": "BTCUSDT", "dca": true, "dcaLevel": 2, "size": "25%"}
// Level 3 - Price dropped 6%, add more
{"action": "buy", "symbol": "BTCUSDT", "dca": true, "dcaLevel": 3, "size": "25%"}
// Close - Exit full position
{"action": "close", "symbol": "BTCUSDT"}
DCA Error Responses
| Error Code | Description |
|---|---|
DCA_DISABLED | DCA not enabled for this bot |
DCA_MAX_LEVELS | Maximum DCA levels reached |
DCA_INVALID_LEVEL | Level out of sequence |
DCA_NO_POSITION | Cannot add DCA entry without existing position |
Response Codes
Success (200)
Signal received and queued for processing.
{
"success": true,
"message": "Signal received",
"signalId": "sig_abc123",
"timestamp": 1704067200000
}
Client Errors (4xx)
| Code | Meaning | Common Causes |
|---|---|---|
| 400 | Bad Request | Invalid JSON, missing required fields |
| 401 | Unauthorized | Invalid webhook ID |
| 403 | Forbidden | Bot paused, disabled, or deleted |
| 404 | Not Found | Webhook ID doesn't exist |
| 429 | Too Many Requests | Rate limit exceeded |
Example Error Response:
{
"success": false,
"error": "Invalid action specified",
"code": "INVALID_ACTION"
}
Server Errors (5xx)
| Code | Meaning | Action |
|---|---|---|
| 500 | Internal Error | Retry after delay |
| 502 | Bad Gateway | Retry after delay |
| 503 | Service Unavailable | Retry after delay |
TradingView Integration
Alert Message Format
In TradingView, set your alert message to JSON:
{
"action": "{{strategy.order.action}}",
"symbol": "{{ticker}}",
"price": "{{close}}"
}
Using TradingView Variables
| Variable | Description | Example |
|---|---|---|
{{strategy.order.action}} | Strategy action | buy, sell |
{{ticker}} | Symbol | BTCUSDT |
{{close}} | Current close price | 50000 |
{{open}} | Current open price | 49800 |
{{high}} | Current high price | 50100 |
{{low}} | Current low price | 49700 |
{{volume}} | Current volume | 1234.56 |
{{time}} | Candle timestamp | 2024-01-01T00:00:00Z |
{{timenow}} | Current timestamp | 2024-01-01T00:00:00Z |
Pine Script Example
//@version=5
strategy("My Strategy", overlay=true)
// Your strategy logic
longCondition = ta.crossover(ta.sma(close, 10), ta.sma(close, 20))
shortCondition = ta.crossunder(ta.sma(close, 10), ta.sma(close, 20))
if longCondition
strategy.entry("Long", strategy.long,
alert_message='{"action":"buy","symbol":"{{ticker}}","size":"100%"}')
if shortCondition
strategy.close("Long",
alert_message='{"action":"close","symbol":"{{ticker}}"}')
Setting Up the Alert
- Create alert on your strategy/indicator
- Set Webhook URL to your TradeStaq webhook URL
- Set Message to your JSON payload
- Enable the alert
Code Examples
cURL
curl -X POST https://www.tradestaq.com/api/webhooks/trade/your-webhook-id \
-H "Content-Type: application/json" \
-d '{"action":"buy","symbol":"BTCUSDT","size":"100%"}'
Python
import requests
webhook_url = "https://www.tradestaq.com/api/webhooks/trade/your-webhook-id"
signal = {
"action": "buy",
"symbol": "BTCUSDT",
"size": "100%",
"stopLoss": "2%",
"takeProfit": "4%"
}
response = requests.post(webhook_url, json=signal)
print(response.json())
JavaScript/Node.js
const axios = require('axios');
const webhookUrl = 'https://www.tradestaq.com/api/webhooks/trade/your-webhook-id';
const signal = {
action: 'buy',
symbol: 'BTCUSDT',
size: '100%',
stopLoss: '2%',
takeProfit: '4%'
openGraph: { title: 'Webhooks API', description: 'Webhook endpoint reference and payload formats.' },
};
axios.post(webhookUrl, signal)
.then(response => console.log(response.data))
.catch(error => console.error(error.response.data));
Signal Processing
Execution Flow
- Receive - Webhook receives the signal
- Validate - Check format and permissions
- Queue - Add to processing queue
- Execute - Send order to exchange
- Confirm - Return execution result
Processing Time
| Stage | Typical Time |
|---|---|
| Validation | < 50ms |
| Queue | < 100ms |
| Exchange API | 100-500ms |
| Total | 200-700ms |
Note: Actual execution time depends on exchange API latency.
Error Codes
| Code | Description | Solution |
|---|---|---|
INVALID_JSON | Malformed JSON | Check JSON syntax |
INVALID_ACTION | Unknown action | Use valid action values |
MISSING_SYMBOL | Symbol required | Include symbol field |
INVALID_SYMBOL | Unknown symbol | Check symbol format |
BOT_PAUSED | Bot is paused | Resume bot in dashboard |
BOT_DISABLED | Bot is disabled | Enable bot in dashboard |
EXCHANGE_ERROR | Exchange rejected order | Check exchange status |
INSUFFICIENT_BALANCE | Not enough funds | Deposit or reduce size |
RATE_LIMITED | Too many requests | Slow down requests |
Best Practices
Security
- Keep your webhook URL private
- Regenerate URL if compromised
- Use HTTPS only (HTTP not supported)
Reliability
- Implement retry logic for 5xx errors
- Log all signals and responses
- Monitor webhook health in dashboard
Performance
- Send only necessary fields
- Avoid duplicate signals
- Respect rate limits
Next Steps
- Authentication - API authentication methods
- Rate Limits - Understanding limits
- TradingView Integration - Detailed setup guide