> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://okx-demo.ferndocs.com/api/api-reference/market/get-history-trades/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://okx-demo.ferndocs.com/_mcp/server. # Get trades history GET https://www.okx.com/api/v5/market/history-trades Retrieve the recent transactions of an instrument from the last 3 months with pagination. Reference: https://okx-demo.ferndocs.com/api/api-reference/market/get-history-trades ## Request ### Query parameters - `instId` (string, required) — Instrument ID, e.g. `BTC-USDT` - `type` (enum, optional) — Pagination Type `1`: tradeId `2`: timestamp The default is `1` - Allowed values: `1`, `2` - `after` (string, optional) — Pagination of data to return records earlier than the requested tradeId or ts. - `before` (string, optional) — Pagination of data to return records newer than the requested tradeId. Do not support timestamp for pagination. The latest data will be returned when using `before` individually - `limit` (string, optional) — Number of results per request. The maximum and default both are `100` ## 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 ApiV5MarketHistoryTradesGetResponsesContentApplicationJsonSchemaDataItems, optional) ## Types ### ApiV5MarketHistoryTradesGetResponsesContentApplicationJsonSchemaDataItems - `instId` (string, optional) — Instrument ID - `tradeId` (string, optional) — Trade ID - `px` (string, optional) — Trade price - `sz` (string, optional) — Trade quantity For spot trading, the unit is base currency For `FUTURES`/`SWAP`/`OPTION`, the unit is contract. - `side` (string, optional) — Trade side of taker `buy` `sell` - `ts` (string, optional) — Trade time, Unix timestamp format in milliseconds, e.g. `1597026383085`. ## Examples **Response** ```json { "code": "0", "msg": "", "data": [ { "instId": "BTC-USDT", "tradeId": "242720720", "px": "29963.2", "sz": "0.00001", "side": "sell", "ts": "1654161646974", "source": "0" }, { "instId": "BTC-USDT", "tradeId": "242720719", "px": "29964.1", "sz": "0.00001", "side": "sell", "ts": "1654161641568", "source": "0" } ] } ``` **SDK Code** ```python market_getHistoryTrades_example import requests url = "https://www.okx.com/api/v5/market/history-trades" querystring = {"instId":"BTC-USDT"} response = requests.get(url, params=querystring) print(response.json()) ``` ```javascript market_getHistoryTrades_example const url = 'https://www.okx.com/api/v5/market/history-trades?instId=BTC-USDT'; const options = {method: 'GET'}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go market_getHistoryTrades_example package main import ( "fmt" "net/http" "io" ) func main() { url := "https://www.okx.com/api/v5/market/history-trades?instId=BTC-USDT" req, _ := http.NewRequest("GET", url, nil) res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby market_getHistoryTrades_example require 'uri' require 'net/http' url = URI("https://www.okx.com/api/v5/market/history-trades?instId=BTC-USDT") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) response = http.request(request) puts response.read_body ``` ```java market_getHistoryTrades_example import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://www.okx.com/api/v5/market/history-trades?instId=BTC-USDT") .asString(); ``` ```php market_getHistoryTrades_example request('GET', 'https://www.okx.com/api/v5/market/history-trades?instId=BTC-USDT'); echo $response->getBody(); ``` ```csharp market_getHistoryTrades_example using RestSharp; var client = new RestClient("https://www.okx.com/api/v5/market/history-trades?instId=BTC-USDT"); var request = new RestRequest(Method.GET); IRestResponse response = client.Execute(request); ``` ```swift market_getHistoryTrades_example import Foundation let request = NSMutableURLRequest(url: NSURL(string: "https://www.okx.com/api/v5/market/history-trades?instId=BTC-USDT")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" 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() ```