Trade Analyzer MCP tools

Server URL: https://app.trade-analyzer.com/mcp. Add it as a custom connector in Claude or another MCP client; on the first connection you sign in with GitHub and allow access. The tools read and annotate your own trading data; amounts are in the account's base currency. Not affiliated with Interactive Brokers.

accounts · Accounts read

The user's broker accounts with their broker, account ID, whether a token is stored for loading data, whether it is a file account, and the loaded date ranges. Pass the account ID as account to the other tools; without it they use the account of the most recent report.

Input

None.

Output

FieldTypeDescription
accountsobject[] {name, broker, account, canLoad, fileAccount, baseCurrency, ranges}

create_account · Create a file account write

Creates a file account, filled from statements and files of any bank with add_rows, and returns it with its account ID. Keep one account per bank, named after it (e.g. "flatex", "Trade Republic"), unless the user wants otherwise; check accounts first so you do not create one twice. IB accounts are created in the web app.

Input

ParameterTypeRequiredDescription
namestringyesName the user sees, e.g. the bank
currencystringAccount currency (default EUR); statements settle in it

Output

FieldTypeDescription
namestring
brokerstring
accountvalue
canLoadbooleanA token is stored, sync_reports can load missing days
fileAccountbooleanFilled from files and statements of any bank; add rows with add_rows
baseCurrencyvalueAccount currency; null for IB until the first report
rangesobject[] {from, to}

rename_account · Rename an account write

Gives an account (file or IB account) a new name; its account ID, files and data stay.

Input

ParameterTypeRequiredDescription
accountstringyesAccount ID from accounts
namestringyes

Output

FieldTypeDescription
namestring
brokerstring
accountvalue
canLoadbooleanA token is stored, sync_reports can load missing days
fileAccountbooleanFilled from files and statements of any bank; add rows with add_rows
baseCurrencyvalueAccount currency; null for IB until the first report
rangesobject[] {from, to}

data_coverage · Loaded data read

Which IB accounts and date ranges are loaded, and what is missing in a period. Call this first to know which periods can be analysed; load missing ones with sync_reports.

Input

ParameterTypeRequiredDescription
fromstringStart date YYYY-MM-DD (default: first loaded day)
tostringEnd date YYYY-MM-DD (default: last loaded day)
accountstringIB account ID if the user has several (default: account of the most recent report)

Output

FieldTypeDescription
accountstring
accountsstring[]
rangesobject[] {from, to}
periodobject {from, to}
missingobject[] {from, to}Not loaded and not being loaded; always empty for a file account (CSV), which has nothing to load
busyobject[] {from, to}Being loaded right now by another request

sync_reports · Load missing days from IB write

Loads missing days of a period from IB with the stored Flex token (at most 365 days per IB request, up to the last day IB has closed; each request takes 10 to 60 seconds, at most three per call). Data is available from the account opening on. Ranges another job is loading are skipped and listed in busy.

Input

ParameterTypeRequiredDescription
fromstringyesCalendar date YYYY-MM-DD
tostringyesCalendar date YYYY-MM-DD
accountstringIB account ID if the user has several (default: account of the most recent report)

Output

FieldTypeDescription
errorvalue
remainingobject[] {from, to}
busyobject[] {from, to}Ranges another job is loading right now; call again when it is done
logstring[]

trading_summary · Trading summary read

Statistics of the trades closed in a period: batting average, average gain and loss in %, win/loss ratio, adjusted win/loss ratio, expectancy, holding days; net P/L of all sales in the period, partial exits included; per asset class and total, plus time- and money-weighted return and max drawdown. Amounts in the account base currency (field currency).

Input

ParameterTypeRequiredDescription
fromstringStart date YYYY-MM-DD (default: first loaded day)
tostringEnd date YYYY-MM-DD (default: last loaded day)
accountstringIB account ID if the user has several (default: account of the most recent report)
lossLimitnumberThreshold in percent for counting losses that are too large (default 8); does not change results

Output

FieldTypeDescription
accountstring
periodobject {from, to}
missingvalueDays of the period not loaded yet (call sync_reports), or null
currencyvalue
excludedTradesnumber
summaryobject {trades, winners, losers, battingAverage, avgGain, avgLoss, largestGain, largestLoss, avgDaysGains, avgDaysLosses, winLossRatio, adjustedWinLossRatio, expectancy, lossesOverLimit, totalPnl}
byClassrecord of object
returnsobject | null

monthly_tracker · Monthly tracker read

Per month: average gain and loss, win %, number of trades and average days of gains and losses of the trades closed in it; net P/L of all sales in the month, partial exits of positions still open included, and in % of the account value at the start of the month.

Input

