Trading Automation Toolkit
Trading Automation Toolkit Link to heading
Go-based HTTP API Server for Programmatic Trading
Overview Link to heading
A Go-based trading automation toolkit that provides an authenticated HTTP API server for programmatic stock trading. The system supports market, limit, stop, and stop-limit orders while carefully mimicking browser behavior to ensure reliability.
The project evolved from a CLI tool into a full HTTP API server, enabling integration with other systems and automated trading strategies.
Key Features Link to heading
- Authenticated HTTP API - Bearer token authentication with Chi router
- Multiple Order Types - Market, Limit, Stop, and Stop-Limit orders
- Browser Mimicry - Matches browser headers and follows validate → order sequence
- Real-time Data - WebSocket integration for live market data
- Fractional Shares - Support for fractional share quantities
Technical Implementation Link to heading
Architecture Link to heading
| Component | Technology |
|---|---|
| Language | Go 1.22+ |
| Router | github.com/go-chi/chi/v5 |
| WebSocket | github.com/gorilla/websocket |
| Auth | Bearer token (API_KEY) |
| Config | godotenv for environment management |
API Endpoints Link to heading
The server exposes RESTful endpoints for trading operations:
| Endpoint | Method | Description |
|---|---|---|
/api/orders/market/buy | POST | Place market buy order |
/api/orders/market/sell | POST | Place market sell order |
/api/orders/limit/buy | POST | Place limit buy order |
/api/orders/limit/sell | POST | Place limit sell order |
/api/orders/stop/* | POST | Stop/Stop-limit orders |
Security Model Link to heading
- Internal Auth - Static API_KEY in Authorization header
- External Auth - Session cookies (refreshed periodically)
- Request Mimicry - Headers match browser exactly
- Validation - Follows platform’s validate → order flow
Client Pattern Link to heading
Separate clients for each integration:
TradingClient- Order executionFinnhubClient- Real-time market data via WebSocket
Development Approach Link to heading
- TDD - Test-driven development for reliability
- Integration Tests - API clients with mocked HTTP responses
- Validation Testing - Ensures browser behavior is mimicked correctly
Constraints Link to heading
- Authentication - Session cookies require periodic refresh
- Rate Limiting - Respects platform rate limits
- Fractional Quantities - Handles decimal share amounts (e.g., 0.1 shares)
Use Case Link to heading
This toolkit enables automated portfolio management and trading strategies that would be tedious to execute manually. All operations are performed through a secure, local API server.