Attach an investment case with library_item_id. That is the document id.
search_library returns it as item_id. list_library_items returns it as id.
Pass the id, not the title. The accept card and the transaction row show
the case. Leave library_item_id empty when there is no case.
A buy, sell, short, or cover is a portfolio order. Call get_portfolio_rules
first and size it to those rules. filled means the book took it. pending
means the card is open: do not ask again and do not send a second order.
A refused error is a portfolio rule. Do not shrink the order. Dividend,
deposit, and withdrawal still record a transaction immediately.
order_type market ignores price and uses the live price. With HIL on, or
the order above Skip HIL up to, the card opens at that live price. HIL
off, or under the skip, fills. A past date records that day's average.
A future date is refused. order_type limit requires price. The card opens
before the limit rests when HIL requires it. Accept arms it. The card
does not open again when the price hits. A past date records the price
after that day's range check.
expires_kind is gtc (90 days), day, or delete_after. delete_after needs
expires_at. after_hours lets a stock or ETF print in the extended session.
on_touch review wakes you when the limit hits so you can look and then
submit. on_touch direct applies the book rules then, with no second look.
A hard limit still refuses. HIL still opens the card for a resting limit.
A short names the stock. qty is the shares sold short. price is the sale
price per share. A cover names the stock. qty is the shares bought back.
price is the price per share. Neither uses $CASH. A short while long, a
cover larger than the short, a sell larger than the long, and a buy while
short come back as the terminal's 400. Do not rewrite that error into a success.
A dividend names the stock, not $CASH. qty is the shares, price is the
amount per share and must be greater than 0, and date is the pay date.
Cash increases on a long and decreases on a short. The share count does
not change. The open cost of a long drops by the part still held. A
short's open credit shrinks. The closed slice is realized P&L.
Args:
portfolio_id: The portfolio UUID
symbol: Stock symbol (e.g. "AAPL"). For deposit/withdrawal use "$CASH"
(aliases "CASH" / blank are normalized to "$CASH").
side: "buy", "sell", "deposit", "withdrawal", "dividend", "short", or "cover"
qty: Number of shares (or cash amount for deposit/withdrawal)
price: Price per share. Required for a limit, a dividend, and cash. Omit it for a market.
date: Trade date, or the dividend pay date (YYYY-MM-DD). Today or a past date.
order_type: market or limit. Market uses the live price today and the day's average in the past.
limit_price: Resting price. Omit it when order_type is set; price is used.
expires_kind: gtc, day, or delete_after. Used with a limit.
expires_at: End time when expires_kind is delete_after.
after_hours: Allow the extended stock and ETF session.
on_touch: review or direct. Used with a limit. Default is review.
library_item_id: The investment case. The document id from search_library
(item_id) or list_library_items (id). Not the title. Omit when there is no case.
strategy_id: Strategy UUID from list_strategies. Tags this order on that
strategy's activity. Omit when the order is not part of a strategy.