BeginnerUtilities & ToolsJavaScript
Alpaca Historical Data Fetcher¶
A Node.js script that fetches historical bars (OHLCV data) for stocks or crypto from the Alpaca Market Data API. It prompts interactively for the symbol type, symbol, timeframe, and date range, then prints the results as JSON.
External API: This utility calls the Alpaca Market Data API. A network connection and valid API credentials are required.
Files¶
| File | Description |
|---|---|
FetchBars.js |
Interactive Node.js historical-bars fetcher |
package.json |
Node.js dependencies |
Requirements¶
- Node.js v14 or higher
- An Alpaca account with API credentials
Setup¶
- Install dependencies:
- Create a
.envfile in the project root to hold your credentials:
Usage¶
You will be prompted for:
- Symbol type —
stockorcrypto - Symbol — e.g.
AAPLfor stocks,BTC/USDfor crypto - Timeframe — e.g.
1Day,1Hour,5Min - Start date —
YYYY-MM-DD - End date —
YYYY-MM-DD
The script fetches the matching bars and prints them in JSON format.
Example session¶
Enter symbol type (stock/crypto): stock
Enter symbol (e.g. AAPL for stock, BTC/USD for crypto): AAPL
Enter timeframe (e.g. 1Day, 1Hour, 5Min): 1Day
Enter start date (YYYY-MM-DD): 2023-01-01
Enter end date (YYYY-MM-DD): 2023-01-31
Notes¶
- Ensure your API key has permission for the data class you request.
- See the Alpaca Stock Bars API docs and Alpaca Crypto Bars API docs for the full list of supported timeframes and parameters.
License¶
MIT
Continue in Utilities & Tools¶
-
This folder contains core mathematical and date/time utilities that form the foundation for quantitative finance calculations.
-
This utility does NOT use any external APIs. All exchange rates are entered manually for learning and experimentation.
-
This folder contains utilities for data processing, validation, and manipulation in financial applications.
-
This utility does NOT use any external APIs. All data is managed locally for learning and experimentation.
-
A pair of minimal, dependency-light logging utilities implemented in both Python and JavaScript. Each supports adding, reading, editing, and deleting log entries through an interactive command-line menu. All entries are persisted to a plain-text
log.txtfile in the working directory. -
This folder contains utilities for processing, analyzing, and fetching market data for financial applications.