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

# Limit Orders

> THORChain / MAYAChain native limit orders — set a target price, walk away

## Overview

Limit orders are a native feature of THORChain and MAYAChain — they're stored as memo-encoded transactions on the source chain, and the protocol's outbound vault settles them when the target price is met.

The SDK exposes both the high-level client methods (recommended) and the low-level building blocks (for custom flows).

`LIMIT_ORDER_NATIVE_ASSETS` lists the assets eligible as the order's source/destination. Currently this includes `RUNE`, `BTC.BTC`, `ETH.ETH`, `ETH.USDC`, `BCH.BCH`, `LTC.LTC`, `DOGE.DOGE`, `AVAX.AVAX`, `BSC.BNB`, `MAYA.CACAO`, and others.

## High-Level API

### Submit

```typescript theme={null}
import { LIMIT_ORDER_NATIVE_ASSETS } from "leokit-sdk";

const orderId = await sdk.submitLimitOrder({
  fromAsset: "ETH.ETH",
  toAsset: "BTC.BTC",
  amount: "1000000000000000000",   // 1 ETH in wei
  targetPrice: "0.05",             // 0.05 BTC per ETH
  destination: "bc1q...",
  protocol: "thorchain",           // or "mayachain"
});
```

Returns the protocol-assigned order ID. The SDK builds the memo, signs the deposit transaction with the active wallet, and broadcasts it.

### Cancel

```typescript theme={null}
const cancelMemo = await sdk.cancelLimitOrder({
  orderId,
  protocol: "thorchain",
});
```

The cancel transaction is signed and broadcast for you. Returns the memo string used (useful for receipts/logs).

## Low-Level Utilities

For custom flows where you don't want the SDK to sign or broadcast:

```typescript theme={null}
import {
  fetchLimitQuote,
  toBaseUnits,
  getLimitOrderStatus,
  fetchInboundAddress,
  buildCancelMemo,
  getCancelVaultAddress,
} from "leokit-sdk";

// Quote first (no on-chain action)
const quote = await fetchLimitQuote({
  fromAsset: "ETH.ETH",
  toAsset: "BTC.BTC",
  amount: "1000000000000000000",
  targetPrice: "0.05",
  protocol: "thorchain",
});

// Inbound vault (where the user must deposit)
const vault = await fetchInboundAddress("thorchain", "ETH");

// After broadcasting, check status
const status = await getLimitOrderStatus(quote.quoteId);
// LimitOrderStatus { state: "open" | "filled" | "cancelled", ... }

// To cancel manually
const memo = buildCancelMemo({ orderId, protocol: "thorchain" });
const cancelVault = getCancelVaultAddress("thorchain"); // chain-specific
// Sign + broadcast a transaction with `memo` to `cancelVault`
```

`toBaseUnits` (under the limit-orders namespace) is a thin wrapper that handles THORChain's 1e8 normalization correctly across decimals — use it instead of generic amount math when building memos by hand.

## Types

| Type                     | Description                                     |
| ------------------------ | ----------------------------------------------- |
| `LimitQuoteParams`       | Input to `fetchLimitQuote` / `submitLimitOrder` |
| `LimitQuoteResponse`     | Quote details + recommended slippage            |
| `LimitOrderStatus`       | Lifecycle state + fill details                  |
| `CancelLimitOrderParams` | Input to `cancelLimitOrder` / `buildCancelMemo` |

All types are exported from the main `leokit-sdk` entry point.

## Notes

* Limit orders only work for protocols that support them (THORChain, MAYAChain). Other protocols throw on `submitLimitOrder`.
* The SDK handles asset normalization (THORChain uses `ASSET~` suffix in some memos); you don't need to format the memo yourself when using `submitLimitOrder` / `cancelLimitOrder`.
* Use `getLimitOrderStatus` (or `sdk.watchTransaction(orderId, ...)` if your status feed exposes the order id) for fill tracking.
