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 TypeAuthenticationUse Case
Webhook APIURL-based tokenSignal bots, TradingView
Bearer JWTAuthorization: Bearer <token>MCP server, CLI tools, SDK clients
Dashboard APISession cookiesWeb dashboard
Public APINonePublic 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

MethodDescription
MCP login toolAuthenticate via the MCP server and receive a JWT
MCP authenticate toolBrowser-based OAuth flow returns a JWT
DashboardCopy your token from account settings

JWT Properties

PropertyValue
AlgorithmHS256
Expiry7 days (refreshed on activity)
ScopeFull API access for the authenticated user
RevocationChanging 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

AspectImplementation
Token FormatUUID v4 (cryptographically random)
Token Length36 characters
Entropy122 bits
StorageHashed 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:

  1. Go to Signal Bots
  2. Select the affected bot
  3. Click SettingsWebhook
  4. Click Regenerate Webhook
  5. Update the URL in TradingView/scripts
  6. 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

PropertyValue
Duration7 days (refreshed on activity)
StorageHTTP-only cookie
SecuritySecure flag, SameSite=Strict

Session Management

ActionResult
LoginNew session created
LogoutSession destroyed
InactivitySession expires after 7 days
Password changeAll sessions invalidated

Exchange API Keys

Your Exchange Credentials

When connecting exchanges, you provide API credentials:

FieldDescriptionSecurity
API KeyPublic identifierEncrypted at rest
API SecretPrivate keyEncrypted at rest
PassphraseAdditional 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:

PermissionSignal BotsTrading BotsRequired
ReadYes
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:

ExchangeIP Whitelist Support
Binance✓ Supported
ByBit✓ Supported
OKX✓ Supported
Bitget✓ Supported

Contact support for current IP addresses to whitelist.

Security Best Practices

For Webhooks

PracticeImplementation
Keep URL privateDon't share publicly
Regenerate if exposedUse regenerate feature
Monitor activityCheck webhook health
Use HTTPS onlyHTTP is rejected

For Exchange Keys

PracticeImplementation
Minimal permissionsOnly enable trading
No withdrawalNever enable withdraw
IP whitelistRestrict to TradeStaq IPs
Regular rotationRegenerate keys periodically
Separate keysDifferent keys per service

For Your Account

PracticeImplementation
Strong password16+ characters, unique
Email securitySecure your email account
Session awarenessLog out on shared devices
Monitor activityReview login history

Error Responses

Authentication Errors

CodeErrorMeaning
401INVALID_WEBHOOKWebhook ID not found
401WEBHOOK_DISABLEDWebhook has been disabled
403BOT_PAUSEDBot is paused
403BOT_DELETEDBot has been deleted
403EXCHANGE_DISCONNECTEDExchange 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:

  1. Verify URL in bot settings
  2. Copy URL fresh from dashboard
  3. Update in TradingView/scripts

"Bot Paused"

Causes:

  • Manually paused bot
  • Auto-paused due to errors
  • Subscription downgrade

Solution:

  1. Check bot status in dashboard
  2. Resume if manually paused
  3. Check subscription status

"Exchange Disconnected"

Causes:

  • API key expired
  • API key deleted on exchange
  • Exchange maintenance

Solution:

  1. Verify exchange status in dashboard
  2. Reconnect exchange if needed
  3. Check exchange status page

Next Steps