Skip to main content

Authentication Parameters

Authentication parameters identify your strategy and user account when sending signals to OptAlgo.

strategy_key ⚠️​

  • Type: string
  • Required: Yes (Critical)
  • Description: Encrypted authentication key that identifies your strategy and user account

Details​

The strategy_key is the only required parameter for all signals. This encrypted key contains your user_id and strategy_id, which OptAlgo uses to:

  • Authenticate your request
  • Route the signal to the correct strategy
  • Apply your strategy's configuration
  • Execute trades on your connected exchange

How to Get Your Strategy Key​

  1. Log in to the OptAlgo Dashboard
  2. Navigate to your strategies
  3. Create a new strategy or select an existing one
  4. Copy the strategy key from the strategy settings page
  5. Use this key in all signals for that strategy

Security​

  • The strategy key is a signed token and is verified on the server
  • Invalid or missing keys result in a 400 Bad Request error
  • Never share your strategy key publicly
  • Each bot has its own key
  • The key does not expire. It stays valid for as long as the bot exists, and a key cannot be revoked on its own. If a key leaks, stop the bot right away, then delete it and create a new one. A deleted bot's key is rejected (Strategy not found).

Example Usage​

{
"strategy_key": "your_strategy_key_here",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"position_side": "LONG",
"action": "BUY",
"leverage": 5
}

Error Messages​

ErrorCauseSolution
"Strategy key is empty"Missing strategy_key parameterAdd strategy_key to your signal JSON
"Invalid strategy key"Incorrect or corrupted keyCopy the strategy key again from dashboard
"Strategy not found"Strategy was deletedCreate a new strategy and use its key

strategy_id​

  • Type: string
  • Required: No (automatically extracted)
  • Description: Internal strategy identifier

Details​

The strategy_id is automatically extracted from your strategy_key during signal processing. You don't need to include it in your signals.

Internal Use​

OptAlgo uses the strategy_id to:

  • Fetch strategy configuration (symbol, exchange, allocation)
  • Check if the strategy is active
  • Apply strategy-specific settings
  • Track trades and positions

Example​

When you send a signal with strategy_key, OptAlgo automatically:

  1. Decrypts the strategy key
  2. Extracts user_id and strategy_id
  3. Validates the strategy exists and is active
  4. Processes the signal with strategy configuration

You'll see strategy_id in logs and error messages, but you never need to manually include it in signals.


Best Practices​

1. Store Strategy Keys Securely​

// ✅ Good: Environment variable
const STRATEGY_KEY = process.env.OPTALGO_STRATEGY_KEY;

// ❌ Bad: Hardcoded in public code
const STRATEGY_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";

2. Use Different Keys for Different Strategies​

// Strategy 1: BTC Long-term
{
"strategy_key": "strategy_1_key_here",
"ticker": "BTCUSDT.P"
}

// Strategy 2: ETH Day Trading
{
"strategy_key": "strategy_2_key_here",
"ticker": "ETHUSDT.P"
}

3. Always Include Strategy Key​

Every signal must include the strategy_key, even for simple operations:

// Closing a position still requires strategy_key (and exchange + ticker)
{
"strategy_key": "your_key_here",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"position_side": "CLOSE"
}

4. TradingView Integration​

TradingView has no placeholder for your strategy key: paste the key itself into the alert message. ({{strategy_key}} would be sent as literal text and rejected.)

{
"strategy_key": "PASTE_YOUR_STRATEGY_KEY",
"exchange": "BINANCE",
"ticker": "{{ticker}}",
"position_side": "LONG",
"action": "BUY",
"leverage": 5,
"entry_price": {{close}}
}

Next Steps​