# Trading & Orders

All Trading & Order API endpoints require authentication. Please create OKX API keys to interact with these functions successfully. Accounts must be funded or collateralized for any trades to successfully post. Please note that some endpoints for Algo & Block trading are currently under development.

## Placing and Manipulating Orders

### Place Order

{% hint style="info" %}
Please refer to the official OKX API Docs for the required parameters. *You can place an order only if you have sufficient funds.*

<https://www.okx.com/docs-v5/en/#rest-api-trade-place-order>
{% endhint %}

#### Function Name:

```javascript
placeOrder()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

    async function placeOrder(exchange, options) {
        try {
            let result = await exchange.placeOrder(options);
            return result
            console.log(result);
        } catch (error) {
            console.log(error.message);
        }
    }
  
    const result = await placeOrder(myOkxAccount, {
         instId: "BTC-USDT",
         tdMode: "cash",
         side: "buy",
         ordType: "limit",
         px: "10000",
         sz: ".01",         // for SWAPS sz is number of contracts which is .01 BTC
    })
```

### Place Multiple Orders

{% hint style="info" %}
Please refer to the official OKX API Docs for the required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-place-multiple-orders>
{% endhint %}

#### Function Name:

```javascript
placeMultiOrder()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function placeMultiOrder(exchange, options) {
    try {
        let result = await exchange.placeMultiOrder(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await placeMultiOrder(myOkxAccount, [

    {
        instId:"BTC-USDT",
        tdMode:"cash",
        clOrdId:"b15",
        side:"buy",
        ordType:"limit",
        px:"2.15",
        sz:"2"
    },
    {
        instId:"BTC-USDT",
        tdMode:"cash",
        clOrdId:"b15",
        side:"buy",
        ordType:"limit",
        px:"2.15",
        sz:"2"
    }
])
```

### Cancel Order

{% hint style="info" %}
Please refer to the official OKX API Docs for the required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-order>
{% endhint %}

#### Function Name:

```
cancelOrder()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function cancelOrder(exchange, options) {
    try {
        let result = await exchange.cancelOrder(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await cancelOrder(myOkxAccount, {
    ordId:"2510789768709120",
    instId:"BTC-USD-190927"
})
```

### Cancel Multiple Orders

{% hint style="info" %}
Please refer to the official OKX API Docs for the required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-multiple-orders>
{% endhint %}

#### Function Name:

```
cancelMultiOrder()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function cancelMultiOrder(exchange, options) {
    try {
        let result = await exchange.cancelMultiOrder(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await cancelOrder(myOkxAccount, [
{
    ordId:"2510789768709120",
    instId:"BTC-USD-190927"
},
{
    ordId:"12312",
    instId:"BTC-USDT"
}
])
```

### Amend Order

{% hint style="info" %}
Please refer to the official OKX API Docs for the required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-amend-order>
{% endhint %}

#### Function Name:

```javascript
modifyOrder()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function modifyOrder(exchange, options) {
    try {
        let result = await exchange.modifyOrder(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await modifyOrder(myOkxAccount, {
    ordId:"2510789768709120",
    newSz:"2",
    instId:"BTC-USDT"
})
```

### Amend Multiple Orders

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-amend-multiple-orders>
{% endhint %}

#### Function Name:

```javascript
modifyMultiOrder()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function modifyMultiOrder(exchange, options) {
    try {
        let result = await exchange.modifyMultiOrder(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await modifyMultiOrder(myOkxAccount, [
    {
        ordId:"2510789768709120",
        newSz:"2",
        instId:"BTC-USDT"
    },
    {
        ordId:"2510789768709121",
        newSz:"2",
        instId:"BTC-USDT"
    }
])
```

### Close Positions

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-close-positions>
{% endhint %}

#### Function Name:

```javascript
closePositions()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function closePositions(exchange, options) {
    try {
        let result = await exchange.closePositions(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await closePositions(myOkxAccount, {
    instId:"BTC-USDT-SWAP",
    mgnMode:"cross"
})
```

