graph TD
A[浏览器客户端] --> B[前端应用 - 图表与自选列表]
B --> C[API 聚合层]
C --> D{"请求类型判断"}
D -->|"行情快照"| E[行情数据源适配器]
D -->|"公司基本面"| F[财报与档案数据源]
D -->|"告警规则"| G[告警调度服务]
E --> H[统一数据模型]
F --> H
G --> I[规则匹配引擎]
I --> J[通知通道 - 邮件与推送]
H --> K[缓存层 - 降低上游配额消耗]
K --> B
值得关注的技术难点集中在三处。
第一是多数据源适配。 免费或低价的行情 API 普遍存在字段命名混乱、时间戳时区不统一、限流策略各异的问题。OpenStock 如果要做成“开放替代品”,必然要在中间层定义一套统一的资产模型(Symbol、Price、Change、Volume、MarketCap 等),把各上游的差异收敛在这一层。这也是它最容易形成社区贡献点的地方——新增一个数据源适配器,比改前端有价值得多。
第二是缓存与配额博弈。 免费 API 的调用次数是硬约束。合理做法是按标的做分级缓存:热门标的短 TTL、冷门标的长 TTL,并为行情推送引入轮询合并(batch polling),把 N 个标的的请求折叠成一次批量调用。若直接让前端逐个轮询,配额会瞬间耗尽。
OpenStock is an open-source alternative to expensive market platforms. Track real-time prices, set personalized alerts, and explore detailed company insights — built openly, for everyone, forever free.
Orbit. Free, open-source macOS screen recorder, screenshot tool and video editor: auto-zoom, smooth cursor, backgrounds, web recordings and AI agent recording.
Markets, minus the paywall. OpenStock is a free, open-source alternative to expensive market platforms: track prices, watch the whole market and dig into company insights. Use it at openstock-ods.vercel.app, or run your own copy with every feature.
OpenStock is community-built and not a brokerage. Market data may be delayed depending on the provider and your setup. Nothing here is financial advice.
A dashboard for nine markets: US, India, Germany, Canada, Australia, Saudi Arabia, Poland, Crypto and Forex, with an index pulse and top stories, plus a heatmap and market leaders, or for Saudi Arabia and Poland today’s movers and a quotes table priced from Yahoo Finance.
Search every exchange Finnhub covers with ⌘K, and keep stocks open as browser-style tabs.
Stock pages
TradingView candles with drawing tools (trend lines, Fibonacci, shapes, text) and fullscreen.
Pick indicators once (SMA, EMA, Bollinger Bands, VWAP, RSI, MACD, Stochastic, ATR) and they stay on every chart.
Financials, technicals, the company profile and the dividend yield.
Sentiment from Reddit, X, news and Polymarket (with an Adanos key).
Recent news rated 1 to 10 for relevance, with what each story means for the stock (with an AlphAI key).
Watchlist and alerts
A starred watchlist of up to 50 stocks, plus up to 10 named lists of 50, saved to your account. File a stock into a list from any watchlist row or straight from search.
Price alerts above or below a target, or when the price crosses its 20, 50, 100 or 200-day moving average, checked every 5 minutes and emailed to you (in realtime mode).
A weekly, AI-written news digest by email every Monday.
Accounts
Email and password, plus Google and GitHub sign-in when configured; password reset and a profile page.
Rate-limited sign-in, sign-up and password reset; resetting your password signs out your other devices.
Languages and devices
The app, sign-in pages and emails in English, Polish and Arabic (laid out right to left), from your browser’s language or the Language menu in the sidebar. The public site is in English.
Fits phones and tablets from 320px wide.
Public pages
A TradingView chart and the latest SEC filings for every S&P 500 and Nasdaq-100 company at /s/<ticker>, and plain comparison guides at /compare, with no account needed.
Community
A changelog that credits everyone who contributed, a Wall of love, and an update banner in the app.
⏱️ How fresh is the data
Charts come from TradingView: live for most markets, end of day for some. Quotes, watchlist prices and alerts come from Finnhub:
Every hour, or every 15 seconds with NEXT_PUBLIC_OPENSTOCK_DATA_MODE=realtime and your own Finnhub keys
By email, in realtime mode
Free
Saudi and Polish prices come from Yahoo Finance, delayed, on every deployment, because TradingView embeds block Tadawul and show Warsaw only end of day.
Vercel; a Docker image on GitHub Container Registry for self-hosting; Cloudflare Workers through vinext (experimental)
🤸 Quick start
You need Node.js 22 LTS, a MongoDB database (a free Atlas cluster, or the Docker setup) and a free Finnhub key.
git clone https://github.com/Open-Dev-Society/OpenStock.git
cd OpenStock
npm ci
cp .env.example .env # fill in MONGODB_URI, BETTER_AUTH_SECRET and FINNHUB_API_KEY
node scripts/check-env.mjs # checks your .env
npm run test:db # checks the MongoDB connection
npm run dev # http://localhost:3000
Welcome emails, price alerts and the weekly digest run as Inngest jobs. Locally, start Inngest’s dev server alongside the app: npx inngest-cli@latest dev.
For production: npm run build && npm start.
🔐 Environment variables
Every variable is listed with comments in .env.example. The ones that matter:
Variable
Needed
What it’s for
MONGODB_URI
Yes
Your MongoDB database
BETTER_AUTH_SECRET
Yes
Signs sessions. Generate it with openssl rand -hex 32. Auth refuses to run in production without it
BETTER_AUTH_URL
Yes
The app’s public URL, used for auth callbacks and links in emails
FINNHUB_API_KEY
Yes
Market data. Or put several free keys, comma-separated, in FINNHUB_API_KEYS: they’re rotated, and each adds 60 requests a minute
NEXT_PUBLIC_OPENSTOCK_DATA_MODE
No
cached (hourly, the default) or realtime (every 15 seconds, with price alerts). Fixed when the app is built: rebuild after changing it
INNGEST_SIGNING_KEY, INNGEST_EVENT_KEY
In production
Background jobs: welcome emails, price alerts and the weekly digest
NODEMAILER_EMAIL, NODEMAILER_PASSWORD
No
Sending email through Gmail, with an app password. Without them, emails are skipped
Social sign-in. Callbacks: <BETTER_AUTH_URL>/api/auth/callback/google and /github
NEXT_PUBLIC_FINNHUB_API_KEY still works as a name for the Finnhub key. No key is ever sent to the browser.
🐳 Self-hosting
Docker Compose
Runs OpenStock and MongoDB together. MongoDB is only reachable inside the Docker network; it isn’t published on your machine.
Fill in .env (see above). For the bundled database, choose a password and use it in both places. Letters and digits are simplest; @ : / ? # must be percent-encoded in the URI.
The image build needs no secrets: every variable is read when the container starts, except NEXT_PUBLIC_OPENSTOCK_DATA_MODE, which Compose passes to the build from .env. Data lives in the mongo-data volume, and the MongoDB password is only applied when that volume is first created.
Prebuilt image
Every push to main publishes ghcr.io/open-dev-society/openstock for amd64 and arm64, tagged latest, sha-<commit>, and a version for each release (for example 2026.10.18). To use it, replace build: under openstock in docker-compose.yml with:
image: ghcr.io/open-dev-society/openstock:latest
then run docker compose pull && docker compose up -d. The prebuilt image runs in cached mode; build it yourself for realtime.
One-click deploys
Railway
OpenStock ships a railway.json that builds the Dockerfile, checks health on /sign-in and restarts on failure. The template above sets everything up; to do it by hand:
Create a project and add a MongoDB database (+ New → Database → MongoDB).
Add a service from this repository (+ New → GitHub Repo).
Under Settings → Networking, generate a public domain and redeploy.
For background jobs, add your Railway domain as an app in the Inngest dashboard, pointing to https://<your-domain>/api/inngest. To turn on realtime mode, also set NEXT_PUBLIC_OPENSTOCK_DATA_MODE=realtime; Railway passes it to the build.
Cloudflare Workers (experimental)
OpenStock can also run on Cloudflare Workers through vinext. The hosted site still runs on Vercel; Workers is for self-hosters who want it.
Set the runtime variables as Worker secrets (npx wrangler secret put MONGODB_URI, and the same for BETTER_AUTH_SECRET, BETTER_AUTH_URL, FINNHUB_API_KEY, the email, Inngest and AI keys). BETTER_AUTH_URL is your Worker’s URL. NEXT_PUBLIC_* values are read at build time, so set them before building.
Allow Cloudflare’s addresses in your database’s network access (on Atlas, 0.0.0.0/0 with a strong password).
Add https://<your-worker>/api/auth/callback/google and .../github to your OAuth apps if you use social sign-in, and point Inngest at https://<your-worker>/api/inngest.
Build and deploy: npm run build:vinext && npm run deploy:vinext. npm run dev:vinext runs it locally on port 3001.
Each request on Workers opens its own MongoDB connection and closes it when the response is done; Node, Docker and Vercel keep one shared connection.
Vercel
Import the repository, set the variables above for Production, and connect Inngest (its Vercel integration sets both keys). vercel.json pins functions to Mumbai (bom1), next to the hosted database; change it to the region nearest yours.
🧱 Project structure
app/
(marketing)/ public pages: landing, about, help, api-docs, sponsor, love, changelog, terms, /s/[ticker], /compare
(auth)/ sign-in, sign-up, forgot-password, reset-password
(root)/ the signed-in app: dashboard, watchlist, stocks/[symbol], profile
api/ auth/[...all] (Better Auth), inngest (background jobs), quotes (live prices)
components/ shell/ (sidebar, tabs), stocks/, watchlist/, landing/, marketing/, sponsors/, forms/, ui/ (shadcn)
database/ MongoDB connection and models (watchlist, named lists, alert)
lib/
actions/ server actions: auth, profile, watchlist, named lists, alerts, Finnhub, Yahoo, sentiment, scored news
better-auth/ auth setup (connects to MongoDB on first use, so builds need no database)
inngest/ background jobs and AI prompts
nodemailer/ email sending and templates
markets.ts the dashboard's markets market-data.ts cached vs realtime
changelog.ts releases and contributor credits sponsors.ts sponsors and tiers
rate-limit.ts MongoDB-backed limits for auth and live quotes
i18n/, messages/ next-intl setup and the English, Polish and Arabic strings
middleware.ts public marketing, /s and /compare pages; app pages redirect to sign-in
scripts/ check-env.mjs, test-db.mjs, and one-off maintenance scripts
__tests__/ Vitest tests
📡 How it works
Finnhub: search, quotes, company profiles and news. Responses are cached and shared (for an hour, or 15 seconds in realtime mode), with timeouts and a key pool, so a slow upstream never hangs a page.
TradingView: the chart, heatmap, financials, technicals and profile widgets.
Yahoo Finance: delayed quotes for Saudi Arabia and Poland on the dashboard, stock pages and watchlist.
Adanos (optional): the sentiment card.
AlphAI (optional): the scored news card.
Better Auth with MongoDB: accounts and sessions. Pages and server actions check the session on the server; the middleware only redirects signed-out visitors.
Inngest runs the background jobs:
Job
When
AI-personalised welcome email
On sign-up
Price alert check
Every 5 minutes, in realtime mode
Weekly news digest (a Kit broadcast)
Mondays at 09:00 UTC
Email: Nodemailer (Gmail) sends welcome, alert and password-reset emails; Kit sends the weekly digest.
🌍 Market support
Market
Charts (TradingView embeds)
Quotes, watchlist prices, alerts (Finnhub free)
🇺🇸 United States
Live
Yes
Crypto (Binance pairs)
Live
Yes
Forex
Live
No
🇨🇦 Canada, 🇦🇺 Australia
Delayed
No
🇸🇦 Saudi Arabia (Tadawul)
Blocked; delayed Yahoo Finance quotes instead
No
🇵🇱 Poland (GPW Warsaw)
End of day; delayed Yahoo Finance quotes on the dashboard
No
🇮🇳 India (BSE; .NS symbols chart on BSE), 🇩🇪 Germany
End of day
No
London, Tokyo, Hong Kong, Korea and others
Candles blocked; financials, technicals and profile work
No
The full table, and why some markets are limited, is in MARKET_SUPPORT.md.
🧪 Scripts and tests
Command
What it does
npm run dev
Development server (Turbopack)
npm run build, npm start
Production build and server
npm test
Vitest tests (npm run test:watch to keep watching)
npm run lint
ESLint
npx tsc --noEmit
Type check. Builds skip type errors, so run this before opening a PR
npm run test:db
Checks the MongoDB connection
node scripts/check-env.mjs
Checks your .env
🤝 Contributing
You belong here. Whether you’re a student, a self-taught dev or a seasoned engineer, contributions are welcome.
Pick a good first issue, or open an issue to talk about an idea or a bug first.
Fork the repo, branch from main, then npm ci and cp .env.example .env.
Keep the pull request focused: a test for new logic, a screenshot for UI changes.
Before you open it, run npm test, npx tsc --noEmit and npm run lint.
Every merged pull request, and every issue that leads to a fix, is credited on the changelog and below. Be kind, guide beginners, no gatekeeping: that’s the Open Dev Society way. Participation is covered by the Code of Conduct.
🏆 Contributors
OpenStock is built by everyone below: the people who wrote the code and the people whose issues led to a fix. Every release, and who made it happen, is on the changelog.
@ravixalgorithm founded and maintains OpenStock, and built it from the ground up: authentication, UI design, API and AI integration, and deployment.
Also thanks to Priyanshuu00007, who designed the OpenStock logo and visual identity, and koevoet1221, who fixed the MongoDB Docker build. Their GitHub accounts are no longer available, so they aren’t linked above.
Want to be here? Pick a good first issue or report a bug you hit.
🛡️ Security
Found a vulnerability? Please don’t open a public issue. Report it privately on GitHub; we’ll work on a fix with you and credit you.
📜 License
OpenStock is and will remain free and open for everyone. It’s licensed under AGPL-3.0: if you modify, redistribute or deploy it (including as a web service), you must release your source code under the same license and credit the original authors.
🌱 Open Dev Society manifesto
We live in a world where knowledge is hidden behind paywalls. Where tools are locked in subscriptions. Where information is twisted by bias. Where newcomers are told they’re not “good enough” to build.
We believe there’s a better way.
Our belief: technology should belong to everyone. Knowledge should be open, free and accessible. Communities should welcome newcomers with trust, not gatekeeping.
Our mission: build free, open-source projects that make a real difference: tools professionals and students can use without barriers, knowledge platforms where learning is free forever, communities where every beginner is guided, not judged, and resources that run on trust, not profit.
Our promise: we will never lock knowledge. We will never charge for access. We will never trade trust for money. We run on transparency, donations and the strength of our community.
Our call: if you’ve ever felt you didn’t belong, struggled to find free resources, or wanted to build something meaningful, you belong here.
Because the future belongs to those who build it openly.
🙏 Acknowledgements
Finnhub for accessible market data, and TradingView for embeddable charts and widgets
OpenStock is free, open source and used by 13,000+ registered people. Keeping it that way costs money every month: hosting, the database, market data keys, AI and email, and the hours that go into reviewing pull requests and shipping fixes.
How OpenStock is funded
OpenStock Cloud will pay for hosting. Cloud ($5 a month, coming soon) adds live quotes and email price alerts. Its subscribers will cover the servers, database and market data the hosted app needs, so the free site stays online without depending on donations.
Sponsors keep the community moving. Sponsorships pay for the time behind OpenStock: reviewing community pull requests, fixing bugs and shipping features at the pace 13,000+ people expect, with the core free for everyone. Self-hosting stays free, with every feature.
Pick a tier. Each link opens GitHub Sponsors with the amount already selected. Cancel any time.
评论