Skip to content

Trading With the CLI and MCP

Start with a public read or an MCP market query. Then connect a Sai account when you want to preview a trade for that account.

Get a public estimate before linking an account. An address-free preview returns addr: null and cannot authorize a trade.

Terminal window
sai --endpoint https://sai-keeper.nibiru.fi/query --json \
trade open --market 0 --side long --type market \
--amount 2 --leverage 2 --slippage 1 --dry-run

On Sai Web Mainnet, open the wallet menu with a connected wallet and an active trading session. Select Connect Sai CLI / MCP, then Copy session token. Run the import command shown in the dialog in your own terminal. Paste the token at the hidden prompt or press Enter to read it from the clipboard.

Check the account and session with the same Keeper endpoint.

Terminal window
sai --endpoint https://sai-keeper.nibiru.fi/query auth status

If you use a Foundry keystore, sai auth login NAME opens a session with the keystore named NAME on the selected network. Keep the session token out of agent prompts, shared files, and shell history. A valid session can trade your Sai balance and request one-click withdrawals of idle funds to its owner wallet. sai auth logout removes the local copy. The token stays valid until it expires. Deposit and bridge through Sai Web.

This Mainnet example sends no order. Replace $SAI_ACCOUNT with your account’s EVM address and choose a market ID from sai --json market list. The amount is collateral in USD. Slippage is a percentage.

Terminal window
sai --endpoint https://sai-keeper.nibiru.fi/query --as "$SAI_ACCOUNT" --json \
trade open --market 0 --side long --type market \
--amount 2 --leverage 2 --slippage 1 --dry-run

Through MCP, call mcp_info to check the network, then call preview_open with the same parameters. Use decimal strings for amount, leverage, and slippage.

{
"market_id": 0,
"side": "long",
"order_type": "market",
"amount": "2",
"leverage": "2",
"slippage": "1",
"addr": "<YOUR_EVM_ADDRESS>"
}

Review the account, network, market, order size, leverage, and reported fee, liquidation, and worst-case fill estimates. A CLI dry run uses the quote available at preview time. A market intent reads a fresh price at submission.

An agent should show the preview and wait for your approval before it submits an intent. Approve the specific account, network, and order parameters. Preview again if any of those change.

A CLI market order gets a fresh price at submission and applies your slippage setting to that price. It does not enforce the preview quote. To proceed after reviewing the preview, use the approved parameters without --dry-run.

For MCP submission, the matching trade_open call uses the same addr and order arguments. Pass the preview’s previewDigest as preview_digest and, for a market order, its referencePrice as reference_price. The server checks the digest and rechecks the price. See the trade safety reference for how the quote check and fill bound affect the result.

Save the intentKey from the submission response. The state accepted means Keeper admitted the request. For a limit or stop order, placed confirms the order was placed. For a market order, wait for the execution outcome and receipt.

Terminal window
sai --endpoint https://sai-keeper.nibiru.fi/query --json \
intent wait "$SAI_INTENT_KEY" --addr "$SAI_ACCOUNT" --timeout 30

In MCP, call intent_wait with the same key and addr. If the outcome is unknown, look up the same key before retrying. A timeout can occur after Keeper accepted the original request. AI tools overview