Ghostfolio
Use this skill when the user asks about Ghostfolio portfolio metrics, holdings, dividends, or API troubleshooting.
Environment Variables
CODEBLOCK0
Auth Modes
Ghostfolio setups can differ. Support both modes:
Mode A — Direct bearer (works in some environments)
CODEBLOCK1
Mode B — Anonymous exchange (required in some environments)
CODEBLOCK2
Endpoint Templates
Portfolio performance
CODEBLOCK3
Holdings
CODEBLOCK4
Dividends
CODEBLOCK5
Quick connectivity + auth probe
CODEBLOCK6
Troubleshooting
- Token invalid for this auth mode, token expired, or wrong token type.
- Try the other auth mode (direct vs anonymous exchange).
- Token recognized but not authorized for the requested resources.
- Verify account/environment and permissions.
- - Timezone inconsistencies
- Send
x-ghostfolio-timezone (or at least
Timezone) explicitly.
- Prefer local URL (
http://127.0.0.1:3333) if service runs locally.
- For remote TLS diagnostics only, temporary
curl -k can help.
Safety Notes
- - Never print or commit real tokens in logs/docs.
- Keep tokens in environment variables only.
- Use
curl -fsS so HTTP/API errors are not silently ignored.
Ghostfolio
当用户询问关于Ghostfolio投资组合指标、持仓、股息或API故障排除时,使用此技能。
环境变量
bash
优先使用本地访问(如可用)
export GHOSTFOLIO
BASEURL=http://127.0.0.1:3333
远程示例(可选):
export GHOSTFOLIOBASEURL=https://rpi5.gate-mintaka.ts.net:8444
用户/管理员提供的长期令牌
export GHOSTFOLIO_TOKEN=...
可选但推荐
export GHOSTFOLIO_TIMEZONE=Europe/Paris
认证模式
Ghostfolio的配置可能有所不同。支持以下两种模式:
模式A — 直接Bearer令牌(在某些环境中有效)
bash
AUTHHEADER=Authorization: Bearer $GHOSTFOLIOTOKEN
模式B — 匿名交换(在某些环境中必需)
bash
AUTHTOKEN=$(curl -fsS $GHOSTFOLIOBASE_URL/api/v1/auth/anonymous \
-H Content-Type: application/json \
--data {\accessToken\:\$GHOSTFOLIO_TOKEN\} \
| jq -r .authToken)
[ -n $AUTHTOKEN ] && [ $AUTHTOKEN != null ] || {
echo 获取authToken失败 >&2
exit 1
}
AUTHHEADER=Authorization: Bearer $AUTHTOKEN
端点模板
投资组合表现
bash
curl -fsS $GHOSTFOLIOBASEURL/api/v2/portfolio/performance?range=ytd \
-H $AUTH_HEADER \
-H Accept: application/json \
-H x-ghostfolio-timezone: $GHOSTFOLIO_TIMEZONE \
| jq .
持仓
bash
curl -fsS $GHOSTFOLIOBASEURL/api/v1/portfolio/holdings?range=ytd \
-H $AUTH_HEADER \
-H Accept: application/json \
-H x-ghostfolio-timezone: $GHOSTFOLIO_TIMEZONE \
| jq .
股息
bash
curl -fsS $GHOSTFOLIOBASEURL/api/v1/portfolio/dividends?groupBy=month&range=ytd \
-H $AUTH_HEADER \
-H Accept: application/json \
-H x-ghostfolio-timezone: $GHOSTFOLIO_TIMEZONE \
| jq .
快速连接与认证探测
bash
1) 首先尝试直接Bearer令牌
for ep in \
/api/v2/portfolio/performance?range=ytd \
/api/v1/portfolio/holdings?range=ytd \
/api/v1/portfolio/dividends?groupBy=month&range=ytd
do
code=$(curl -s -o /tmp/gf
probe.json -w %{httpcode} $GHOSTFOLIO
BASEURL$ep \
-H Authorization: Bearer $GHOSTFOLIO_TOKEN \
-H Accept: application/json \
-H x-ghostfolio-timezone: $GHOSTFOLIO_TIMEZONE)
echo 直接 $ep -> $code
done
2) 如果直接访问返回401/403,尝试匿名交换
AUTH
TOKEN=$(curl -fsS $GHOSTFOLIOBASE_URL/api/v1/auth/anonymous \
-H Content-Type: application/json \
--data {\accessToken\:\$GHOSTFOLIO_TOKEN\} | jq -r .authToken)
echo 匿名交换令牌存在:$([ -n $AUTHTOKEN ] && [ $AUTHTOKEN != null ] && echo 是 || echo 否)
故障排除
- 令牌对此认证模式无效、令牌已过期或令牌类型错误。
- 尝试另一种认证模式(直接与匿名交换)。
- 令牌已被识别但无权访问请求的资源。
- 验证账户/环境和权限。
- 明确发送x-ghostfolio-timezone(或至少Timezone)。
- 如果服务在本地运行,优先使用本地URL(http://127.0.0.1:3333)。
- 仅用于远程TLS诊断时,临时使用curl -k可能有帮助。
安全注意事项
- - 切勿在日志或文档中打印或提交真实令牌。
- 令牌仅保存在环境变量中。
- 使用curl -fsS以确保HTTP/API错误不会被静默忽略。