Commit Graph

8 Commits

Author SHA1 Message Date
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
Jon
7b1a20c768 Poll for market open instead of single long setTimeout
macOS sleep suspends the Docker VM, causing long setTimeout calls to
never fire. Replace the one-shot wait with a polling loop that checks
getClock every 30s (capped to time-until-open), so the bot resumes
promptly after the host wakes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 11:02:49 -07:00
Jon
4f1e745534 Add backtesting entry point for offline strategy testing
Introduces a BacktestClient that replays historical 1-min bars against the
existing strategy code, plus a CLI entry point (npm run backtest) that fetches
bars from Alpaca and runs the bot over a date range. Makes wait() pluggable
so the backtest resolves delays instantly while advancing simulated time.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 00:59:22 -07:00
Jon
188a1dc8b0 Add granular logging across all source files
Introduce logger infrastructure and add structured logging to every layer:
alpaca.ts (buy/sell/quote/clock), momentum-indicator.ts (evaluate flow),
momentum-strategy.ts (poll loop), index.ts (startup/cycle), and trading.ts
(market timing). Replace raw console.log calls with leveled logger. Update
all tests with appropriate console spies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 17:00:15 -07:00
Jon
075572a01c Remove executor, add buy/sell to Alpaca, move capital allocation to Bot
Replace the Executor logging placeholder with real buy/sell methods on
the Alpaca class that place market orders via createOrder and return the
fill price. Strategies now receive their capital amount directly and
place orders themselves. Bot accepts StrategyAllocation[] to decouple
capital allocation from strategy definition.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 11:05:21 -07:00
Jon
e32e30af47 update our alpaca calls to be separate bid and ask 2026-02-03 13:58:42 -07:00
Jon
ecdffab950 Add bot orchestrator, wire up index.ts, remove old runDay
Bot validates strategy capital allocations, waits for market open,
runs all strategies concurrently, and passes signals to the executor.
The main loop in index.ts now delegates to Bot.runDay().

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 14:09:30 -07:00
Jon
5e06c06987 Refactor for TDD workflow with Vitest and ESLint
- Move API keys from hardcoded values to .env via dotenv
- Extract business logic into src/trading.ts with dependency injection
- Add typed AlpacaClient interface, replace `any` on Alpaca class
- Add Vitest test suites for trading logic and Alpaca wrapper (14 tests)
- Set up ESLint with @typescript-eslint for linting
- Fix getAsset to pass symbol string directly to SDK
- Fix typo (alpacha -> alpaca), remove unused ws/node-fetch deps
- Update .gitignore for node_modules and .env

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 13:49:31 -07:00