investing 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,390 @@
1
+ # Investing
2
+
3
+ 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.
4
+
5
+ ## Features
6
+
7
+ - 🤖 **Trading Agents** - Multi-agent framework for automated trading strategies
8
+ - 📊 **Stock Data** - Fetch and analyze stock data from Yahoo Finance, SEC filings, and more
9
+ - 💹 **Prediction Markets** - Polymarket integration for prediction market data
10
+ - 🔌 **Alpaca Trading API** - Easy-to-use wrapper for Alpaca trading platform
11
+ - 📈 **Technical Analysis** - Algorithmic trading strategies and indicators
12
+ - 🎯 **Social Trading** - Track and analyze top traders and strategies
13
+ - 🧠 **AI-Powered Analysis** - LLM-based investment research and debate generation
14
+ - 📦 **Data Files** - Pre-packaged stock indexes, sector information, and market data
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install investing
20
+ # or
21
+ yarn add investing
22
+ # or
23
+ pnpm add investing
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ### Alpaca Trading Client
29
+
30
+ ```typescript
31
+ import { createAlpacaClient } from 'investing';
32
+
33
+ // Create client with environment variables
34
+ const alpaca = createAlpacaClient({
35
+ paper: true, // Use paper trading
36
+ keyId: process.env.ALPACA_API_KEY,
37
+ secretKey: process.env.ALPACA_SECRET,
38
+ });
39
+
40
+ // Get account info
41
+ const account = await alpaca.getAccount();
42
+ console.log(`Portfolio value: $${account.portfolio_value}`);
43
+
44
+ // Place an order
45
+ const order = await alpaca.createOrder({
46
+ symbol: 'AAPL',
47
+ qty: 10,
48
+ side: 'buy',
49
+ type: 'market',
50
+ time_in_force: 'day',
51
+ });
52
+ ```
53
+
54
+ ### Fetch Stock Data
55
+
56
+ ```typescript
57
+ import { getStockQuote, getHistoricalData } from 'investing';
58
+
59
+ // Get real-time quote
60
+ const quote = await getStockQuote('AAPL');
61
+ console.log(`AAPL: $${quote.regularMarketPrice}`);
62
+
63
+ // Get historical data
64
+ const history = await getHistoricalData('AAPL', {
65
+ period1: '2024-01-01',
66
+ period2: '2024-12-31',
67
+ interval: '1d',
68
+ });
69
+ ```
70
+
71
+ ### Polymarket Prediction Markets
72
+
73
+ ```typescript
74
+ import { fetchMarkets, fetchLeaderboard } from 'investing';
75
+
76
+ // Get active prediction markets
77
+ const markets = await fetchMarkets(50, 'volume24hr');
78
+ console.log(`Top market: ${markets[0].question}`);
79
+
80
+ // Get top traders
81
+ const leaders = await fetchLeaderboard({
82
+ timePeriod: '7d',
83
+ orderBy: 'PNL',
84
+ limit: 10,
85
+ });
86
+ ```
87
+
88
+ ### Trading Agents Framework
89
+
90
+ ```typescript
91
+ import { createTradingGraph, MarketAnalyst } from 'investing';
92
+
93
+ // Create a trading agent system
94
+ const tradingSystem = createTradingGraph({
95
+ agents: [
96
+ new MarketAnalyst(),
97
+ new BullResearcher(),
98
+ new BearResearcher(),
99
+ new Trader(),
100
+ ],
101
+ config: {
102
+ ticker: 'AAPL',
103
+ budget: 10000,
104
+ },
105
+ });
106
+
107
+ // Run analysis
108
+ const result = await tradingSystem.invoke({
109
+ ticker: 'AAPL',
110
+ question: 'Should I buy AAPL stock?',
111
+ });
112
+ ```
113
+
114
+ ## API Reference
115
+
116
+ ### Alpaca Trading
117
+
118
+ ```typescript
119
+ import { createAlpacaClient, AlpacaConfig } from 'investing/alpaca';
120
+ ```
121
+
122
+ #### `createAlpacaClient(config?: AlpacaConfig)`
123
+
124
+ Creates an Alpaca API client for trading operations.
125
+
126
+ **Parameters:**
127
+ - `config.paper` - Use paper trading (default: true)
128
+ - `config.keyId` - Alpaca API key ID
129
+ - `config.secretKey` - Alpaca secret key
130
+ - `config.baseUrl` - Custom base URL (optional)
131
+
132
+ **Environment Variables:**
133
+ - `ALPACA_API_KEY` or `APCA_API_KEY_ID`
134
+ - `ALPACA_SECRET` or `APCA_API_SECRET_KEY`
135
+ - `ALPACA_BASE_URL` (optional)
136
+
137
+ ### Stock Data & Analysis
138
+
139
+ ```typescript
140
+ import {
141
+ getStockQuote,
142
+ getHistoricalData,
143
+ getSECFilings,
144
+ StockQuote,
145
+ } from 'investing/stocks';
146
+ ```
147
+
148
+ #### `getStockQuote(symbol: string): Promise<StockQuote>`
149
+
150
+ Fetch real-time stock quote from Yahoo Finance.
151
+
152
+ #### `getHistoricalData(symbol: string, options?: HistoricalOptions)`
153
+
154
+ Get historical price data for technical analysis.
155
+
156
+ #### `getSECFilings(ticker: string, filingType?: string)`
157
+
158
+ Fetch SEC filings (10-K, 10-Q, 8-K) for a company.
159
+
160
+ ### Prediction Markets
161
+
162
+ ```typescript
163
+ import {
164
+ fetchMarkets,
165
+ fetchLeaderboard,
166
+ PolymarketMarket,
167
+ } from 'investing/prediction';
168
+ ```
169
+
170
+ #### `fetchMarkets(limit?: number, sortBy?: string)`
171
+
172
+ Fetch active prediction markets from Polymarket.
173
+
174
+ **Parameters:**
175
+ - `limit` - Number of markets to fetch (default: 50)
176
+ - `sortBy` - Sort field: 'volume24hr', 'liquidity', etc.
177
+
178
+ #### `fetchLeaderboard(options?)`
179
+
180
+ Get Polymarket leaderboard of top traders.
181
+
182
+ **Options:**
183
+ - `timePeriod` - '1d' | '7d' | '30d' | 'all'
184
+ - `orderBy` - 'VOL' | 'PNL'
185
+ - `limit` - Number of results (default: 20)
186
+ - `category` - Market category (default: 'overall')
187
+
188
+ ### Trading Agents
189
+
190
+ ```typescript
191
+ import {
192
+ createTradingGraph,
193
+ MarketAnalyst,
194
+ BullResearcher,
195
+ BearResearcher,
196
+ Trader,
197
+ } from 'investing/trading-agents';
198
+ ```
199
+
200
+ #### `createTradingGraph(config)`
201
+
202
+ Creates a multi-agent trading system using LangGraph.
203
+
204
+ **Agents:**
205
+ - `MarketAnalyst` - Analyzes market conditions and trends
206
+ - `BullResearcher` - Researches bullish arguments
207
+ - `BearResearcher` - Researches bearish arguments
208
+ - `Trader` - Makes trading decisions based on research
209
+
210
+ ### Constants & Data
211
+
212
+ ```typescript
213
+ import { STOCK_INDEXES, SECTORS, CATEGORIES } from 'investing/constants';
214
+ ```
215
+
216
+ Pre-loaded data files available:
217
+ - `data/stock-indexes.json` - Major stock indexes (S&P 500, NASDAQ, etc.)
218
+ - `data/sectors-industries.json` - Industry classifications
219
+ - `data/sector-info.json` - Sector descriptions and metrics
220
+ - `data/stock-names.json` - Company names and tickers
221
+ - `data/globe.json` - Geographic market data
222
+
223
+ ### Utilities
224
+
225
+ ```typescript
226
+ import { cn, setStateInURL } from 'investing/utils';
227
+ ```
228
+
229
+ #### `cn(...inputs: ClassValue[])`
230
+
231
+ Utility for merging CSS classes using clsx and tailwind-merge.
232
+
233
+ #### `setStateInURL(state?, addToHistory?)`
234
+
235
+ Sync application state to URL parameters for shareable links.
236
+
237
+ ## Data Files
238
+
239
+ Access pre-packaged data files:
240
+
241
+ ```typescript
242
+ import stockIndexes from 'investing/data/stock-indexes.json';
243
+ import sectors from 'investing/data/sectors-industries.json';
244
+ import stockNames from 'investing/data/stock-names.json';
245
+
246
+ console.log(`Total stocks: ${stockNames.length}`);
247
+ console.log(`S&P 500 stocks: ${stockIndexes['S&P 500'].length}`);
248
+ ```
249
+
250
+ ## Environment Variables
251
+
252
+ Create a `.env` file with your API keys:
253
+
254
+ ```env
255
+ # Alpaca Trading API
256
+ ALPACA_API_KEY=your_key_here
257
+ ALPACA_SECRET=your_secret_here
258
+
259
+ # Optional: Use live trading (default is paper)
260
+ # ALPACA_BASE_URL=https://api.alpaca.markets
261
+
262
+ # OpenAI for AI-powered analysis
263
+ OPENAI_API_KEY=your_openai_key
264
+
265
+ # Optional: Alternative LLM providers
266
+ ANTHROPIC_API_KEY=your_anthropic_key
267
+ GOOGLE_API_KEY=your_google_key
268
+ GROQ_API_KEY=your_groq_key
269
+ ```
270
+
271
+ ## TypeScript Support
272
+
273
+ This package includes full TypeScript definitions. Import types directly:
274
+
275
+ ```typescript
276
+ import type {
277
+ AlpacaConfig,
278
+ StockQuote,
279
+ PolymarketMarket,
280
+ TradingAgent,
281
+ } from 'investing';
282
+ ```
283
+
284
+ ## Advanced Usage
285
+
286
+ ### Custom Trading Strategy
287
+
288
+ ```typescript
289
+ import { createTradingGraph, BaseTradingAgent } from 'investing';
290
+
291
+ class MomentumTrader extends BaseTradingAgent {
292
+ name = 'momentum-trader';
293
+
294
+ async analyze(state: TradingState) {
295
+ // Implement your strategy
296
+ const data = await this.getHistoricalData(state.ticker);
297
+ const momentum = this.calculateMomentum(data);
298
+
299
+ return {
300
+ signal: momentum > 0.5 ? 'buy' : 'sell',
301
+ confidence: Math.abs(momentum),
302
+ };
303
+ }
304
+ }
305
+
306
+ const strategy = new MomentumTrader();
307
+ const result = await strategy.analyze({ ticker: 'TSLA' });
308
+ ```
309
+
310
+ ### Multi-Agent Debate System
311
+
312
+ ```typescript
313
+ import { createDebateSystem } from 'investing';
314
+
315
+ const debate = await createDebateSystem({
316
+ ticker: 'NVDA',
317
+ agents: ['bull_researcher', 'bear_researcher', 'neutral_analyst'],
318
+ rounds: 3,
319
+ });
320
+
321
+ const decision = await debate.run();
322
+ console.log(decision.recommendation); // 'buy' | 'sell' | 'hold'
323
+ console.log(decision.reasoning);
324
+ ```
325
+
326
+ ### Batch Stock Analysis
327
+
328
+ ```typescript
329
+ import { getStockQuote } from 'investing';
330
+
331
+ const tickers = ['AAPL', 'GOOGL', 'MSFT', 'AMZN'];
332
+ const quotes = await Promise.all(tickers.map(getStockQuote));
333
+
334
+ const summary = quotes.map((q, i) => ({
335
+ ticker: tickers[i],
336
+ price: q.regularMarketPrice,
337
+ change: q.regularMarketChangePercent,
338
+ }));
339
+ ```
340
+
341
+ ## Database Integration (Optional)
342
+
343
+ If using the database features, install the peer dependency:
344
+
345
+ ```bash
346
+ npm install drizzle-orm @libsql/client
347
+ ```
348
+
349
+ Then import database schemas:
350
+
351
+ ```typescript
352
+ import { db, stocksTable, positionsTable } from 'investing/db';
353
+
354
+ // Query your database
355
+ const stocks = await db.select().from(stocksTable).limit(10);
356
+ ```
357
+
358
+ ## Examples
359
+
360
+ See the `/examples` directory for complete working examples:
361
+
362
+ - `examples/alpaca-trading.ts` - Basic trading operations
363
+ - `examples/stock-analysis.ts` - Stock data analysis
364
+ - `examples/prediction-markets.ts` - Polymarket integration
365
+ - `examples/trading-bot.ts` - Automated trading bot
366
+ - `examples/multi-agent-research.ts` - AI research agents
367
+
368
+ ## Contributing
369
+
370
+ Contributions are welcome! Please read the contributing guidelines before submitting PRs.
371
+
372
+ ## License
373
+
374
+ rights.institute/prosper
375
+
376
+ ## Links
377
+
378
+ - [GitHub Repository](https://github.com/vtempest/ai-broker-investment-agent)
379
+ - [Documentation](https://invest.vtempest.com/docs)
380
+ - [Examples](./examples)
381
+
382
+ ## Support
383
+
384
+ For issues and questions:
385
+ - [GitHub Issues](https://github.com/vtempest/ai-broker-investment-agent/issues)
386
+ - [Documentation](https://invest.vtempest.com/docs)
387
+
388
+ ---
389
+
390
+ Built with ❤️ for the investment and trading community.