Personal API and exports
Personal API
Get your own portfolios, stats, P&L positions, watchlists, cards and charts into a script, a spreadsheet or another app. Make a key (signed in with Discord), then send it with every request:
Authorization: Bearer lgf_…
X-API-Key: lgf_… works too. For spreadsheets, which can't send headers, add key=lgf_… to the address (it can end up in browser history and logs, so use a key just for that). Answers are JSON unless noted; errors are { error } with a 4xx status, plus choices when a name didn't match. Prices are delayed, as on the site.
- GET /api/v1/me/api/v1/meWhose key it is, what you've saved, and your limits. Use it to check a key works.
- GET /api/v1/portfolios/api/v1/portfoliosEvery portfolio with its totals at the latest prices: value, cost, P&L, today's change, realized gains.
- GET /api/v1/portfolios/<name or number>/api/v1/portfolios/1One portfolio: totals; every holding with value, weight, today's change and P&L; weight by sector; realized gains; earnings and ex-dividend dates in the next 30 days.format=csv for the holdings as CSV
- GET /api/v1/pnl/api/v1/pnlYour saved P&L positions valued now: strategy, cost to open, model value, P&L.
- GET /api/v1/pnl/<symbol>/api/v1/pnl/TSLAOne P&L position with its legs (strikes, expiries, prices) and value now.
- GET /api/v1/watchlists/api/v1/watchlistsYour watchlists and their symbols.
- GET /api/v1/watchlists/<name or number>/api/v1/watchlists/1One watchlist with each symbol's latest price, change, volume, market cap, P/E and 52-week range.format=csv
- GET /api/v1/cards/<kind>/api/v1/cards/portfolio?q=1The PNG card, as in the Share menu and the bot.kind = portfolio, pnl, positions or watchlist; q = name or symbol; hide=1 for percentages only
- GET /api/v1/charts/api/v1/chartsYour chart setups (type, indicators, lengths, colours), the settings your charts start from, and which symbols have drawings.
- GET /api/v1/charts/<symbol>/api/v1/charts/NVDAYour drawings on a symbol: kind, points (unix seconds and price), style and notes.
- GET /api/v1/charts/<symbol>/image/api/v1/charts/NVDA/image?range=6MYour chart as a PNG: your chart type, overlays, colours and drawings. Indicator panes (RSI, MACD…) aren't drawn.range = 1D … MAX (default 1Y); interval; setup = a setup's name, or default; drawings=0 to leave yours off
import requests
KEY = "lgf_…" # from Your API Keys
api = requests.Session()
api.headers["Authorization"] = f"Bearer {KEY}"
for p in api.get("https://finance.lastguardbot.com/api/v1/portfolios").json()["portfolios"]:
print(p["name"], p["value"], f'{p["day_pct"]:+.2f}%')
png = api.get("https://finance.lastguardbot.com/api/v1/charts/NVDA/image",
params={"range": "6M", "setup": "default"}).content
open("nvda.png", "wb").write(png)curl -H "Authorization: Bearer lgf_…" \
https://finance.lastguardbot.com/api/v1/portfolios/1
curl -H "Authorization: Bearer lgf_…" -o card.png \
"https://finance.lastguardbot.com/api/v1/cards/portfolio?q=1&hide=1"
=IMPORTDATA("https://finance.lastguardbot.com/api/v1/portfolios/1?format=csv&key=lgf_…")Only your own saved data is available. Market data for other symbols (quotes, charts, search, news) is served to this site's own pages and isn't part of the API.
Your API Keys
Checking sign-in…
Use It in Discord
lgf portfolioYour portfolios, P&L positions and watchlists, with today's valueslgf portfolio generate "My portfolio"Post a portfolio card (add --private for % only, --dm for your DMs)lgf portfolio add AAPL 10 182.50Add shares (current price if you leave the cost off; to <name> for another portfolio)lgf portfolio sell AAPL 5 at 190Sell shares; the sale goes into Realized Gainslgf portfolio eventsEarnings and ex-dividend dates for your holdingslgf pnl TSLAA saved P&L position with its payoff chart (lgf pnl for all of them)lgf watchlist cardYour watchlist as a card; add a name for a list saved herelgf leaderboardThis server's portfolio leaderboard (opt in from a portfolio's Share menu)lgf alertsettingsHow your alerts, daily card and move alerts reach you
Use your server's prefix in front (for example =lgf portfolio).
Exports on the Site
| What | Where | How |
|---|---|---|
| Chart images | Any price chart: right-click, Export | Save a PNG, copy the image, or send it to your Discord DMs or a server's alerts channel, with your drawings and indicators on it. |
| Chart links and data | Price chart: right-click, Export | A link that opens the exact chart; the visible range or every loaded bar as CSV. |
| Portfolio cards | Portfolio: Share | An image of a portfolio, with amounts or percentages only, downloaded or posted to Discord. You can also get one in your DMs every trading day. |
| Portfolio stats | Portfolio | Holdings and realized gains as CSV; holdings import from a broker's CSV. |
| P&L and watchlist cards | P&L calculator or Watchlist: Share | Card images, downloaded or posted to Discord. Watchlists also export as CSV. |
| Tables | Financials, options chains, the screener, backtests | Download what's on screen as CSV. |