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

ComponentTechnology
LanguageGo 1.22+
Routergithub.com/go-chi/chi/v5
WebSocketgithub.com/gorilla/websocket
AuthBearer token (API_KEY)
Configgodotenv for environment management

API Endpoints Link to heading

The server exposes RESTful endpoints for trading operations:

EndpointMethodDescription
/api/orders/market/buyPOSTPlace market buy order
/api/orders/market/sellPOSTPlace market sell order
/api/orders/limit/buyPOSTPlace limit buy order
/api/orders/limit/sellPOSTPlace limit sell order
/api/orders/stop/*POSTStop/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 execution
  • FinnhubClient - 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.