# 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.


---

# Agent Instructions: 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:

```
GET https://sdk.unlockd.finance/getting-started/sdk-modules/market-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