ParameterTypeRequiredDescription
fromstringStart date YYYY-MM-DD (default: first loaded day)
tostringEnd date YYYY-MM-DD (default: last loaded day)
accountstringIB account ID if the user has several (default: account of the most recent report)
lossLimitnumberThreshold in percent for counting losses that are too large (default 8); does not change results
assetClassStocks · CFDs

Output

FieldTypeDescription
accountstring
periodobject {from, to}
missingvalueDays of the period not loaded yet (call sync_reports), or null
monthsobject[] {trades, winners, losers, battingAverage, avgGain, avgLoss, largestGain, largestLoss, avgDaysGains, avgDaysLosses, winLossRatio, adjustedWinLossRatio, expectancy, lossesOverLimit, totalPnl, month, netPnlPercent}

returns · Returns read

Monthly and period returns: time-weighted (like IB), money-weighted (Modified Dietz), max drawdown. Includes unrealized gains and losses. Amounts in the account base currency.

Input

ParameterTypeRequiredDescription
fromstringStart date YYYY-MM-DD (default: first loaded day)
tostringEnd date YYYY-MM-DD (default: last loaded day)
accountstringIB account ID if the user has several (default: account of the most recent report)

Output

FieldTypeDescription
accountstring
periodobject {from, to}
missingvalueDays of the period not loaded yet (call sync_reports), or null
twrnumberPercent, e.g. -3.5 for -3.5 %
moneyWeightedobject {result, averageCapital, percent}
maxDrawdownnumberPercent, e.g. -3.5 for -3.5 %
monthsobject[] {month, startValue, endValue, deposits, transfers, result, twr}

income · Income and taxes read

Dividends, interest, advance lump sums (German Vorabpauschale) and taxes of a file account in a period, as booked from its statements: totals per kind and every row, amounts in the account base currency (a tax refund is negative). net is dividends and interest minus all taxes, without advance lump sums. Not part of the P/L of a trade. IB accounts have no such rows yet.

Input

ParameterTypeRequiredDescription
fromstringStart date YYYY-MM-DD (default: first loaded day)
tostringEnd date YYYY-MM-DD (default: last loaded day)
accountstringIB account ID if the user has several (default: account of the most recent report)

Output

FieldTypeDescription
accountstring
periodobject {from, to}
missingvalueDays of the period not loaded yet (call sync_reports), or null
totalsobject {dividends, interest, advanceLumpSum, withholdingTax, capitalGainsTax, otherTax, net}
rowsobject[] {day, kind, symbol, name, currency, amount, amountInBase}

find_trades · Find trades read

Closed trades (round trips) of a period with the facts needed to judge them: entry and exit, holding days, cost basis, P/L and return, position size in % of the account value before entry, entries and exits, whether the position was added to while losing or winning, partial exits, commissions, and the user's tags and notes. Filter and sort to find e.g. the largest losses, losses beyond a limit, long-held losers or oversized positions. Use trade_detail for the price path of one trade.

Input

ParameterTypeRequiredDescription
fromstringStart date YYYY-MM-DD (default: first loaded day)
tostringEnd date YYYY-MM-DD (default: last loaded day)
accountstringIB account ID if the user has several (default: account of the most recent report)
symbolstring
assetClassStocks · CFDs
outcomewin · loss
maxReturnPctnumberOnly trades with a return at most this, e.g. -8 for losses of 8 % or more
minReturnPctnumber
minHoldingDaysnumber
maxHoldingDaysnumber
minPositionSizePctnumberOnly positions at least this large in % of the account value
addedWhileLosingboolean
tagstring
includeExcludedbooleanAlso trades the user excluded from the statistics (default false)
sortexit · return · pnl · holdingDays · positionSizeDefault exit date
descendingboolean
limitnumberDefault 50

Output

FieldTypeDescription
accountstring
periodobject {from, to}
missingvalueDays of the period not loaded yet (call sync_reports), or null
baseCurrencyvalue
matchingnumber
returnednumber
tradesobject[] {key, symbolKey, symbol, description, assetClass, direction, currency, entry, exit, holdingDays, firstEntryPrice, averageEntryPrice, averageExitPrice, quantity, costBasis, pnl, returnPct, positionSizePct, entries, exits, addedWhileLosing, addedWhileWinning, partialExits, commissions, tags, note, excluded}

trade_detail · Trade detail read

One trade in detail: all executions (with the distance to the first entry), the facts from find_trades and the daily price path from Yahoo: maximum adverse and favorable excursion while the trade was open and the price change 5, 20 and 60 trading days after the exit, plus the daily bars.

Input

ParameterTypeRequiredDescription
keystringyesTrade key from find_trades (trip:...)
accountstringIB account ID if the user has several (default: account of the most recent report)
includeBarsbooleanInclude the daily bars (default true)

