buy
Records a completed purchase in the local ledger, updating existing positions at weighted-average cost or opening new ones for unseen symbols; it never places broker orders.
Instructions
Record a buy in the local ledger: adds to an existing position with weighted-average cost, or opens a new position for an unseen symbol. This bookkeeps a trade the user already placed with their broker — openInvest never places real orders.
Confirm symbol, units, and price with the user before calling; this
moves ledger cash. A position the user already held before using
openInvest is not a purchase: record it with record_existing_position.
Off-exchange China mutual funds (FUND:<6 digits>) settle T+1 or later
at the NAV of the pricing day: use place_fund_order +
confirm_fund_order instead (buy books them as instantly filled and
total assets dip by the amount until the real confirmation).
Args:
symbol: yfinance ticker (e.g. "AAPL", "510300.SS"). Gold = "GC=F", booked in
CNY per gram only (units = grams, currency "CNY", kind "metal", unit_label "克").
units: Quantity bought; must be > 0.
price: Execution price per unit, in currency.
currency: Currency of price; omitted = the existing position's currency (CNY if new).
kind: Asset kind tag: "equity", "etf", "metal" (gold), "crypto", "bond", "fund", "other".
unit_label: Human display label for units (default "股", i.e. shares).
idempotency_key: Reuse the same key when retrying this exact call; recorded once.
Returns: Updated position summary, or {"status": "error", "error": ...}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kind | No | Asset kind tag: 'equity', 'etf', 'metal' (gold), 'crypto', 'bond', 'fund', 'other'. | equity |
| price | Yes | Execution price per unit, in `currency`. | |
| units | Yes | Quantity bought; must be > 0. | |
| symbol | Yes | yfinance ticker, e.g. 'AAPL', '510300.SS'. Gold is 'GC=F' and must be booked per gram in CNY: units = grams, price = CNY/gram, currency='CNY', kind='metal', unit_label='克' (USD/oz bookings are rejected). | |
| currency | No | Currency of `price`, e.g. 'CNY', 'USD', 'AUD'. Omit to use the existing position's currency (CNY for a new position); a different currency than the position's is rejected. | |
| unit_label | No | Human display label for units (default '股', i.e. shares). | 股 |
| idempotency_key | No | Optional client-generated key (e.g. a UUID4). When retrying this SAME call after a timeout or an unknown result, reuse the same key: the ledger records it once and later calls return {"status": "duplicate"} without touching cash or holdings. Only the key is compared, not the arguments — a different order (other symbol/units/price/amount) needs a new key, or it is silently treated as the retry. | |
| existing_position | No | Not supported on buy. For a position held before using openInvest call `record_existing_position`; passing true here returns an error instead of deducting cash. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |