Jon 4ca7073d77 Sell by qty instead of notional, poll for buy fill
The buy order can return before filling, giving null price/qty. Now
buy polls getOrder until filled. Sell takes the actual qty from the
buy fill instead of the original dollar amount, which avoids the
"insufficient qty" error when the price moves between buy and sell.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 12:37:12 -07:00
2026-02-09 17:06:28 -07:00
2025-02-11 00:24:00 -07:00
2026-02-01 17:51:46 -07:00

fit

A TypeScript trading bot built on the Alpaca paper trading API. It runs pluggable strategies that use indicators to generate buy/sell signals.

How it works

  1. The Bot waits for market open via the Alpaca clock API
  2. It runs all registered Strategies concurrently, each with its own capital allocation
  3. Each strategy uses Indicators to evaluate market conditions and returns buy/sell Signals
  4. The Executor processes the signals
  5. The bot loops hourly, waiting for the next market open

Setup

Requires an Alpaca paper trading account. Create a .env file in the project root:

ALPACA_KEY_ID=your_key_id
ALPACA_SECRET_KEY=your_secret_key

Install dependencies:

npm install

Running

# Build and run
npm run build
npm start

# Development (auto-reload)
npm run dev

# Docker
docker build -t fit .
docker run --env-file .env fit

Testing and linting

npm test
npm run lint

Project structure

src/
  index.ts                  # Entry point, main loop
  alpaca.ts                 # Alpaca API client wrapper
  bot.ts                    # Orchestrator, runs strategies each day
  executor.ts               # Executes signals from strategies
  indicator.ts              # Indicator interface
  strategy.ts               # Strategy/Signal interfaces
  trading.ts                # Utilities (wait, market open, etc.)
  momentum-indicator.ts     # Samples QQQ direction after open
  momentum-strategy.ts      # Trades TQQQ/SQQQ based on momentum
Description
Just a simple stock trading bot, playing around with claude code
Readme 5.3 MiB
Languages
TypeScript 98.5%
JavaScript 1.1%
Shell 0.2%
Dockerfile 0.2%