Initial commit: A-share stock analysis project with screening, backtesting, and multi-factor analysis tools
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { tool } from "@opencode-ai/plugin";
|
||||
import path from "path";
|
||||
|
||||
const SCRIPTS_DIR = (ctx: { worktree: string }) =>
|
||||
path.join(ctx.worktree, "scripts");
|
||||
|
||||
async function runPython(
|
||||
ctx: { worktree: string },
|
||||
script: string,
|
||||
fn: string,
|
||||
args: Record<string, unknown>,
|
||||
): Promise<string> {
|
||||
const scriptPath = path.join(SCRIPTS_DIR(ctx), script);
|
||||
const argsJson = JSON.stringify(args);
|
||||
const result = await Bun.$`python3 ${scriptPath} ${fn} ${argsJson}`.text();
|
||||
return result.trim();
|
||||
}
|
||||
|
||||
export const quote = tool({
|
||||
description: "Get daily/weekly K-line and real-time quotes for a stock",
|
||||
args: {
|
||||
symbol: tool.schema.string().describe("Stock code (e.g. 600519 for Kweichow Moutai)"),
|
||||
period: tool.schema.enum(["daily", "weekly", "monthly"]).default("daily").describe("K-line period"),
|
||||
start_date: tool.schema.string().optional().describe("Start date YYYYMMDD, defaults to 90 days ago"),
|
||||
end_date: tool.schema.string().optional().describe("End date YYYYMMDD, defaults to today"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
return runPython(context, "market_data.py", "quote", args);
|
||||
},
|
||||
});
|
||||
|
||||
export const financial = tool({
|
||||
description: "Get financial statement indicators for a stock",
|
||||
args: {
|
||||
symbol: tool.schema.string().describe("Stock code (e.g. 600519)"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
return runPython(context, "market_data.py", "financial", args);
|
||||
},
|
||||
});
|
||||
|
||||
export const moneyflow = tool({
|
||||
description: "Get capital flow data (main fund, northbound) for a stock",
|
||||
args: {
|
||||
symbol: tool.schema.string().describe("Stock code (e.g. 600519)"),
|
||||
days: tool.schema.number().default(10).describe("Number of recent days"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
return runPython(context, "market_data.py", "moneyflow", args);
|
||||
},
|
||||
});
|
||||
|
||||
export const news = tool({
|
||||
description: "Get recent news and announcements for a stock",
|
||||
args: {
|
||||
symbol: tool.schema.string().describe("Stock code (e.g. 600519)"),
|
||||
limit: tool.schema.number().default(20).describe("Max number of news items"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
return runPython(context, "sentiment.py", "news", args);
|
||||
},
|
||||
});
|
||||
|
||||
export const index = tool({
|
||||
description: "Get major A-share index data (Shanghai Composite, Shenzhen Component, ChiNext)",
|
||||
args: {
|
||||
index_code: tool.schema.enum(["sh", "sz", "cyb", "all"]).default("all").describe("Index to fetch"),
|
||||
days: tool.schema.number().default(30).describe("Number of recent trading days"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
return runPython(context, "market_data.py", "index", args);
|
||||
},
|
||||
});
|
||||
|
||||
export const sector = tool({
|
||||
description: "Get sector/industry performance and ranking",
|
||||
args: {
|
||||
date: tool.schema.string().optional().describe("Date YYYYMMDD, defaults to latest"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
return runPython(context, "market_data.py", "sector", args);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user