Build a Go-Powered Automated Stock Screener with SQLite and Vue3 Visualization
This article presents version 2.0 of a Go-based stock analysis system that upgrades data storage to SQLite, adds MA/MACD indicators, modular strategy engines, daily scheduling, and a Vue3 front‑end, providing full code snippets, configuration examples, and deployment instructions.
Overview
The project is a Go‑based stock analysis system (version 2.0) that replaces CSV storage with SQLite , automatically computes technical indicators (MA5/10/20/30, MACD), modularizes the strategy engine, schedules daily updates at 15:00, and provides a Vue3 front‑end for visualizing results.
System Architecture
The system is divided into the following modules:
Fetcher : pulls K‑line data from the Sina Finance API.
Indicator : calculates moving averages and MACD.
Storage : persists raw data and analysis results in SQLite.
Strategy : modular engine supporting MA, MACD, composite, and DSL strategies.
Scheduler : runs the update job daily at 15:00.
Web : exposes a RESTful API.
Frontend : Vue3 UI for result display and DSL testing.
Project Structure
backend/
├── main.go
├── config/ # configuration files
│ └── config.yaml
├── fetcher/ # data fetching
├── indicator/ # technical indicators
├── storage/ # SQLite handling
├── strategy/ # strategy engine
├── scheduler/ # scheduled tasks
└── web/ # API service
frontend/
├── src/
│ ├── views/
│ │ ├── ResultView.vue
│ │ └── DSLTester.vue
│ └── components/
│ └── StockChart.vueConfiguration‑Driven Strategies
All strategies are enabled via a YAML file:
# backend/config/config.yaml
database: "stock.db"
update_time: "15:00"
strategies:
- type: "MA"
ma: 20
hold_days: 3
- type: "MACD"
- type: "Composite"
hold_days: 3
- type: "DSL"
expr: "close > ma20 and macd_dif > macd_dea"Data Fetching and Storage
Fetch Historical Data
// fetcher/fetcher.go
url := fmt.Sprintf(
"http://money.finance.sina.com.cn/quotes_service/api/json_v2.php/CN_MarketData.getKLineData?symbol=%s&scale=240&ma=5&datalen=120",
stockCode,
)Sample JSON response from the API:
[{ "day":"2025-04-10", "open":"10.18", "high":"10.18", "low":"9.91", "close":"10.00", "volume":"78108087" }]SQLite Table Schema
CREATE TABLE IF NOT EXISTS kline (
code TEXT,
day TEXT,
open REAL, high REAL, low REAL, close REAL, volume INTEGER,
ma5 REAL, ma10 REAL, ma20 REAL, ma30 REAL,
dif REAL, dea REAL, macd REAL,
PRIMARY KEY(code, day)
);
CREATE TABLE IF NOT EXISTS results (
code TEXT,
day TEXT,
strategy TEXT,
PRIMARY KEY(code, day, strategy)
);Strategy Engine
All strategies implement a common interface:
type Strategy interface {
Name() string
Match(code string, klines []storage.KLine) bool
}MA Strategy
// Continuous N‑day closing price > MA20
ma := strategy.NewMAStrategy(20, 3)MACD Strategy
// Detect DIF crossing above DEA (golden cross)
macd := strategy.NewMACDStrategy()Composite Strategy
// Require both MA20 and MACD golden cross
combo := strategy.NewCompositeStrategy(3)DSL Strategy
// User‑defined expression for flexible conditions
dsl := strategy.NewDSLStrategy("close > ma20 and macd_dif > macd_dea")Scheduling and Tasks
// scheduler/scheduler.go
func ScheduleDailyUpdate(stocks []string) {
gocron.Every(1).Day().At("15:00").Do(func() {
UpdateAndAnalyze(stocks)
})
}
// At startup, fetch 120 days of history and then run incremental updates daily at 15:00.Web API
Return Screening Results
r.GET("/api/results", func(c *gin.Context) {
results := storage.LoadResults()
c.JSON(200, results)
})Test DSL Strategy
r.POST("/api/dsl/test", func(c *gin.Context) {
var req struct { Expr string }
c.BindJSON(&req)
strat := strategy.NewDSLStrategy(req.Expr)
matched := strat.Match("sz000001", storage.GetKLines("sz000001"))
c.JSON(200, gin.H{"match": matched})
})Frontend Visualization (Vue3)
ResultView.vue : displays the latest screening results in a table or list.
StockChart.vue : renders K‑line charts using ECharts.
DSLTester.vue : allows users to input a DSL expression and see real‑time matching results.
Deployment
# Start backend
cd backend
go run main.go
# Start frontend
cd ../frontend
npm install
npm run devOpen http://localhost:5173 in a browser to view the UI.
Project Highlights
Configuration‑driven, modular strategy engine.
Automated daily scheduling for hands‑free operation.
SQLite storage enables easy back‑testing and analysis.
Front‑end/back‑end separation with Vue3 visualization.
GitHub Repository
https://github.com/louis-xie-programmer/go-stock-analyzer
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Code Wrench
Focuses on code debugging, performance optimization, and real-world engineering, sharing efficient development tips and pitfall guides. We break down technical challenges in a down-to-earth style, helping you craft handy tools so every line of code becomes a problem‑solving weapon. 🔧💻
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
