Skip to main content

Overview

API key trading allows you to execute trades on behalf of your main wallet using a separate API key wallet. This keeps your main wallet’s private key secure while enabling programmatic trading with bots and automated systems.

Security

Your main wallet’s private key stays offline and secure. Only the API key is exposed to your trading bot.

Multiple Keys

Create multiple API keys for different bots or trading strategies while keeping your main wallet secure.

Easy Rotation

If an API key is compromised, simply revoke it and create a new one without affecting your main wallet.

Team Collaboration

Share API keys with team members or services without sharing your main wallet credentials.

How API Keys Work

Key Concepts:
  • Main Wallet: Holds your funds and positions (private key stays secure)
  • API Key Wallet: Signs transactions on behalf of main wallet
  • Authenticator: On-chain permission that links API key to main wallet
  • Subaccount: The trading account where positions are held

Setting Up API Key Trading

1

Create API Key in Web Interface

Go to the LFG web interface to create your API key:
  1. Visit https://lfg.land
  2. Connect your main wallet
  3. Navigate to SettingsAPI Keys
  4. Click Create New API Key
  5. Download and save the private key - it will only be shown once
  6. Note the authenticator ID displayed
Save the private key immediately! You won’t be able to view it again. Store it securely - this key will be used by your trading bot.
API keys have trading permissions only - they can place and cancel orders but cannot withdraw funds from your account.
2

Configure Your Bot

Use the private key from the website in your trading bot:
Store the private key in environment variables, never hardcode it in your source code.
3

Get Authenticator ID

The authenticator ID is shown in the web interface when you create the API key. You can also retrieve it programmatically:

Configure Your Trading Bot

Set up your bot with the API key configuration:

Placing Orders with API Keys

Complete Example

Here’s a complete example of placing an order using an API key:

Key Differences from Regular Trading

The main difference when using API keys is creating the subaccount:

Security Best Practices

Never hardcode API keys:
Use .env files (add to .gitignore):
Regularly rotate your API keys:
  1. Generate new API key
  2. Register new key in web interface
  3. Update bot configuration
  4. Test with small orders
  5. Revoke old key
Rotation Schedule:
  • High-value accounts: Monthly
  • Production bots: Quarterly
  • Development: After major changes
API keys have trading-only permissions by design:
  • Can do: Place and cancel orders
  • Cannot do: Withdraw funds from your account
  • Best practice: Create separate API keys for different bots or strategies
This built-in limitation minimizes damage if a key is compromised.
Regularly audit API key usage:

Environment Configuration

Production Setup

.env.production

Development Setup

.env.development
API keys only have trading permissions. For withdrawals or other sensitive operations, you must use your main wallet directly.

Troubleshooting

Problem: Error finding authenticator for API keySolutions:
  1. Verify API key is registered in web interface
  2. Check authenticator ID is correct
  3. Ensure API key wallet matches registered public key
  4. Wait a few blocks after registration
Problem: Transaction rejected due to insufficient permissionsSolutions:
  1. Verify the API key is properly registered
  2. Ensure authenticator is active (not revoked)
  3. Check that you’re using the correct authenticator ID
  4. Re-register API key if needed
API keys only have trading permissions. If you need to withdraw funds, use your main wallet directly.
Problem: Order placed in wrong subaccountSolution: Verify subaccount number in SubaccountInfo:

Advanced: Finding the Correct Authenticator

If you have multiple API keys, you need to find the right authenticator:

Next Steps

Order Management

Learn more about placing and managing orders

Security Guide

Comprehensive security best practices

Wallet Management

Understand subaccounts and permissions

Error Handling

Handle common errors and edge cases
Always test API key trading on staging network before using on mainnet with real funds!