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

# Orders, Cancellation, and Replacement

> Place native orders and perform slot-bound cancellation and replacement.

```typescript theme={null}
import { abi } from "@toxicflow-labs/ts-sdk";
import { parseUnits } from "viem";

function precisionDecimals(precision: bigint): number {
  const value = precision.toString();
  if (!/^10*$/.test(value)) throw new Error(`Unsupported precision: ${precision}`);
  return value.length - 1;
}

const [pricePrecision, sizePrecision, tickSize] = await publicClient.readContract({
  address: market,
  abi: abi.orderBookAbi,
  functionName: "getMarketParams"
});
const price = parseUnits("12.34", precisionDecimals(BigInt(pricePrecision)));
if (price % BigInt(tickSize) !== 0n) throw new Error("Price is off tick");
const quantity = parseUnits("1", precisionDecimals(sizePrecision));

await kuru.spot.batch({
  market,
  userId,
  orders: [{
    side: "buy",
    quantity,
    price,
    tif: "gtc",
    executionInstruction: "postOnly",
    minSizeAfterBlock: 0n
  }],
  cancelSlotIdxs: [],
  clientOrderId
});
```

The SDK accepts enum names or exported numeric constants and validates integer widths. It does not validate market tick, notional, balance, or live-book conditions locally; write simulation handles contract validation.

## Packed replacement

```typescript theme={null}
import { encodePackedReplaceOps } from "@toxicflow-labs/ts-sdk";

const packedOps = encodePackedReplaceOps([
  {
    slotIdx: 2,
    side: "sell",
    price: parseUnits("12.5", precisionDecimals(BigInt(pricePrecision))),
    size: parseUnits("0.5", precisionDecimals(sizePrecision)),
    postOnly: true
  },
  { slotIdx: 5 } // cancel
]);

await kuru.spot.replaceBySlotPacked({ market, userId, packedOps, clientOrderId });
```

`cancelBySlots` builds an empty-order `batch`; `cancelAllOrders` calls the dedicated entrypoint. Read the current `getOrderId` before submitting asynchronous slot operations.

`protocolCancelBySlots` and its request builder are exported but require the contract's protocol cancellation authority. Ordinary applications should not call them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.