npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

investing

v0.1.0

Published

Reusable investment utilities, trading agents, and financial data tools

Readme

Investing

A comprehensive TypeScript/JavaScript library for investment analysis, trading automation, and financial data processing. This package provides reusable utilities for building investment applications, trading bots, and financial analysis tools.

Features

  • 🤖 Trading Agents - Multi-agent framework for automated trading strategies
  • 📊 Stock Data - Fetch and analyze stock data from Yahoo Finance, SEC filings, and more
  • 💹 Prediction Markets - Polymarket integration for prediction market data
  • 🔌 Alpaca Trading API - Easy-to-use wrapper for Alpaca trading platform
  • 📈 Technical Analysis - Algorithmic trading strategies and indicators
  • 🎯 Social Trading - Track and analyze top traders and strategies
  • 🧠 AI-Powered Analysis - LLM-based investment research and debate generation
  • 📦 Data Files - Pre-packaged stock indexes, sector information, and market data

Installation

npm install investing
# or
yarn add investing
# or
pnpm add investing

Quick Start

Alpaca Trading Client

import { createAlpacaClient } from 'investing';

// Create client with environment variables
const alpaca = createAlpacaClient({
  paper: true, // Use paper trading
  keyId: process.env.ALPACA_API_KEY,
  secretKey: process.env.ALPACA_SECRET,
});

// Get account info
const account = await alpaca.getAccount();
console.log(`Portfolio value: $${account.portfolio_value}`);

// Place an order
const order = await alpaca.createOrder({
  symbol: 'AAPL',
  qty: 10,
  side: 'buy',
  type: 'market',
  time_in_force: 'day',
});

Fetch Stock Data

import { getStockQuote, getHistoricalData } from 'investing';

// Get real-time quote
const quote = await getStockQuote('AAPL');
console.log(`AAPL: $${quote.regularMarketPrice}`);

// Get historical data
const history = await getHistoricalData('AAPL', {
  period1: '2024-01-01',
  period2: '2024-12-31',
  interval: '1d',
});

Polymarket Prediction Markets

import { fetchMarkets, fetchLeaderboard } from 'investing';

// Get active prediction markets
const markets = await fetchMarkets(50, 'volume24hr');
console.log(`Top market: ${markets[0].question}`);

// Get top traders
const leaders = await fetchLeaderboard({
  timePeriod: '7d',
  orderBy: 'PNL',
  limit: 10,
});

Trading Agents Framework

import { createTradingGraph, MarketAnalyst } from 'investing';

// Create a trading agent system
const tradingSystem = createTradingGraph({
  agents: [
    new MarketAnalyst(),
    new BullResearcher(),
    new BearResearcher(),
    new Trader(),
  ],
  config: {
    ticker: 'AAPL',
    budget: 10000,
  },
});

// Run analysis
const result = await tradingSystem.invoke({
  ticker: 'AAPL',
  question: 'Should I buy AAPL stock?',
});

API Reference

Alpaca Trading

import { createAlpacaClient, AlpacaConfig } from 'investing/alpaca';

createAlpacaClient(config?: AlpacaConfig)

Creates an Alpaca API client for trading operations.

Parameters:

  • config.paper - Use paper trading (default: true)
  • config.keyId - Alpaca API key ID
  • config.secretKey - Alpaca secret key
  • config.baseUrl - Custom base URL (optional)

Environment Variables:

  • ALPACA_API_KEY or APCA_API_KEY_ID
  • ALPACA_SECRET or APCA_API_SECRET_KEY
  • ALPACA_BASE_URL (optional)

Stock Data & Analysis

import {
  getStockQuote,
  getHistoricalData,
  getSECFilings,
  StockQuote,
} from 'investing/stocks';

getStockQuote(symbol: string): Promise<StockQuote>

Fetch real-time stock quote from Yahoo Finance.

getHistoricalData(symbol: string, options?: HistoricalOptions)

Get historical price data for technical analysis.

getSECFilings(ticker: string, filingType?: string)

Fetch SEC filings (10-K, 10-Q, 8-K) for a company.

Prediction Markets

import {
  fetchMarkets,
  fetchLeaderboard,
  PolymarketMarket,
} from 'investing/prediction';

fetchMarkets(limit?: number, sortBy?: string)

Fetch active prediction markets from Polymarket.

Parameters:

  • limit - Number of markets to fetch (default: 50)
  • sortBy - Sort field: 'volume24hr', 'liquidity', etc.

fetchLeaderboard(options?)

Get Polymarket leaderboard of top traders.