Output

FieldTypeDescription
keystringTrade key from find_trades (trip:...)
symbolKeystringKey of all trades of this security (symbol:...), for exclusions
symbolstring
descriptionstring
assetClassstringStocks or CFDs
directionlong · short
currencystringTrading currency of the prices; amounts are in the base currency
entrystring | nullnull: opened before the loaded data
exitstringISO 8601 date and time (UTC)
holdingDaysvalue
firstEntryPricevalue
averageEntryPricevalue
averageExitPricevalue
quantitynumber
costBasisnumberAmount in the account base currency
pnlnumberAmount in the account base currency
returnPctnumberPercent, e.g. -3.5 for -3.5 %
positionSizePctvalueCost basis in percent of the account value the day before entry
entriesnumber
exitsnumber
addedWhileLosingbooleanAdded below (long) or above (short) the first entry
addedWhileWinningboolean
partialExitsboolean
commissionsnumberAmount in the account base currency
tagsstring[]
notestring
baseCurrencyvalue
executionsobject[] {time, side, role, quantity, price, commission, vsFirstEntryPct, files, comment}
pricePathobject {ticker, error, maxAdverseExcursionPct, maxAdverseDate, maxFavorableExcursionPct, maxFavorableDate, afterExitPct, bars}

open_positions · Open positions read

Positions still open at the end of the loaded data: entry, holding days, open quantity, average entry, cost basis and its size in % of the latest account value, realized P/L from partial exits, adds while losing or winning. Average entry and cost basis count only the shares still held, first in first out, as IB and the tax office do. With prices (default) also the latest price (at most 15 minutes old) from Yahoo, or from Lang & Schwarz Exchange for securities known only by their ISIN (daily closes only there), the market value, the unrealized change against the average entry, the unrealized P/L in the base currency with and without the currency effect since the purchase, the worst and best level since the entry and the distance to the best price since the entry, and the cash per currency from the last cash report. Use it to check open positions against the user's rules; asOf is the last loaded day (call sync_reports first if it is old).

Input

ParameterTypeRequiredDescription
accountstringIB account ID if the user has several (default: account of the most recent report)
symbolstring
includePricesbooleanLoad daily prices (default true)

Output

FieldTypeDescription
accountstring
asOfstringLast loaded day YYYY-MM-DD
baseCurrencyvalue
accountValuevalueLast known account value, base currency
accountValueDayvalueDay of accountValue YYYY-MM-DD; in a file account it can be older than asOf
cashobject | nullCash per currency at the end of the last day with a cash report (IB) or Cash rows (file account); null without either
positionsobject[] {symbolKey, symbol, description, assetClass, direction, currency, entry, holdingDays, quantity, firstEntryPrice, averageEntryPrice, costBasis, positionSizePct, realizedPnl, entries, partialExits, addedWhileLosing, addedWhileWinning, excluded, price}

annotate_trade · Tag and note a trade write

Stores tags and a note for a trade, e.g. the setup, a rule violation or a lesson ("breakout", "stop too late"). They appear in find_trades and can be filtered by tag. Replaces the previous tags and note; empty tags and note remove them.

Input

ParameterTypeRequiredDescription
keystringyesTrade key from find_trades (trip:...)
tagsstring[]
notestring

Output

FieldTypeDescription
keystringTrade key from find_trades (trip:...)
tagsstring[]
notestring

loss_limit_simulation · Stop-loss simulation read

Simulates stops at X % below the entry with daily prices from Yahoo: a stop also hits later winners that dipped below it on the way, and small losses that dipped below it become larger (unlike the usual estimate without price data, which only caps losses). Returns per stop the statistics, winners and losers stopped out and the P/L difference.

Input

ParameterTypeRequiredDescription
fromstringStart date YYYY-MM-DD (default: first loaded day)
tostringEnd date YYYY-MM-DD (default: last loaded day)
accountstringIB account ID if the user has several (default: account of the most recent report)
stopsnumber[]Stops in percent, default 5,6,7,8,10,12,15

Output

FieldTypeDescription
accountstring
periodobject {from, to}
missingvalueDays of the period not loaded yet (call sync_reports), or null
currencyvalue
coverednumber
skippedobject[] {symbol, end, reason}
scenariosobject[] {stop, stats, stoppedWinners, stoppedLosers, pnlDifference, stoppedTrades}
priceErrorsstring[]

exclusions · Excluded trades write

Lists, adds or removes trades excluded from all statistics of an account, e.g. long-term buy-and-hold positions that are not trades. Use the key of one trade from find_trades, or the symbolKey from find_trades or open_positions for all trades of a security.

Input

