4ca7073d773e1602a7a6c0449e2acc846f288d9b
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>
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
- The Bot waits for market open via the Alpaca clock API
- It runs all registered Strategies concurrently, each with its own capital allocation
- Each strategy uses Indicators to evaluate market conditions and returns buy/sell Signals
- The Executor processes the signals
- 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
Languages
TypeScript
98.5%
JavaScript
1.1%
Shell
0.2%
Dockerfile
0.2%