Options:

  • timePeriod - '1d' | '7d' | '30d' | 'all'
  • orderBy - 'VOL' | 'PNL'
  • limit - Number of results (default: 20)
  • category - Market category (default: 'overall')

Trading Agents

import {
  createTradingGraph,
  MarketAnalyst,
  BullResearcher,
  BearResearcher,
  Trader,
} from 'investing/trading-agents';

createTradingGraph(config)

Creates a multi-agent trading system using LangGraph.

Agents:

  • MarketAnalyst - Analyzes market conditions and trends
  • BullResearcher - Researches bullish arguments
  • BearResearcher - Researches bearish arguments
  • Trader - Makes trading decisions based on research

Constants & Data

import { STOCK_INDEXES, SECTORS, CATEGORIES } from 'investing/constants';

Pre-loaded data files available:

  • data/stock-indexes.json - Major stock indexes (S&P 500, NASDAQ, etc.)
  • data/sectors-industries.json - Industry classifications
  • data/sector-info.json - Sector descriptions and metrics
  • data/stock-names.json - Company names and tickers
  • data/globe.json - Geographic market data

Utilities

import { cn, setStateInURL } from 'investing/utils';

cn(...inputs: ClassValue[])

Utility for merging CSS classes using clsx and tailwind-merge.

setStateInURL(state?, addToHistory?)

Sync application state to URL parameters for shareable links.

Data Files

Access pre-packaged data files:

import stockIndexes from 'investing/data/stock-indexes.json';
import sectors from 'investing/data/sectors-industries.json';
import stockNames from 'investing/data/stock-names.json';

console.log(`Total stocks: ${stockNames.length}`);
console.log(`S&P 500 stocks: ${stockIndexes['S&P 500'].length}`);

Environment Variables

Create a .env file with your API keys:

# Alpaca Trading API
ALPACA_API_KEY=your_key_here
ALPACA_SECRET=your_secret_here

# Optional: Use live trading (default is paper)
# ALPACA_BASE_URL=https://api.alpaca.markets

# OpenAI for AI-powered analysis
OPENAI_API_KEY=your_openai_key

# Optional: Alternative LLM providers
ANTHROPIC_API_KEY=your_anthropic_key
GOOGLE_API_KEY=your_google_key
GROQ_API_KEY=your_groq_key

TypeScript Support

This package includes full TypeScript definitions. Import types directly:

import type {
  AlpacaConfig,
  StockQuote,
  PolymarketMarket,
  TradingAgent,
} from 'investing';

Advanced Usage

Custom Trading Strategy

import { createTradingGraph, BaseTradingAgent } from 'investing';

class MomentumTrader extends BaseTradingAgent {
  name = 'momentum-trader';

  async analyze(state: TradingState) {
    // Implement your strategy
    const data = await this.getHistoricalData(state.ticker);
    const momentum = this.calculateMomentum(data);

    return {
      signal: momentum > 0.5 ? 'buy' : 'sell',
      confidence: Math.abs(momentum),
    };
  }
}

const strategy = new MomentumTrader();
const result = await strategy.analyze({ ticker: 'TSLA' });

Multi-Agent Debate System

import { createDebateSystem } from 'investing';

const debate = await createDebateSystem({
  ticker: 'NVDA',
  agents: ['bull_researcher', 'bear_researcher', 'neutral_analyst'],
  rounds: 3,
});

const decision = await debate.run();
console.log(decision.recommendation); // 'buy' | 'sell' | 'hold'
console.log(decision.reasoning);

Batch Stock Analysis

import { getStockQuote } from 'investing';

const tickers = ['AAPL', 'GOOGL', 'MSFT', 'AMZN'];
const quotes = await Promise.all(tickers.map(getStockQuote));

const summary = quotes.map((q, i) => ({
  ticker: tickers[i],
  price: q.regularMarketPrice,
  change: q.regularMarketChangePercent,
}));

Database Integration (Optional)

If using the database features, install the peer dependency:

npm install drizzle-orm @libsql/client

Then import database schemas:

import { db, stocksTable, positionsTable } from 'investing/db';

// Query your database
const stocks = await db.select().from(stocksTable).limit(10);

Examples

See the /examples directory for complete working examples:

  • examples/alpaca-trading.ts - Basic trading operations
  • examples/stock-analysis.ts - Stock data analysis
  • examples/prediction-markets.ts - Polymarket integration
  • examples/trading-bot.ts - Automated trading bot
  • examples/multi-agent-research.ts - AI research agents

Contributing

Contributions are welcome! Please read the contributing guidelines before submitting PRs.

License

rights.institute/prosper

Links

Support

For issues and questions:


Built with ❤️ for the investment and trading community.