Skip to content
LAST GUARD

Personal API and exports

API

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/me
    Whose key it is, what you've saved, and your limits. Use it to check a key works.
  • GET /api/v1/portfolios
    /api/v1/portfolios
    Every 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/1
    One 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/pnl
    Your saved P&L positions valued now: strategy, cost to open, model value, P&L.
  • GET /api/v1/pnl/<symbol>
    /api/v1/pnl/TSLA
    One P&L position with its legs (strikes, expiries, prices) and value now.
  • GET /api/v1/watchlists
    /api/v1/watchlists
    Your watchlists and their symbols.
  • GET /api/v1/watchlists/<name or number>
    /api/v1/watchlists/1
    One 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=1
    The 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/charts
    Your 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/NVDA
    Your 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=6M
    Your 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
Python
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 and Google Sheets
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.

API

Your API Keys

Checking sign-in…

BOT

Use It in Discord

  • lgf portfolioYour portfolios, P&L positions and watchlists, with today's values
  • lgf 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 Gains
  • lgf portfolio eventsEarnings and ex-dividend dates for your holdings
  • lgf 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 here
  • lgf 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).

API

Exports on the Site

WhatWhereHow
Chart imagesAny price chart: right-click, ExportSave 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 dataPrice chart: right-click, ExportA link that opens the exact chart; the visible range or every loaded bar as CSV.
Portfolio cardsPortfolio: ShareAn 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 statsPortfolioHoldings and realized gains as CSV; holdings import from a broker's CSV.
P&L and watchlist cardsP&L calculator or Watchlist: ShareCard images, downloaded or posted to Discord. Watchlists also export as CSV.
TablesFinancials, options chains, the screener, backtestsDownload what's on screen as CSV.
HELP

Keyboard shortcuts & functions

Anywhere

/ or Ctrl K
Focus the command line
?
Show this help
Esc
Close menus and dialogs

Command line

AAPL
Open a security
WEI
Open a function
NVDA GP
Ticker + function
↑ ↓ Enter
Pick a suggestion

Charts (click the chart first)

Right-click / Shift F10
Alerts, drawings, measure, export
Alt A
Alert at the cursor price
Alt H
Horizontal line
Alt T
Trend line
Alt F
Fibonacci retracement
Alt V
Vertical line
Del
Delete the selected drawing
Ctrl Z
Undo the last drawing change
Alt R
Reset to the chosen range
Esc
Stop drawing / deselect
Scroll · drag
Zoom · pan

Function codes

  • WEIWorld equity indices & cross-asset
  • BRIEFMarket brief for today
  • WCLKWorld markets clock
  • HMAPMarket heatmap
  • MOSTMovers & most active
  • SCRNStock screener
  • TECHTechnical signals (S&P 500)
  • ECALEarnings calendar
  • EAEarnings season scorecard
  • ECOEconomic calendar
  • ECSTUS economic statistics
  • IPOIPO calendar
  • DVDDividends & splits
  • CURVTreasury yield curve
  • WIRPFed rate expectations (futures)
  • CBCentral bank policy rates
  • FXCFX cross rates & pairs
  • CMDTYCommodity futures
  • CRYPCrypto board
  • SECTSector & industry performance
  • RRGSector rotation
  • CORRCorrelation matrix
  • BRDHBreadth of the S&P 500
  • FGFear & greed gauge
  • VOLVolatility (VIX term structure)
  • CONGCongress trades (House PTRs)
  • CNBCongress notice board (changed & removed reports)
  • UOAUnusual options activity
  • UPDNAnalyst upgrades & downgrades
  • TOPNews wire (top stories)
  • GPPrice chart
  • DESDescription & key stats
  • ANRAnalyst ratings & targets
  • CNCompany news
  • SEASSeasonality
  • FAFinancial statements
  • EEEarnings & estimates
  • FUNDFund holdings & profile
  • OMONOptions chain, IV & gamma
  • PNLP&L calculator & scenarios
  • ODDSOdds from option prices
  • DCFValuation (discounted cash flow)
  • RVRelative value vs peers
  • HDSHolders (institutions & funds)
  • ANLGAnalogs from price history
  • INSDInsider activity
  • WATCHWatchlists
  • PORTPortfolio tracker
  • COMPCompare performance
  • MULTMulti-chart layout
  • STRSStress test through past crises
  • BTBacktest a strategy
  • ALRTAlerts & chart drawings
  • APIPersonal API & exports
  • LOGWhat's new (changelog)