> For the complete documentation index, see [llms.txt](https://limelight-1.gitbook.io/limelight-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://limelight-1.gitbook.io/limelight-docs/developers/bot-trading-guide.md).

# Bot Trading Guide

Developer reference for wiring a bot against a Limelight market on Movement. Limelight markets are **Move modules**, so you interact with them using the **Aptos TypeScript SDK** pointed at a Movement fullnode.

{% hint style="info" %}
**Illustrative.** Module addresses and entry/view signatures below are placeholders that show the integration shape. Request the current values, a Movement fullnode REST endpoint, and a funded wallet from the Limelight team.
{% endhint %}

## Setup

```ts
import {
  Aptos, AptosConfig, Network, Account, Ed25519PrivateKey,
} from "@aptos-labs/ts-sdk";

// Point the SDK at a Movement fullnode (Aptos-compatible REST).
const aptos = new Aptos(new AptosConfig({
  network: Network.CUSTOM,
  fullnode: process.env.MOVEMENT_FULLNODE_URL!, // e.g. https://<movement-fullnode>/v1
}));

const account = Account.fromPrivateKey({
  privateKey: new Ed25519PrivateKey(process.env.BOT_PRIVATE_KEY!),
});

const LIMELIGHT = process.env.LIMELIGHT_MODULE_ADDR!; // e.g. 0x<addr>
```

## Quote (view functions — base LS-LMSR cost, excludes fees)

```ts
// Cost to buy `amounts` shares of `outcomes` at current curve state.
const [baseCost] = await aptos.view({
  payload: {
    function: `${LIMELIGHT}::lslmsr_engine::get_purchase_cost`,
    functionArguments: [marketAddr, outcomes /* u8[] */, amounts /* u64[] */],
  },
});

// Current outcome prices (probabilities).
const [prices] = await aptos.view({
  payload: { function: `${LIMELIGHT}::lslmsr_engine::get_prices`, functionArguments: [marketAddr] },
});
```

## Buy

```ts
// Add fee + slippage headroom to the base quote to derive maxCost.
const maxCost = (BigInt(baseCost) * 11_000n) / 10_000n; // ~10% headroom; tighten in production

const txn = await aptos.transaction.build.simple({
  sender: account.accountAddress,
  data: {
    function: `${LIMELIGHT}::market::buy`,
    functionArguments: [marketAddr, outcomes, amounts, maxCost],
  },
});
const committed = await aptos.signAndSubmitTransaction({ signer: account, transaction: txn });
await aptos.waitForTransaction({ transactionHash: committed.hash });
```

USDCx is withdrawn from the signer by the Move framework's fungible-asset flow — there's no separate `approve` call. `maxCost` protects you from adverse price movement (the tx aborts if the real cost exceeds it).

## Sell / Redeem

```ts
// Sell: minReturn guards against slippage; tx aborts if the return is lower.
await submit(`${LIMELIGHT}::market::sell`, [marketAddr, outcomes, amounts, minReturn]);

// Redeem winning shares after a market closes.
await submit(`${LIMELIGHT}::market::redeem`, [marketAddr]);
```

## Resolving Price Markets (Pyth pull pattern)

For price markets, a fresh Pyth update is submitted and read in the same transaction:

```ts
// 1) Fetch the VAA/update payload from Pyth's price service for your feed IDs
//    (feed IDs on Movement/Aptos have NO 0x prefix).
// 2) Submit update_price_feeds (pay the update fee), then read the price — same tx.
await submit(`${LIMELIGHT}::oracle_resolver::resolve_with_pyth`, [marketAddr, pythUpdateData]);
```

## Practical Notes

* **Re-check status on-chain** via the market's view function before trading; off-chain caches can be stale.
* **Share units match USDCx decimals** — quote and size in those units.
* **Gas is paid in MOVE** — keep the bot wallet funded with a small MOVE balance.
* Market discovery (lists, metadata) is available via the Limelight backend REST API — see [API & Widgets](/limelight-docs/developers/api-and-widgets.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://limelight-1.gitbook.io/limelight-docs/developers/bot-trading-guide.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
