37 - API Key & Playground
Overview
Architecture Diagram
┌──────────────────────────────────────────────────────────────────────────────┐
│ API Key Architecture │
└──────────────────────────────────────────────────────────────────────────────┘
Generate API Key Request
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ API Key Generation │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ api_key = secrets.token_hex(32) # 64 character hex string │ │
│ │ │ │
│ │ Example: a1b2c3d4e5f6...789012345678901234567890abcdef12345678 │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Dual Storage Strategy │
│ │
│ ┌──────────────────────────────┐ ┌──────────────────────────────────────┐│
│ │ Hashed (Argon2 + Pepper) │ │ Encrypted (Fernet) ││
│ │ For API authentication │ │ For TradingView integration ││
│ │ │ │ ││
│ │ hash = argon2.hash( │ │ encrypted = fernet.encrypt( ││
│ │ api_key + pepper │ │ api_key ││
│ │ ) │ │ ) ││
│ │ │ │ ││
│ │ → Stored in api_key_hash │ │ → Stored in encrypted_api_key ││
│ └──────────────────────────────┘ └──────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ api_keys Table (SQLite) │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ id | user_id | api_key_hash | encrypted_api_key | order_mode │ │
│ │ ───┼─────────┼──────────────┼───────────────────┼─────────────────│ │
│ │ 1 | admin | $argon2id... | gAAAAA... | auto │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘API Key Generation
Key Properties
Property
Value
API Key Storage
Dual Storage for Different Use Cases
Three-Level Verification
Order Mode
Auto vs Semi-Auto Mode
Mode
Description
Use Case
API Playground
Architecture
Endpoint Categories
API Endpoints
Endpoint
Method
Description
WebSocket Testing
WebSocket Endpoint Format in Bruno
WebSocket Actions
Action
Description
API Usage Examples
Using API Key in Requests
TradingView Integration
Security Considerations
API Key Protection
Layer
Protection
Playground Security
Key Files Reference
File
Purpose
Last updated