ParameterTypeRequiredDescription
actionlist · add · removeyes
accountstringIB account ID if the user has several (default: account of the most recent report)
keystringtrip:... or symbol:...
labelstringNote shown in the list, e.g. "QQQ buy and hold"

Output

FieldTypeDescription
exclusionsobject[] {key, label, createdAt}

add_rows · Add rows to a file account write

Adds buys and sells (also deposits, withdrawals, account values and cash balances) to a file account (fileAccount in accounts), as one file named fileName. This is how broker statements get into the app: read the statement (PDF, screenshot, export) yourself and send one row per execution. Always give the ISIN of a security, and its name; look the name up if the statement lacks it. Put anything worth keeping about a row into comment. Rows are checked like a CSV upload; an error names the line (line 2 is the first row) and nothing is stored. The same execution sent again counts once (same tradeId, else same time, security, quantity and price). Returns the file and, per security in the rows, the quantity now held in the whole account: compare it with the statement; a negative quantity is a short position, usually a missing buy.

Input

ParameterTypeRequiredDescription
accountstringyesAccount ID of a file account from accounts
fileNamestringyesName of the file, e.g. the statement's file name
rowsobject[] {type, date, time, isin, symbol, name, quantity, price, currency, fxRate, fees, amount, tradeId, comment, acquired}yes

Output

FieldTypeDescription
fileobject {id, name, from, to}
rowsnumber
alreadyPresentnumberRows the account already had from other files; they count once
holdingsobject[] {isin, symbol, quantity}
possibleDuplicatesobject[] {day, symbol, name, side, quantity, price, currency, count, files}Possibly the same execution twice, labelled differently (with and without tradeId, different tradeIds, with and without time): same security, day, side, quantity and price in different files. Check them against the statements and correct or remove the wrong file.

file_rows · Rows of a file read

The rows of one file of a file account, in the form add_rows takes, to correct them with replace_file_rows. Which file holds an execution: files in the executions of trade_detail.

Input

ParameterTypeRequiredDescription
accountstringyesAccount ID from accounts
idstringyesid from account_files

Output

FieldTypeDescription
fileobject {id, name}
rowsobject[] {type, date, time, isin, symbol, name, quantity, price, currency, fxRate, fees, amount, tradeId, comment, acquired}

replace_file_rows · Correct the rows of a file write

Replaces all rows of one file of a file account with corrected rows, e.g. a name, price, quantity or comment: read them with file_rows, change what is wrong and send all rows back, also the unchanged ones. The file keeps its id, name, statement date and PDF. Checked like add_rows; on an error nothing changes. New executions go into a new file with add_rows instead. Returns what add_rows returns.

Input

ParameterTypeRequiredDescription
accountstringyesAccount ID from accounts
idstringyesid from account_files
rowsobject[] {type, date, time, isin, symbol, name, quantity, price, currency, fxRate, fees, amount, tradeId, comment, acquired}yes

Output

FieldTypeDescription
fileobject {id, name, from, to}
rowsnumber
alreadyPresentnumberRows the account already had from other files; they count once
holdingsobject[] {isin, symbol, quantity}
possibleDuplicatesobject[] {day, symbol, name, side, quantity, price, currency, count, files}Possibly the same execution twice, labelled differently (with and without tradeId, different tradeIds, with and without time): same security, day, side, quantity and price in different files. Check them against the statements and correct or remove the wrong file.

account_files · Files of an account read

The files of an account, newest statement first: id, name, the statement date or period, and when it was added. Use it to find a file that was added twice or to the wrong account, then remove it with remove_account_file.

Input

ParameterTypeRequiredDescription
accountstringyesAccount ID from accounts

Output

FieldTypeDescription
filesobject[] {id, name, statementDate, from, to, addedAt, hasPdf}
possibleDuplicatesobject[] {day, symbol, name, side, quantity, price, currency, count, files}Possibly the same execution twice, labelled differently (with and without tradeId, different tradeIds, with and without time): same security, day, side, quantity and price in different files. Check them against the statements and correct or remove the wrong file.

remove_account_file · Remove a file write

Removes one file of a file account (fileAccount in accounts) with all its rows; the other files stay. Ask the user first. Returns the remaining files.

Input

ParameterTypeRequiredDescription
accountstringyesAccount ID from accounts
idstringyesid from account_files

Output

FieldTypeDescription
filesobject[] {id, name, statementDate, from, to, addedAt, hasPdf}
possibleDuplicatesobject[] {day, symbol, name, side, quantity, price, currency, count, files}Possibly the same execution twice, labelled differently (with and without tradeId, different tradeIds, with and without time): same security, day, side, quantity and price in different files. Check them against the statements and correct or remove the wrong file.