Average Buy Price
workflow.run_average_buy_priceReal entry price of a spot coin bought and sold in several trades: moving average cost, trades in the order they happened, each with its own fee (no leverage, no funding). The buy fee is part of the cost basis; a sale removes coins at the current average and never changes the average of what is left, only a later buy does; selling everything resets it. Selling more than is held at that point is an error naming the trade. Each fee is a fraction of that trade's value (0.001 = 0.1%, at most 0.05). Edge cases: 1 to 1000 trades; price and quantity above zero; a sale before any buy, or above the holding, is an error; a sale within 1e-12 of the largest holding since the position was last flat counts as selling everything (float noise) and leaves exactly zero, never a residual; when nothing is held the average, before-fee average and break-even are null and costBasis is 0; realizedProfit can be negative. Not covered: taxes, FIFO/LIFO lots (moving average cost only), slippage, withdrawal or network fees, currency conversion, leverage and funding. Prices may be in any currency; results are in the same one. sellFeePct is the fee expected when the remaining coins are sold, used for the break-even sell price. For equal cash buys at a list of prices use workflow.run_spot_dca; for the average entry of a perpetual futures position use primitive.average_entry. Use when user asks "I bought and sold this coin several times, what is my average buy price and break-even now?". Returns: remainingQuantity, averageBuyPrice (fees in) and averageBuyPriceBeforeFees (null when nothing is held), costBasis, totalBought, totalSold, totalInvested, totalSellProceeds, realizedProfit, totalFees, breakevenSellPrice (null when nothing is held).
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"trades": "<trades>"
},
"name": "workflow.run_average_buy_price"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| trades | Yes | Trades in the order they happened (1 to 1000) | |
| sellFeePct | No | Fee expected when the remaining coins are sold, 0 to 0.05, for the break-even sell price. Default 0 |