Appearance
trade
Trades are intents: the script asks, the engine fills at a later block against the pool reserves, or rejects.
| Name | Description |
|---|---|
trade.buy() | Asks to buy alpha with TAO. |
trade.sell() | Asks to sell alpha from the position. |
trade.closePosition() | Sells the whole position. |
trade.cancel() | Cancels an intent that has not filled yet. |
trade.cancelAll() | Cancels every intent that has not filled yet; returns how many. |
trade.stop() | Engine-managed: sell when price <= level. |
trade.takeProfit() | Engine-managed: sell when price >= level. |
trade.trailingStop() | Engine-managed: sell when price falls pct percent below the running high since creation. |
trade.cancelConditional() | Cancels an active stop, take-profit or trailing stop. |
trade.buy()
ts
trade.buy(options: BuyOptions): IntentIdAsks to buy alpha with TAO. Fills at a later block against the pool, or is rejected; see event.onFill and event.onReject. Returns null before the tester's trading start.
Types: BuyOptions, IntentId
trade.sell()
ts
trade.sell(options: SellOptions): IntentIdAsks to sell alpha from the position. Long only: without a position the intent is rejected with "no-position". Returns null before the tester's trading start.
Types: SellOptions, IntentId
trade.closePosition()
ts
trade.closePosition(options?: { reason?: string }): IntentId | nullSells the whole position. Returns null when there is no position.
Types: IntentId
trade.cancel()
ts
trade.cancel(id: IntentId): booleanCancels an intent that has not filled yet. Returns false when it already filled, expired or was rejected.
Types: IntentId
trade.cancelAll()
ts
trade.cancelAll(): numberCancels every intent that has not filled yet; returns how many.
trade.stop()
ts
trade.stop(options: ConditionalOptions & { price: Price }): stringEngine-managed: sell when price <= level. Evaluated every block (precise/live) or at bar open/low/high/close (quick). Fills after the normal latency, never at the trigger price. Place it once the position exists (e.g. in event.onPositionOpened): an order checked while flat is cancelled.
Types: ConditionalOptions, Price
trade.takeProfit()
ts
trade.takeProfit(options: ConditionalOptions & { price: Price }): stringEngine-managed: sell when price >= level.
Types: ConditionalOptions, Price
trade.trailingStop()
ts
trade.trailingStop(options: ConditionalOptions & { pct: number }): stringEngine-managed: sell when price falls pct percent below the running high since creation.
Types: ConditionalOptions
trade.cancelConditional()
ts
trade.cancelConditional(id: string): booleanCancels an active stop, take-profit or trailing stop. Returns false when it already triggered or was cancelled.
Types
BuyOptions
Options of trade.buy(). Give the size as tao (TAO to spend, fee included) or as alpha.
| Field | Type | Description |
|---|---|---|
tao? | number | TAO to spend, fee included |
alpha? | number | alpha to buy, converted to TAO at the pool price when the intent fills |
maxPrice? | Price | reject (or partially fill) above this effective price |
ttlBlocks? | number | blocks the intent may wait for a fill before it expires (default 3) |
partialOk? | boolean | when the whole size would break maxPrice or exceed the cash, fill what fits instead of rejecting (default true) |
reason? | string | a label shown in the journal and the tester's trade list |
SellOptions
Options of trade.sell(). Give the size as alpha or as tao (converted at the pool price).
| Field | Type | Description |
|---|---|---|
alpha? | number | alpha to sell; more than the position sells the whole position |
tao? | number | TAO worth of alpha to sell, converted at the pool price when the intent fills |
minPrice? | Price | reject (or partially fill) below this price |
ttlBlocks? | number | blocks the intent may wait for a fill before it expires (default 3) |
partialOk? | boolean | when the whole size would break minPrice, fill what fits instead of rejecting (default true) |
reason? | string | a label shown in the journal and the tester's trade list |
ConditionalOptions
Options shared by the conditional orders.
| Field | Type | Description |
|---|---|---|
alpha? | number | "all" | alpha to sell when triggered (default "all": the whole position) |
ttlBlocks? | number | blocks the triggered sell may wait for a fill (default 3) |
reason? | string | a label for the triggered sell (default: the order's kind) |
Rejection
Why an intent was not filled, as passed to event.onReject.
| Field | Type | Description |
|---|---|---|
intent | Intent | |
reason | string | "price-limit" | "no-position" | "insufficient-cash" | "empty" | "no-price" | "risk:<rule>" (e.g. "risk:maxOrderTao") |
