> This page is for API Reference.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://okx-demo.ferndocs.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://okx-demo.ferndocs.com/_mcp/server.

# Place grid algo order

POST https://www.okx.com/api/v5/tradingBot/grid/order-algo
Content-Type: application/json

Create a spot grid, contract grid or moon grid algo order for automated grid trading within a defined price range.

Reference: https://okx-demo.ferndocs.com/api/api-reference/grid-trading/place-grid-algo-order

## Authentication

- `OK-ACCESS-KEY` header (required) — Your API key.
- `OK-ACCESS-SIGN` header (required) — Base64-encoded HMAC-SHA256 signature of the prehash string.
- `OK-ACCESS-TIMESTAMP` header (required) — ISO 8601 UTC timestamp, e.g. 2020-12-08T09:08:57.715Z.
- `OK-ACCESS-PASSPHRASE` header (required) — The passphrase you set when creating the API key.

## Request

### Body (application/json)

This endpoint expects an object.

- `instId` (string, required) — Instrument ID, e.g. `BTC-USDT-SWAP`
- `algoOrdType` (enum, required) — Algo order type `grid`: Spot grid `contract_grid`: Contract grid
  - Allowed values: `grid`, `contract_grid`, `moon_grid`
- `maxPx` (string, required) — Upper price of price range
- `minPx` (string, required) — Lower price of price range
- `gridNum` (string, required) — Grid quantity
- `runType` (enum, required) — Grid type `1`: Arithmetic, `2`: Geometric Default is Arithmetic
  - Allowed values: `1`, `2`
- `tpTriggerPx` (string, optional) — TP tigger price Applicable to `Spot grid`/`Contract grid`
- `slTriggerPx` (string, optional) — SL tigger price Applicable to `Spot grid`/`Contract grid`
- `tag` (string, optional) — Order tag
- `quoteSz` (string, optional) — Invest amount for quote currency Either `quoteSz` or `baseSz` is required
- `baseSz` (string, optional) — Invest amount for base currency Either `quoteSz` or `baseSz` is required
- `sz` (string, optional) — Used margin based on `USDT`
- `direction` (enum, optional) — Contract grid type `long`,`short`,`neutral`
  - Allowed values: `long`, `short`, `neutral`
- `lever` (string, optional) — Leverage
- `basePos` (boolean, optional) — Whether or not open a position when the strategy activates Default is `false` Neutral contract grid should omit the parameter
- `tpRatio` (string, optional) — Take profit ratio, 0.1 represents 10%
- `slRatio` (string, optional) — Stop loss ratio, 0.1 represents 10%
- `tradeQuoteCcy` (string, optional) — The quote currency for trading. Only applicable to SPOT. The default value is the quote currency of instId, e.g. USD for BTC-USD.
- `triggerParams` (list of ApiV5TradingBotGridOrderAlgoPostRequestBodyContentApplicationJsonSchemaTriggerParamsItems, optional) — Trigger Parameters Applicable to `Spot grid`/`Contract grid`

## Response

### 200

Successful response

- `code` (string, optional) — Result code. `0` means success; any other value is an error code.
- `msg` (string, optional) — Error message. Empty on success.
- `data` (list of ApiV5TradingBotGridOrderAlgoPostResponsesContentApplicationJsonSchemaDataItems, optional)

## Types

### ApiV5TradingBotGridOrderAlgoPostRequestBodyContentApplicationJsonSchemaTriggerParamsItems

- `triggerAction` (enum, optional) — Trigger action.
  - Allowed values: `start`, `stop`
- `triggerStrategy` (enum, optional) — Trigger strategy.
  - Allowed values: `instant`, `price`, `rsi`
- `delaySeconds` (string, optional) — Delay seconds after triggering.
- `timeframe` (enum, optional) — K-line timeframe used for RSI.
  - Allowed values: `3m`, `5m`, `15m`, `30m`, `1H`, `4H`, `1D`
- `thold` (string, optional) — Threshold value.
- `triggerCond` (enum, optional) — Trigger condition.
  - Allowed values: `cross_up`, `cross_down`, `above`, `below`, `cross`
- `timePeriod` (string, optional) — Time period for the indicator.
- `triggerPx` (string, optional) — Trigger price.
- `stopType` (enum, optional) — Stop type.
  - Allowed values: `1`, `2`

