> ## Documentation Index
> Fetch the complete documentation index at: https://api.alphainsider.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Trading

> AlphaInsider trading component guide for agents: normalized strategy_value, input_multiplier display math, fixed orders, allocation orders, webhooks, max order size, and safe order sizing.

# Trading Calculations

Use this page to convert AlphaInsider's normalized strategy data into correct user-facing values and API order inputs.

* REST API: `https://alphainsider.com/api`
* WebSocket: `wss://alphainsider.com/ws`
* OpenAPI: [https://api.alphainsider.com/openapi.yaml](https://api.alphainsider.com/openapi.yaml)
* Skill guide: [https://api.alphainsider.com/skill.md](https://api.alphainsider.com/skill.md)

Use this page before implementing AlphaInsider trading calculations. Verify exact endpoint fields in `https://api.alphainsider.com/openapi.yaml`, especially `newOrder`, `newOrderAllocations`, `getPositions`, `getOrders`, `getMaxOrderSize`, and `newOrderWebhook`.

## Core Model

AlphaInsider strategies use normalized internal values:

* `strategy_value` is a normalized performance score, not dollars.
* Position `amount` and order `amount`/`total` are strategy-normalized units.
* `price`, `bid`, `ask`, `last`, and stop/limit prices are real market prices.
* `input_multiplier` converts strategy-normalized units into the user's display units.
* `input_multiplier = input_value / strategy_value_at_input_date`.
* Fetch `input_multiplier` from `GET /getStrategySubscriptions`.
* Set or update calculation inputs with `POST /updateStrategyCalculation`.
* API numeric values may arrive as strings. Convert before doing math.

Never display raw `strategy_value`, raw position `amount`, or raw order `total` as user-facing dollars or shares.

## Missing Multiplier

Owners should have an `input_multiplier`. If an owner flow appears to lack one, refresh the subscription/calculation context before displaying values or sizing fixed orders.

Subscribers may have `input_multiplier: null`. When it is missing:

* Do not silently treat it as `1`.
* Display percent fallback values derived from `strategy_value`, or ask for `input_value` and `input_date`.
* Do not size a fixed `newOrder` from user-visible shares/USD until a multiplier exists.

## Display Formulas

Use these formulas when showing positions, cash, shares, crypto, or portfolio values to a user.

| Display value         | With `input_multiplier`                | Percent fallback                             |
| --------------------- | -------------------------------------- | -------------------------------------------- |
| Portfolio value       | `strategy_value * input_multiplier`    | `strategy_value * 100`                       |
| Long asset value      | `amount * bid * input_multiplier`      | `(amount * bid) / strategy_value * 100`      |
| Short liability value | `abs(amount) * ask * input_multiplier` | `(abs(amount) * ask) / strategy_value * 100` |
| Cash                  | `amount * input_multiplier`            | `amount / strategy_value * 100`              |
| Share or crypto count | `amount * input_multiplier`            | show percent exposure only                   |
| Cost basis            | `amount * price * input_multiplier`    | show percent exposure only                   |

Use `bid` for long assets, `ask` for short liabilities, and `1` for cash.

## Order Endpoint Choice

| Goal                                | Endpoint                       | Multiplier math                     |
| ----------------------------------- | ------------------------------ | ----------------------------------- |
| Exact user-visible shares or crypto | `POST /newOrder` with `amount` | divide by `input_multiplier`        |
| Exact user-visible USD              | `POST /newOrder` with `total`  | divide by `input_multiplier`        |
| Rebalance to target percents        | `POST /newOrderAllocations`    | none                                |
| TradingView or external signal      | `POST /newOrderWebhook`        | none                                |
| Cancel an open order                | `POST /deleteOrder`            | none                                |
| Check buying/selling power          | `GET /getMaxOrderSize`         | endpoint returns user-facing limits |

Call `GET /getMaxOrderSize` before large, leveraged, or user-risky fixed orders.

## `newOrder`

`newOrder` accepts exactly one of `amount` or `total`.

* `amount` is strategy-normalized shares or crypto units.
* `total` is strategy-normalized cash.
* If the user gives a share or crypto count, send `amount = user_visible_amount / input_multiplier`.
* If the user gives a USD amount, send `total = user_visible_dollars / input_multiplier`.
* Do not use `newOrder` with user-visible shares/USD when `input_multiplier` is missing.

Open order responses from `getOrders`, `newOrder`, `newOrderAllocations`, `newOrderWebhook`, and `wsOrders` include `order_dependencies` as prerequisite order IDs. `[]` means no outstanding prerequisite.

## `newOrderAllocations`

Use `newOrderAllocations` when the user wants target portfolio percents instead of exact shares/USD.

Before submitting allocation-generated orders, this endpoint cancels any existing open orders for the strategy.

* Send target percents as documented in OpenAPI.
* Do not apply `input_multiplier`.
* Do not send `order_dependencies` in the request.
* Allocation-generated increase orders may depend on reduce orders; read returned `order_dependencies` before assuming an order can fill immediately.

## Webhooks And Streams

`newOrderWebhook` is for signal-style actions and uses `api_token` in the body. It does not need multiplier math. By default each alert goes fully in or out of the position at `leverage`; the optional `pyramiding` integer steps into the position by `leverage / pyramiding` per same-direction alert.

Before submitting a new order, `newOrderWebhook` cancels any existing open orders for the strategy.

For live displays, subscribe to:

* `wsStrategyValue:<strategy_id>` for live `strategy_value`.
* `wsPositions:<strategy_id>` for position changes.
* `wsOrders:<strategy_id>` for open order changes and `order_dependencies`.

Refresh subscription/calculation context after strategy resets before displaying normalized values.

## Agent Checklist

* Fetch or confirm `input_multiplier` before showing user-facing dollars, shares, crypto counts, or fixed-order sizes.
* Use percent fallback only when multiplier is missing.
* Convert user-visible shares/USD to `newOrder.amount` or `newOrder.total` by dividing by `input_multiplier`.
* Do not apply multiplier math to prices, stop prices, allocation percents, or webhook signal actions.
* Check `success` before using `response`.
