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

# Market orders

> Open and close positions at market and wait for the keeper.

## Open

```ts theme={null}
const receipt = await zeus.trade.marketOpen({
  market: 'BTC/USD',
  side: 'short',
  collateral: 500,
  payToken: 'USDC',
  size: 5000,
  slippage: 0.3
})
```

**market** `string` *required*

`BTC/USD`, or just `BTC`, in any case.

**side** `'long' | 'short'` *required*

**collateral** `Amount` *required*

Amount of `payToken` put in as collateral.

**payToken** `string` *required*

`USDC`, `ETH` (sent as native ETH), `WETH` or a market token such as `BTC`.

**size | leverage** `Amount` *required*

Position size in USD, or leverage. Pass exactly one.

**slippage** `Amount` *required*

Percent, 0.01 to 5.

## Close

```ts theme={null}
// Whole position, collateral back as ETH
await zeus.trade.marketClose({ market: 'ETH/USD', side: 'long', receiveToken: 'ETH', slippage: 0.5 })

// Part of it
await zeus.trade.marketClose({ market: 'ETH/USD', side: 'long', size: 50, receiveToken: 'ETH', slippage: 0.5 })
```

Without `size` the whole position closes.

> [!WARNING]
>
> Receiving a token other than the collateral swaps the payout through the pool. When the pool cannot give that token, for example below its USDC buffer, the keeper cancels the close with `cancelReason: 'capacity'`. Receiving the collateral token (the market's token or ETH for a Long, USDC for a Short) never swaps.

## Cancel a pending request

A request that sees no keeper outcome within 60 seconds throws `ExecutionTimeout`, which can withdraw it:

```ts theme={null}
import { ExecutionTimeout } from '@zeustrade/sdk'

try {
  await zeus.trade.marketOpen(params)
} catch (error) {
  if (error instanceof ExecutionTimeout) await error.cancel()
}
```

`zeus.trade.cancelRequest(requestKey)` does the same for any pending request of the wallet once the contract's public delay has passed.


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