## Order Details And Transaction History

### Get Order Details

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-get-order-details>
{% endhint %}

#### Function Name:

```javascript
getOrderDetails()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getOrderDetails(exchange, options) {
    try {
        let result = await exchange.getOrderDetails(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getOrderDetails(myOkxAccount, {
    instId: "BTC-USDT"
})
```

### Get Order List

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-get-order-list>
{% endhint %}

#### Function Name:

```javascript
getOrderList()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getOrderList(exchange, options) {
    try {
        let result = await exchange.getOrderList(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getOrderList(myOkxAccount)
```

### Get Order History (last 7 days)

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-get-order-history-last-7-days>
{% endhint %}

#### Function Name:

```javascript
getOrderHistoryWeek()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getOrderHistoryWeek(exchange, options) {
    try {
        let result = await exchange.getOrderHistoryWeek(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getOrderHistoryWeek(myOkxAccount, {
                instType: "SPOT"
                })
```

### Get Order History (last 3 months)

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-get-order-history-last-3-months>
{% endhint %}

#### Function Name:

```javascript
getOrderHistoryArchive()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getOrderHistoryArchive(exchange, options) {
    try {
        let result = await exchange.getOrderHistoryArchive(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getOrderHistoryArchive(myOkxAccount, {
                instType: "SPOT"
                })
```

### Get Transaction Details (last 3 days)

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-get-transaction-details-last-3-days>
{% endhint %}

#### Function Name:

```javascript
getRecentTransactionDetailsShort()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getRecentTransactionDetailsShort(exchange, options) {
    try {
        let result = await exchange.getRecentTransactionDetailsShort(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getRecentTransactionDetailsShort(myOkxAccount)
```

### Get Transaction Details (last 3 months)

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-get-transaction-details-last-3-months>
{% endhint %}

#### Function Name:

```javascript
getRecentTransactionDetailsLong()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getRecentTransactionDetailsLong(exchange, options) {
    try {
        let result = await exchange.getRecentTransactionDetailsLong(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getRecentTransactionDetailsLong(myOkxAccount)
```

## Placing & Editing Algo Orders

### Place Algo Order

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-place-algo-order>
{% endhint %}

#### Function Name:

```javascript
placeAlgoOrder()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function placeAlgoOrder(exchange, options) {
    try {
        let result = await exchange.placeAlgoOrder(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await placeAlgoOrder(myOkxAccount, {
    instId:"BTC-USDT",
    tdMode:"cross",
    side:"buy",
    ordType:"conditional",
    sz:"2",
    tpTriggerPx:"15",
    tpOrdPx:"18")
    })
```

### Cancel Algo Order

{% hint style="warning" %}
This endpoint is currently under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-algo-order>
{% endhint %}

#### Function Name:

```javascript
cancelAlgoOrder()
```

#### Usage:

```javascript
// 
```

### Cancel Advance Algo Order

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-advance-algo-order>
{% endhint %}

#### Function Name:

```javascript
cancelAdvAlgoOrder()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function cancelAdvAlgoOrder(exchange, options) {
    try {
        let result = await exchange.cancelAdvAlgoOrder(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await cancelAdvAlgoOrder(myOkxAccount, 
[
    {
        algoId:"198273485",
        instId:"BTC-USDT"
    },
    {
        algoId:"198273485",
        instId:"BTC-USDT"
    }
])
```

### Get Algo Order List

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-get-algo-order-list>
{% endhint %}

#### Function Name:

```javascript
getAlgoOrderList()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getAlgoOrderList(exchange, options) {
    try {
        let result = await exchange.getAlgoOrderList(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getAlgoOrderList(myOkxAccount, {
            ordType: "conditional"
    })
```

### Get Algo Order History

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-trade-get-algo-order-history>
{% endhint %}

#### Function Name:

```javascript
getAlgoOrderHistory()
```

