Asset Quote API Worker
你的个人资产记账 App 行情聚合 API。它不保存资产数据,只负责拉行情、做汇率换算、返回估值结果。
Cloudflare Worker
Twelve Data
CoinGecko
Frankfurter
Gold API
基础地址
https://ledger.wweh.dpdns.org
如果你绑定了自己的域名,比如 api.xxx.com,那接口就是 https://api.xxx.com/api/...。
接口列表
| 功能 | 方法 | 路径 | 说明 |
|---|---|---|---|
| 健康检查 | GET | /api/health | 测试服务是否正常 |
| 配置说明 | GET | /api/config | 返回支持的资产类型和币种 |
| 汇率 | GET | /api/fx?base=USD"e=CNY&amount=700 | 查 USD/CNY,并返回换算后的金额 |
| 换算 | GET | /api/convert?from=USD&to=CNY&amount=700 | 金额换算 |
| 虚拟币 | GET | /api/crypto?ids=solana,bitcoin"e=CNY | 查 CoinGecko ID 的价格 |
| 黄金白银 | GET | /api/metal?symbol=XAU&unit=gram"e=CNY | XAU/XAG/XPT/XPD,支持克和金衡盎司 |
| 股票 ETF | GET | /api/stock?symbol=AAPL"e=CNY | 查 Twelve Data 股票价格并换算 |
| 资产组合估值 | POST | /api/portfolio/valuate | Flutter 最推荐用这个,一个接口算总资产、负债、净资产 |
直接测试
健康检查
curl "https://ledger.wweh.dpdns.org/api/health"
汇率
curl "https://ledger.wweh.dpdns.org/api/fx?base=USD"e=CNY&amount=700"
虚拟币
curl "https://ledger.wweh.dpdns.org/api/crypto?ids=solana,bitcoin,tether"e=CNY"
黄金
curl "https://ledger.wweh.dpdns.org/api/metal?symbol=XAU&unit=gram"e=CNY"
股票
curl "https://ledger.wweh.dpdns.org/api/stock?symbol=AAPL"e=CNY"
资产组合估值 Body 示例
{
"defaultCurrency": "CNY",
"assets": [
{
"id": "cash-1",
"type": "cash",
"name": "现金",
"quantity": 1000,
"currency": "CNY"
},
{
"id": "gold-1",
"type": "metal",
"name": "黄金",
"symbol": "XAU",
"quantity": 1,
"unit": "gram"
},
{
"id": "sol-1",
"type": "crypto",
"name": "SOL",
"symbol": "solana",
"quantity": 1
},
{
"id": "aapl-1",
"type": "stock",
"name": "Apple",
"symbol": "AAPL",
"quantity": 1
}
],
"liabilities": [
{
"id": "loan-1",
"name": "我欠朋友",
"direction": "payable",
"amount": 500,
"currency": "CNY"
},
{
"id": "receive-1",
"name": "朋友欠我",
"direction": "receivable",
"amount": 100,
"currency": "USD"
}
]
}
curl
curl -X POST "https://ledger.wweh.dpdns.org/api/portfolio/valuate" \
-H "content-type: application/json" \
-d '{
"defaultCurrency": "CNY",
"assets": [
{
"id": "cash-1",
"type": "cash",
"name": "现金",
"quantity": 1000,
"currency": "CNY"
},
{
"id": "gold-1",
"type": "metal",
"name": "黄金",
"symbol": "XAU",
"quantity": 1,
"unit": "gram"
},
{
"id": "sol-1",
"type": "crypto",
"name": "SOL",
"symbol": "solana",
"quantity": 1
},
{
"id": "aapl-1",
"type": "stock",
"name": "Apple",
"symbol": "AAPL",
"quantity": 1
}
],
"liabilities": [
{
"id": "loan-1",
"name": "我欠朋友",
"direction": "payable",
"amount": 500,
"currency": "CNY"
},
{
"id": "receive-1",
"name": "朋友欠我",
"direction": "receivable",
"amount": 100,
"currency": "USD"
}
]
}'
Flutter 调用示例
final res = await http.post(
Uri.parse('https://ledger.wweh.dpdns.org/api/portfolio/valuate'),
headers: {
'content-type': 'application/json',
// 'x-api-token': '你的 APP_API_TOKEN',
},
body: jsonEncode({
'defaultCurrency': 'CNY',
'assets': [
{'type': 'crypto', 'name': 'SOL', 'symbol': 'solana', 'quantity': 1},
{'type': 'metal', 'name': '黄金', 'symbol': 'XAU', 'quantity': 1, 'unit': 'gram'},
{'type': 'stock', 'name': 'Apple', 'symbol': 'AAPL', 'quantity': 1},
],
'liabilities': [
{'name': '我欠朋友', 'direction': 'payable', 'amount': 500, 'currency': 'CNY'},
],
}),
);
资产类型格式
现金
{"type":"cash","name":"现金","quantity":1000,"currency":"CNY"}
手动估值
{"type":"manual","name":"房租押金","quantity":1,"manualPrice":3000,"currency":"CNY"}
虚拟币
{"type":"crypto","name":"SOL","symbol":"solana","quantity":1}
黄金
{"type":"metal","name":"黄金","symbol":"XAU","quantity":1,"unit":"gram"}
股票 / ETF
{"type":"stock","name":"Apple","symbol":"AAPL","quantity":1}
借款 / 应收
{"name":"我欠朋友","direction":"payable","amount":500,"currency":"CNY"}
{"name":"朋友欠我","direction":"receivable","amount":100,"currency":"USD"}