Lightning API
The Lightning API is our HTTPS-based trading API designed for quick integration. Send a request and we handle everything: transaction building, signing, and broadcasting.
Overview
Base URL: https://api.turnpike.dev
Authentication: Bearer token in Authorization header
Rate Limits:
Standard: 100 requests/minute
Premium: 1,000 requests/minute
Endpoints
Buy Token
Execute a buy order for a specific token.
Endpoint: POST /trade/buy
Request Body:
publicKey
string
Yes
Your Solana wallet public key (base58 format)
mint
string
Yes
Token mint address to purchase
amount
number
Yes
Amount of SOL to spend (min: 0.001, max: 100)
slippage
number
No
Maximum slippage percentage (default: 10, range: 0.1-50)
priorityFee
number
No
Priority fee in SOL (default: auto, range: 0.00001-0.01)
Example Request:
Success Response (200):
Sell Token
Execute a sell order for tokens you own. Supports both token amount and percentage-based selling.
Endpoint: POST /trade/sell
Request Body:
publicKey
string
Yes
Your Solana wallet public key
mint
string
Yes
Token mint address to sell
amount
number | string
Yes
Token amount to sell or percentage ("50%", "100%")
slippage
number
No
Maximum slippage percentage (default: 10)
priorityFee
number
No
Priority fee in SOL (default: auto)
sellAll
boolean
No
If true, sells entire balance (default: false)
Example Request:
Success Response (200):
Get Token Info
Retrieve detailed information about a specific token.
Endpoint: GET /token/info/{mint}
Parameters:
mint
string
Yes
Token mint address (path parameter)
Example Request:
Success Response (200):
Get Portfolio
Get all token holdings for a specific wallet address.
Endpoint: GET /portfolio/{publicKey}
Parameters:
publicKey
string
Yes
Wallet public key (path parameter)
Example Request:
Success Response (200):
Error Responses
All endpoints may return these common errors:
400 Bad Request
Invalid parameters:
401 Unauthorized
429 Rate Limit
Common Error Codes
INSUFFICIENT_BALANCE
Not enough SOL for transaction + fees
Add more SOL to wallet
INVALID_MINT
Token mint address invalid or doesn't exist
Verify mint address
SLIPPAGE_EXCEEDED
Price moved beyond acceptable slippage
Increase slippage tolerance
RATE_LIMIT
Too many requests
Slow down requests
See Error Handling for complete error documentation.
Code Examples
JavaScript/TypeScript
Python
Best Practices
Always Handle Errors: Implement robust error handling for all requests
Use Appropriate Slippage: Higher slippage for volatile tokens, lower for stablecoins
Monitor Transactions: Track signatures and verify confirmations
Respect Rate Limits: Implement backoff strategies
Secure API Keys: Never expose keys in client-side code
Test with Small Amounts: Validate integration with minimal SOL first
Next Steps
Learn about Local Transaction API for full control
Set up WebSocket streaming for real-time data
View code examples for your language
Last updated