> For the complete documentation index, see [llms.txt](https://sdk.unlockd.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sdk.unlockd.finance/getting-started/sdk-modules/market-module.md).

# Market Module

<figure><img src="/files/k3sPaIcRLm3LBo2qlBwP" alt=""><figcaption><p>Market flow</p></figcaption></figure>

## Types

```typescript
export type CreateOrderInput = {
  startAmount: BigInt
  endAmount: BigInt
  startTime: number
  endTime: number
  debtToSell: BigInt
}
```

```typescript
export enum OrderTypes {
  ASC = 'ASC',
  DESC = 'DESC',
  NONE = 'none'
}
```

### Signature

```typescript
export type Signature = {
  data: object
  signature: { v: number; r: string; s: string; deadline: number }
}

/* data object
interface SignMarket {
  loan: SignLoanConfig;
  assetId: string;
  collection: string;
  tokenId: BigInt;
  assetPrice: BigInt;
  assetLtv: BigInt;
  nonce: BigInt;
  deadline: BigInt;
}

interface SignLoanConfig {
  loanId: string;
  aggLoanPrice: BigInt;
  aggLtv: BigInt;
  aggLiquidationThreshold: BigInt;
  totalAssets: BigInt;
  nonce: BigInt;
  deadline: BigInt;
}
*/
```

### ClientOptions

```typescript
export type ClientOptions = {
  network?: Chain
}

export type Chain = 'mainnet' | 'sepolia' | 'localhost'
```

## Functions

### Creating a Market Item

To create a market item, use the `create` function from the `market` module:

```typescript
export const create = async (
        underlyingAsset: Address,
        orderType: OrderType,
        config: CreateOrderInput,
        signature: Signature,
        options?: ClientOptions
    )
```

```typescript
const result = await create(underlyingAsset, orderType, config, signature, options?);
```

Refer to the [Market Module](https://devs.unlockd.finance/modules/debt-tokens-5) documentation for more details on the `create` function.

### Canceling a Market Item

To cancel a market item, use the cancel function from the `market` module:

```typescript
export const cancel = async (
        orderId: string, 
        options?: ClientOptions
    )
```

```typescript
const result = await cancel(orderId, options?);
```

Refer to the Market Module documentation for more details on the `cancel` function.

### Bidding a Market Item

To bid on a market item, use the marketBid function from the `market` module:

```typescript
export const marketBid = async (
        orderId: string,
        amountToPay: BigInt,
        amountOfDebt: BigInt,
        signature: Signature,
        options?: ClientOptions
    )
```

```typescript
const result = await marketBid(orderId, amountToPay, amountOfDebt, signature, options?);
```

Refer to the [Market Module](https://devs.unlockd.finance/modules/debt-tokens-5) documentation for more details on the `marketBid` function.

### Claiming a Market Item

To claim a market item, use the `claim` function from the `market` module:

```typescript
export const claim = async (
        claimOnUWallet: boolean,
        orderId: string,
        signature: Signature,
        options?: ClientOptions
    )
```

```typescript
const result = await claim(claimOnUWallet, orderId, signature, options?);
```

Refer to the Market Module documentation for more details on the `claim` function.

### Cancel Claiming a Market Item

To cancel a claim on a market item, use the `cancelClaim` function from the `market` module:

```typescript
export const cancelClaim = async (
        orderId: string, 
        signature: Signature, 
        options?: ClientOptions
    )
```

```typescript
const result = await cancelClaim(orderId, signature, options?);
```

Refer to the Market Module documentation for more details on the `cancelClaim` function.

### Buy Now Market Item

To do a buy now on a market item, use the `buyNow` function from the `market` module:

```typescript
export const buyNow = async (
        claimOnUWallet: boolean,
        orderId: string,
        amountToPay: BigInt,
        amountOfDebt: BigInt,
        signature: Signature,
        options?: ClientOptions
    )
```

```typescript
const result = await buyNow(claimOnUWallet, orderId, amountToPay, amountOfDebt, signature, options?);
```

Refer to the Market Module documentation for more details on the `buyNow` function.