### ApiV5TradingBotGridOrderAlgoPostResponsesContentApplicationJsonSchemaDataItems

- `algoId` (string, optional) — Algo ID
- `algoClOrdId` (string, optional) — Client-supplied Algo ID
- `sCode` (string, optional) — The code of the event execution result, `0` means success.
- `sMsg` (string, optional) — Rejection message if the request is unsuccessful.
- `tag` (string, optional) — Order tag

## Examples

**Request**

```json
{
  "instId": "BTC-USDT",
  "algoOrdType": "grid",
  "maxPx": "5000",
  "minPx": "3000",
  "gridNum": "10",
  "runType": "1"
}
```

**Response**

```json
{
  "code": "0",
  "msg": "",
  "data": [
    {
      "algoId": "447053782921515008",
      "algoClOrdId": "",
      "sCode": "0",
      "sMsg": "",
      "tag": ""
    }
  ]
}
```

**SDK Code**

```python gridTrading_placeGridAlgoOrder_example
import requests

url = "https://www.okx.com/api/v5/tradingBot/grid/order-algo"

payload = {
    "instId": "BTC-USDT",
    "algoOrdType": "grid",
    "maxPx": "5000",
    "minPx": "3000",
    "gridNum": "10",
    "runType": "1"
}
headers = {
    "OK-ACCESS-KEY": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript gridTrading_placeGridAlgoOrder_example
const url = 'https://www.okx.com/api/v5/tradingBot/grid/order-algo';
const options = {
  method: 'POST',
  headers: {'OK-ACCESS-KEY': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"instId":"BTC-USDT","algoOrdType":"grid","maxPx":"5000","minPx":"3000","gridNum":"10","runType":"1"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go gridTrading_placeGridAlgoOrder_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://www.okx.com/api/v5/tradingBot/grid/order-algo"

	payload := strings.NewReader("{\n  \"instId\": \"BTC-USDT\",\n  \"algoOrdType\": \"grid\",\n  \"maxPx\": \"5000\",\n  \"minPx\": \"3000\",\n  \"gridNum\": \"10\",\n  \"runType\": \"1\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("OK-ACCESS-KEY", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby gridTrading_placeGridAlgoOrder_example
require 'uri'
require 'net/http'

url = URI("https://www.okx.com/api/v5/tradingBot/grid/order-algo")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["OK-ACCESS-KEY"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"instId\": \"BTC-USDT\",\n  \"algoOrdType\": \"grid\",\n  \"maxPx\": \"5000\",\n  \"minPx\": \"3000\",\n  \"gridNum\": \"10\",\n  \"runType\": \"1\"\n}"

response = http.request(request)
puts response.read_body
```

```java gridTrading_placeGridAlgoOrder_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://www.okx.com/api/v5/tradingBot/grid/order-algo")
  .header("OK-ACCESS-KEY", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"instId\": \"BTC-USDT\",\n  \"algoOrdType\": \"grid\",\n  \"maxPx\": \"5000\",\n  \"minPx\": \"3000\",\n  \"gridNum\": \"10\",\n  \"runType\": \"1\"\n}")
  .asString();
```

```php gridTrading_placeGridAlgoOrder_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://www.okx.com/api/v5/tradingBot/grid/order-algo', [
  'body' => '{
  "instId": "BTC-USDT",
  "algoOrdType": "grid",
  "maxPx": "5000",
  "minPx": "3000",
  "gridNum": "10",
  "runType": "1"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'OK-ACCESS-KEY' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp gridTrading_placeGridAlgoOrder_example
using RestSharp;

var client = new RestClient("https://www.okx.com/api/v5/tradingBot/grid/order-algo");
var request = new RestRequest(Method.POST);
request.AddHeader("OK-ACCESS-KEY", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"instId\": \"BTC-USDT\",\n  \"algoOrdType\": \"grid\",\n  \"maxPx\": \"5000\",\n  \"minPx\": \"3000\",\n  \"gridNum\": \"10\",\n  \"runType\": \"1\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift gridTrading_placeGridAlgoOrder_example
import Foundation

let headers = [
  "OK-ACCESS-KEY": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "instId": "BTC-USDT",
  "algoOrdType": "grid",
  "maxPx": "5000",
  "minPx": "3000",
  "gridNum": "10",
  "runType": "1"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://www.okx.com/api/v5/tradingBot/grid/order-algo")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```