Financial Data Connector v2.0 (Data Bridge)
Use the built-in dataBridgePull() function to retrieve financial data,no need to hand-write XHR。
Retrieve comprehensive financial data
var resp = dataBridgePull("yahoo-finance", "stock_info", { ticker: "AAPL" });
if (!resp || !resp.ok) return "获取数据失败: " + (resp ? resp.error : "网络错误");
var d = resp.data;
// d.summary — 公司概况
// d.keyStats — 估值指标
// d.incomeStatements — 历年损益表
// d.balanceSheets — 历年资产负债表
// d.cashFlows — 历年现金流量表
Retrieve historical prices
var resp = dataBridgePull("yahoo-finance", "stock_price", {
ticker: "AAPL",
range: "1y",
interval: "1d"
});
if (!resp || !resp.ok) return "获取价格数据失败";
var prices = resp.data.prices; // [{date, open, high, low, close, volume}, ...]
Data field reference
| Path | Field | Description |
|---|---|---|
d.summary |
shortName, sector, industry, currency, currentPrice, totalRevenue, grossProfit, netIncome, operatingCashflow, freeCashflow, totalCash, totalDebt, grossMargins, operatingMargins, profitMargins, ebitdaMargins, revenueGrowth, earningsGrowth, debtToEquity, returnOnEquity, returnOnAssets, fullTimeEmployees | Latest summary |
d.keyStats |
beta, trailingPE, forwardPE, priceToBook, enterpriseValue, enterpriseToRevenue, enterpriseToEbitda, pegRatio, sharesOutstanding, bookValue, dividendYield, marketCap | Valuation metrics |
d.incomeStatements[i] |
endDate, totalRevenue, costOfRevenue, grossProfit, operatingIncome, netIncome, ebit, ebitda, interestExpense, taxProvision, researchDevelopment, sellingGeneralAdministrative | Income statement |
d.balanceSheets[i] |
endDate, totalAssets, totalCurrentAssets, totalLiabilitiesNetMinorityInterest, totalCurrentLiabilities, stockholdersEquity, cashAndCashEquivalents, longTermDebt, totalDebt, netDebt, propertyPlantEquipment, inventory, receivables, minorityInterest | Balance sheet |
d.cashFlows[i] |
endDate, operatingCashFlow, capitalExpenditure, freeCashFlow, depreciationAndAmortization, changeInWorkingCapital | Cash flow |
Ticker format
| Market | Format | Example |
|---|---|---|
| US stocks | Direct ticker | AAPL, MSFT, TSLA |
| Hong Kong stocks | Ticker.HK | 0700.HK, 9988.HK |
| A-shares (Shanghai) | Ticker.SS | 601899.SS, 600519.SS |
| A-shares (Shenzhen) | Ticker.SZ | 000858.SZ, 002594.SZ |
Unit conversion (for modeling)
Yahoo Finance returns raw units (e.g., yuan); modeling uniformly uses millions:
function _n(v) { return (typeof v === "number" && isNaN(v)) ? 0 : (v == null ? 0 : v); }
function toM(v) { return _n(v) / 1000000; }
ws.Range("B3").Value2 = toM(d.incomeStatements[0].totalRevenue);
Important rules
- Use
dataBridgePull: Do not hand-write XHR; calldataBridgePull("yahoo-finance", "stock_info", { ticker: "..." }) - Check
resp.ok: Data retrieval may fail; must check - Unify units to millions: raw data ÷ 1,000,000, using the
toM()function - Secure data access:
d.incomeStatements && d.incomeStatements.length > 0 ? d.incomeStatements[0].totalRevenue : 0 - Field names are all camelCase
- Note suffixes for A-shares: Shanghai .SS, Shenzhen .SZ