@pi-stef/finance

extensionmaintained

Pi extension client for @pi-stef/finance-api: exposes portfolio state, drift, and deterministic suggestions to the pi agent.

by · v0.3.1 · published 2w ago

$ pi install npm:@pi-stef/finance
downloads/mo
0
stars
9
last push
1d ago
open issues
0

Signals

license: MITtestspi manifest: missinginstall size: —deps: 0peer deps: 0

Download trend

1.5K downloads · last 12 weeks (weekly)

README

@pi-stef/finance

Pi extension client for @pi-stef/finance-api — exposes portfolio state, drift, and deterministic suggestions to the pi agent.

Install

pi install npm:@pi-stef/finance

Or via catalog:

/ct add npm:@pi-stef/finance

Prerequisites

The @pi-stef/finance-api service must be running (Docker or native) and you must have its bearer token. See the finance-api README for service setup, or the docs-site guide.

Full documentation: docs-site/packages/finance.md

Configuration

The extension reads its config from ~/.pi/sf/finance/config.json, or from environment variables (prefix SF_FINANCE_):

{
  "apiUrl": "http://127.0.0.1:7780",
  "token": "your-bearer-token",
  "providers": {
    "snaptrade": {
      "clientId": "PERS-...",
      "consumerKey": "<your personal consumer key>"
    },
    "simplefin": {
      "setupToken": "aHR0cHM6Ly9iZXRhLWJyaWRnZS5zaW1wbGVmaW4ub3JnL3NpbXBsZWZpbi9jbGFpbS8uLi4="
    }
  }
}
FieldEnv overrideDefaultDescription
apiUrlSF_FINANCE_API_URLhttp://127.0.0.1:7780finance-api service URL
tokenSF_FINANCE_TOKEN(auto-read from ~/.pi/sf/finance/token)Bearer token for API auth
providers.snaptrade.clientIdPersonal SnapTrade client ID (see SnapTrade setup)
providers.snaptrade.consumerKeyPersonal SnapTrade consumer key
providers.simplefin.setupTokenOne-time SimpleFIN setup token (see SimpleFIN setup)
providers.simplefin.accessUrlPersistent SimpleFIN access URL (auto-set after first sync)

Where does the token come from? The finance-api service auto-generates a token on first start and writes it to ~/.pi/sf/finance/token. When the extension runs on the same host, it reads that file automatically — you usually don't need to set token at all. In Docker, retrieve it with docker compose exec finance-api cat /root/.pi/sf/finance/token and copy it into config.json.

SnapTrade credentials live here, not in the server. SnapTrade uses a Personal API key that flows per-call: the extension attaches clientId + consumerKey to each /v1/sync request, and the server uses them for that single tick and stores nothing. This lets one finance-api deployment serve different SnapTrade users. See SnapTrade setup for how to obtain them.

SimpleFIN credentials live here too. SimpleFIN uses a one-time setup token that the server exchanges for a persistent access URL on the first sync. The extension automatically writes the resolved accessUrl back to config.json, replacing the setupToken. See SimpleFIN setup for details.

Tools

The extension exposes these tools to the pi agent:

ToolDescription
sf_fin_market_statusGet current US market session
sf_fin_get_holdingsGet all account holdings
sf_fin_get_net_worthGet total portfolio value
sf_fin_get_driftGet allocation drift vs target
sf_fin_get_allocationGet current asset allocation
sf_fin_list_goalsList investment goals
sf_fin_set_targetCreate/update investment goal
sf_fin_get_suggestionsGet pending suggestions
sf_fin_dismiss_suggestionDismiss a suggestion
sf_fin_sync_nowTrigger a data sync (all providers, or one via provider)
sf_fin_import_fileImport holdings/transactions from a CSV/OFX file
sf_fin_historyGet price history

sf_fin_sync_now

Triggers a data sync: ingest from providers, refresh prices, recompute suggestions.

ParameterTypeRequiredDescription
providerstringnoProvider ID to sync (e.g. snaptrade, simplefin). Omit to sync all providers.

Behavior:

  • No provider arg → syncs all providers. If providers.snaptrade and/or providers.simplefin are configured, their credentials are attached so they run alongside any server-side providers.
  • provider: "snaptrade" → syncs only SnapTrade, attaching your key.
  • provider: "snaptrade" but no key configured → sends the scoped request with no credentials; the server skips SnapTrade (silent no-op).
  • provider: "simplefin" → syncs only SimpleFIN, attaching your setupToken or accessUrl.
  • provider: "simplefin" but no creds configured → scoped request with no credentials; the server skips SimpleFIN (silent no-op).

SimpleFIN auto-persist: On the first sync with a setupToken, the server exchanges it for an accessUrl and returns it in the response. The extension automatically writes the accessUrl to config.json, replacing the setupToken. You never need to manually update the config after the first sync.

sf_fin_import_file

Imports holdings (CSV) or transactions + balance (OFX) from a file. The format is detected from the extension/contents. See the File Import guide for accepted formats.

ParameterTypeRequiredDescription
filePathstringyesAbsolute or relative path to the CSV/OFX file

Slash Commands

Every tool has a matching slash command (kebab-case). Type /sf-fin- in pi to see autocomplete.

CommandArgsExample
/sf-fin-market-status/sf-fin-market-status
/sf-fin-get-holdingsoptional symbol/sf-fin-get-holdings AAPL
/sf-fin-get-net-worth/sf-fin-get-net-worth
/sf-fin-get-drift/sf-fin-get-drift
/sf-fin-get-allocation/sf-fin-get-allocation
/sf-fin-list-goals/sf-fin-list-goals
/sf-fin-set-target— (wizard)/sf-fin-set-target
/sf-fin-get-suggestions/sf-fin-get-suggestions
/sf-fin-dismiss-suggestionsuggestion ID/sf-fin-dismiss-suggestion rebalance-1
/sf-fin-sync-nowoptional provider/sf-fin-sync-now snaptrade
/sf-fin-import-filefile path/sf-fin-import-file ~/Downloads/positions.csv
/sf-fin-historysymbol/sf-fin-history AAPL

Usage

Ask the pi agent:

  • "What's my current portfolio allocation?"
  • "How far am I from my target allocation?"
  • "What should I buy/sell to rebalance?"
  • "Sync my SnapTrade accounts"
  • "Sync my SimpleFIN bank accounts"
  • "Import the positions CSV at ~/Downloads/positions.csv"

Disclaimer

This is not financial advice. The suggestions are computed deterministically from your configured goals and current holdings. The LLM applies judgment but never recomputes the numbers. Always consult a qualified financial advisor before making investment decisions.

License

MIT