Add investment trade and holding support#4
Closed
shrijayan wants to merge 1 commit into
Closed
Conversation
Sure's backend already exposes /api/v1/trades and /api/v1/holdings for managing stock buys/sells/dividends/deposits/withdrawals/interest on investment (or crypto exchange) accounts, but this MCP server only wrapped the generic cash /api/v1/transactions endpoint. Investment accounts had no way to record trades through Claude/an MCP client. Adds 7 new tools mirroring the existing transaction tools' pattern: - get_trades / get_trade: list and view trades - create_trade: record a buy/sell/dividend/deposit/withdrawal/interest - update_trade / delete_trade: modify or remove a trade - get_holdings / get_holding: view computed stock positions (read-only, Sure derives these from trades + prices, so there's no write endpoint) Trade type validation (buy/sell/dividend/deposit/withdrawal/interest) and per-type required-field checks are left to the Sure API itself rather than duplicated client-side, consistent with how the existing transaction tools already defer validation to the server. README updated with the new tools table entries and a short "Investment Trades" section documenting which fields are required per trade_type, matching Api::V1::TradesController's actual validation.
Author
|
Superseded by we-promise#3 — opening this same change against |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Sure's API already has full support for investment trades (
/api/v1/trades) and holdings (/api/v1/holdings) — buying/selling stock, dividends, deposits/withdrawals, interest — but this MCP server only ever wrapped the generic cash/api/v1/transactionsendpoint. There was no way to record a stock trade on an investment account through Claude/an MCP client; the only option (create_transaction) has no concept of ticker/quantity/price, so it can't represent a trade correctly.What's added
7 new tools, following the exact same pattern already used by the transaction tools (
get_client()/handle_response()/ try-except-log-json.dumps):get_tradesGET /api/v1/trades(filters:account_id,account_ids,start_date,end_date, paginated)get_tradeGET /api/v1/trades/:idcreate_tradePOST /api/v1/trades—trade_typeone ofbuy/sell/dividend/deposit/withdrawal/interestupdate_tradePATCH /api/v1/trades/:iddelete_tradeDELETE /api/v1/trades/:idget_holdingsGET /api/v1/holdings(read-only — Sure computes these from trades + prices)get_holdingGET /api/v1/holdings/:idAll endpoint paths, required params, and per-
typevalidation rules were confirmed directly againstApi::V1::TradesController/Api::V1::HoldingsControllerinwe-promise/sure, not guessed.Trade-type validation and per-type required-field rules (e.g.
qty/pricefor buy/sell,amountfor dividend/interest/deposit/withdrawal) are intentionally not duplicated client-side — same as the existing transaction tools, invalid input is left to the Sure API to reject with its own descriptive error message, so this stays in sync automatically if Sure's rules change.Docs
README.md: added the new tools to the tools table, plus a short "Investment Trades" section documenting which fields are required pertrade_typeand the investment/crypto-exchange account requirement.Testing
get_trades/get_holdings(and their singular counterparts) were run live against a real self-hosted Sure instance with existing investment-account data and correctly returned real trades/holdings.create_transaction/update_transaction/delete_transactiontools, with parameters verified against the controller source (linked above).python -m py_compileandruff check --select F,E9pass on the new code (pre-existing lint/type debt elsewhere in the file — untyped@mcp.tool()decorators, missingmcp/httpxstubs, a few long log lines — is unrelated to this change and left as-is to keep the diff focused).