#### Usage:

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getAlgoOrderHistory(exchange, options) {
    try {
        let result = await exchange.getAlgoOrderHistory(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getAlgoOrderHistory(myOkxAccount, {
            state: "effective",
            ordType: "conditional"
    })
```

## One-Click & Easy Convert

### Get Easy Convert Currency List

{% hint style="warning" %}
This endpoint is currently under development.
{% endhint %}

### Place Easy Convert

{% hint style="warning" %}
This endpoint is currently under development.
{% endhint %}

### Get Easy Convert History

{% hint style="warning" %}
This endpoint is currently under development.
{% endhint %}

### Get One-Click Repay Currency List

{% hint style="warning" %}
This endpoint is currently under development.
{% endhint %}

### Trade One-Click Repay

{% hint style="warning" %}
This endpoint is currently under development.
{% endhint %}

### Get One-Click Repay History

{% hint style="warning" %}
This endpoint is currently under development.
{% endhint %}

## Block Trading

### Get Counterparties

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-get-counterparties>
{% endhint %}

#### Function Name:

```javascript
getCounterparties()
```

#### Usage:

```javascript
// 
```

### Create RFQ

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-create-rfq>
{% endhint %}

#### Function Name:

```javascript
createRfq()
```

#### Usage:

```javascript
// 
```

### Cancel RFQ

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-rfq>
{% endhint %}

#### Function Name:

```javascript
cancelRfq()
```

#### Usage:

```javascript
//
```

### Cancel Multiple RFQ's

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-multiple-rfqs>
{% endhint %}

#### Function Name:

```javascript
cancelBatchRfq()
```

#### Usage:

```javascript
//
```

### Cancel All RFQ's

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-all-rfqs>
{% endhint %}

#### Function Name:

```javascript
cancelAllRfqs()
```

#### Usage:

```javascript
//
```

### Execute Quote

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-execute-quote>
{% endhint %}

#### Function Name:

```javascript
executeQuote()
```

#### Usage:

```javascript
//
```

### Set Quote Products

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-set-quote-products>
{% endhint %}

#### Function Name:

```javascript
//
```

#### Usage:

```javascript
//
```

### Reset MMP Status

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-reset-mmp-status>
{% endhint %}

#### Function Name:

```javascript
//
```

#### Usage:

```javascript
//
```

### Create Quote

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-create-quote>
{% endhint %}

#### Function Name:

```javascript
createQuote()
```

#### Usage:

```javascript
//
```

### Cancel Quote

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-quote>
{% endhint %}

#### Function Name:

```javascript
cancelQuote()
```

#### Usage:

```javascript
//
```

### Cancel Multiple Quotes

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-multiple-quotes>
{% endhint %}

#### Function Name:

```javascript
cancelBatchQuotes()
```

#### Usage:

```javascript
//
```

### Cancel All Quotes

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-all-quotes>
{% endhint %}

#### Function Name:

```javascript
cancelAllQuotes()
```

#### Usage:

```javascript
//
```

### Get RFQ's

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-get-rfqs>
{% endhint %}

#### Function Name:

```javascript
getRfqs()
```

#### Usage:

```javascript
//
```

### Get Quotes

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-get-quotes>
{% endhint %}

#### Function Name:

```javascript
getQuotes()
```

#### Usage:

```javascript
//
```

### Get Trades

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-get-trades>
{% endhint %}

#### Function Name:

```javascript
getUserBlockTrades()
```

#### Usage:

```javascript
//
```

### Get Public Trades

{% hint style="warning" %}
This endpoint is under development
{% endhint %}

{% hint style="info" %}
Please refer to the official OKX API Docs for required parameters.

<https://www.okx.com/docs-v5/en/#rest-api-block-trading-get-public-trades>
{% endhint %}

#### Function Name:

```javascript
getPublicBlockTrades()
```

#### Usage:

```javascript
//
```


---

# 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://docs.compendium.finance/pendax/using-pendax-sdk/okx-functions/trading-and-orders.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.
