API Authentication
Learn about TradeStaq's authentication methods for API access and webhook security.
Authentication Methods
TradeStaq uses different authentication methods depending on the API type:
| API Type | Authentication | Use Case |
|---|---|---|
| Webhook API | URL-based token | Signal bots, TradingView |
| Bearer JWT | Authorization: Bearer <token> | MCP server, CLI tools, SDK clients |
| Dashboard API | Session cookies | Web dashboard |
| Public API | None | Public data |
Bearer JWT Authentication
For programmatic access from MCP clients, CLI tools, or custom SDK integrations, TradeStaq supports standard Bearer token authentication using JWTs.
How It Works
Include your JWT in the Authorization header of every API request:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Obtaining a JWT
| Method | Description |
|---|---|
MCP login tool | Authenticate via the MCP server and receive a JWT |
MCP authenticate tool | Browser-based OAuth flow returns a JWT |
| Dashboard | Copy your token from account settings |
JWT Properties
| Property | Value |
|---|---|
| Algorithm | HS256 |
| Expiry | 7 days (refreshed on activity) |
| Scope | Full API access for the authenticated user |
| Revocation | Changing your password invalidates all tokens |
Example Request
curl -X GET https://www.tradestaq.com/api/user/portfolio \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
When to Use Bearer JWT
- MCP server — the MCP server stores and sends the JWT automatically after login
- Custom scripts — any HTTP client that needs to call TradeStaq APIs
- CI/CD pipelines — automated trading or monitoring workflows
For more on MCP authentication, see the MCP Authentication guide.
Webhook Authentication
URL-Based Tokens
Webhook URLs contain an embedded authentication token:
https://www.tradestaq.com/api/webhooks/trade/{webhookId}
↑
This IS your token
Security Model
| Aspect | Implementation |
|---|---|
| Token Format | UUID v4 (cryptographically random) |
| Token Length | 36 characters |
| Entropy | 122 bits |
| Storage | Hashed in database |
Webhook ID Properties
- Unique per bot - Each Signal Bot has its own webhook ID
- Non-guessable - Randomly generated, not sequential
- Revocable - Can be regenerated at any time
- Scoped - Only works for the associated bot
Protecting Your Webhook
Keep It Secret
Your webhook URL is essentially a password. Anyone with the URL can:
- Send trading signals to your bot
- Trigger trades on your exchange
- Potentially drain your account
Never share:
- In public forums
- In screenshots
- In public code repositories
- With untrusted parties
Regenerating Webhook ID
If your webhook URL is compromised:
- Go to Signal Bots
- Select the affected bot
- Click Settings → Webhook
- Click Regenerate Webhook
- Update the URL in TradingView/scripts
- Old URL immediately stops working
IP Restrictions (Future)
Coming Soon: Ability to whitelist IP addresses for webhook access.
Session Authentication
How Sessions Work
The dashboard uses secure session-based authentication:
┌──────────┐ Login ┌──────────┐ Cookie ┌──────────┐
│ User │───────────▶│ Server │────────────▶│ Browser │
│ │◀───────────│ │◀────────────│ │
└──────────┘ Session └──────────┘ Requests └──────────┘
Session Properties
| Property | Value |
|---|---|
| Duration | 7 days (refreshed on activity) |
| Storage | HTTP-only cookie |
| Security | Secure flag, SameSite=Strict |
Session Management
| Action | Result |
|---|---|
| Login | New session created |
| Logout | Session destroyed |
| Inactivity | Session expires after 7 days |
| Password change | All sessions invalidated |
Exchange API Keys
Your Exchange Credentials
When connecting exchanges, you provide API credentials:
| Field | Description | Security |
|---|---|---|
| API Key | Public identifier | Encrypted at rest |
| API Secret | Private key | Encrypted at rest |
| Passphrase | Additional auth (some exchanges) | Encrypted at rest |
Encryption
Exchange credentials are protected with:
- AES-256 encryption at rest
- TLS 1.3 in transit
- Hardware Security Module for key management
- Zero-knowledge design (we can't see your keys)
Recommended API Permissions
Only enable what's needed:
| Permission | Signal Bots | Trading Bots | Required |
|---|---|---|---|
| Read | ✓ | ✓ | Yes |
| Spot Trading | ✓ (if spot) | ✓ (if spot) | Conditional |
| Futures Trading | ✓ (if futures) | ✓ (if futures) | Conditional |
| Withdraw | - | - | Never |
| Transfer | - | - | Never |
Important: Never enable withdrawal permissions. TradeStaq never needs them.
IP Whitelisting
For maximum security, whitelist TradeStaq's IP addresses on your exchange:
| Exchange | IP Whitelist Support |
|---|---|
| Binance | ✓ Supported |
| ByBit | ✓ Supported |
| OKX | ✓ Supported |
| Bitget | ✓ Supported |
Contact support for current IP addresses to whitelist.
Security Best Practices
For Webhooks
| Practice | Implementation |
|---|---|
| Keep URL private | Don't share publicly |
| Regenerate if exposed | Use regenerate feature |
| Monitor activity | Check webhook health |
| Use HTTPS only | HTTP is rejected |
For Exchange Keys
| Practice | Implementation |
|---|---|
| Minimal permissions | Only enable trading |
| No withdrawal | Never enable withdraw |
| IP whitelist | Restrict to TradeStaq IPs |
| Regular rotation | Regenerate keys periodically |
| Separate keys | Different keys per service |
For Your Account
| Practice | Implementation |
|---|---|
| Strong password | 16+ characters, unique |
| Email security | Secure your email account |
| Session awareness | Log out on shared devices |
| Monitor activity | Review login history |
Error Responses
Authentication Errors
| Code | Error | Meaning |
|---|---|---|
| 401 | INVALID_WEBHOOK | Webhook ID not found |
| 401 | WEBHOOK_DISABLED | Webhook has been disabled |
| 403 | BOT_PAUSED | Bot is paused |
| 403 | BOT_DELETED | Bot has been deleted |
| 403 | EXCHANGE_DISCONNECTED | Exchange not connected |
Example Error Response
{
"success": false,
"error": "Invalid webhook ID",
"code": "INVALID_WEBHOOK",
"timestamp": 1704067200000
}
Troubleshooting
"Invalid Webhook ID"
Causes:
- Typo in webhook URL
- Webhook was regenerated
- Bot was deleted
Solution:
- Verify URL in bot settings
- Copy URL fresh from dashboard
- Update in TradingView/scripts
"Bot Paused"
Causes:
- Manually paused bot
- Auto-paused due to errors
- Subscription downgrade
Solution:
- Check bot status in dashboard
- Resume if manually paused
- Check subscription status
"Exchange Disconnected"
Causes:
- API key expired
- API key deleted on exchange
- Exchange maintenance
Solution:
- Verify exchange status in dashboard
- Reconnect exchange if needed
- Check exchange status page
Next Steps
- Webhook API - Complete webhook reference
- Rate Limits - API rate limits
- Exchange API Permissions - Permission guide