Utilities for handling trading exchange data with proper type safety and aggregation.
- Candle Batching: Aggregates multiple exchange candles into larger timeframes
- Type Safety: Zod schemas for runtime validation of exchange data
- High Precision: Uses
big.jsfor arbitrary-precision decimal arithmetic - Event-Driven: Built-in EventEmitter for streaming candle updates
- Flexible Intervals: Timeframes using human-readable strings (e.g., "1h", "5m")
The Exchange interface is intentionally kept generic so that any exchange can implement it. This means:
- No exchange-specific order types. Features like
stop_limitortrailing_stopare available on some exchanges (e.g. Alpaca) but not others. Instead of leaking exchange-specific concepts into the shared interface, these behaviors should be replicated in the trading-strategy layer. This keeps the boundary clean and portable. - No order modification (patch/replace). Some exchanges support modifying an existing order in-place. This can always be substituted with a cancellation followed by a new order placement, which works universally across all exchanges.
- Only
MARKETandLIMITorder types. These are the two primitives supported by virtually every exchange, making them the right abstraction level for this package.
This package includes a first-class Alpaca implementation.
import {getAlpacaClient} from '@typedtrader/exchange';
const exchange = getAlpacaClient({
apiKey: process.env.ALPACA_API_KEY,
apiSecret: process.env.ALPACA_API_SECRET,
usePaperTrading: true,
});Resources: