# getSwapTrades GET https://api.0x.org/trade-analytics/swap Get the list of completed swap trades. Returns a maximum of 200 trades per request. Visit [here](https://docs.0x.org/trade-analytics-api/introduction) for more details about how the API works. Reference: https://docs.0x.org/api-reference/openapi-yaml/trade-analytics/trade-analytics-swap ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: getSwapTrades version: endpoint_tradeAnalytics.tradeAnalytics::swap paths: /trade-analytics/swap: get: operationId: trade-analytics-swap summary: getSwapTrades description: >- Get the list of completed swap trades. Returns a maximum of 200 trades per request. Visit [here](https://docs.0x.org/trade-analytics-api/introduction) for more details about how the API works. tags: - - subpackage_tradeAnalytics parameters: - name: cursor in: query description: >- A pagination cursor used to fetch the next page of trades. It should be set to `null` for the initial request; otherwise, it should be the value of `nextCursor` that is returned from `getSwapTrades` or `getGaslessTrades` calls. required: false schema: type: string - name: startTimestamp in: query description: >- Unix timestamp in seconds, specifying the starting point of the time range filter. Only trades completed on or after this timestamp will be included in the response. required: false schema: type: integer - name: endTimestamp in: query description: >- Unix timestamp in seconds, specifying the end point of the time range filter. Only trades completed on or before this timestamp will be included in the response. required: false schema: type: integer - name: 0x-api-key in: header description: Visit dashboard.0x.org to get your API Key required: true schema: type: string - name: 0x-version in: header description: API version required: true schema: type: string responses: '200': description: Successful response content: application/json: schema: $ref: >- #/components/schemas/Trade Analytics_tradeAnalytics::swap_Response_200 '400': description: 400 error response content: {} '500': description: 500 error response content: {} components: schemas: TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsFeesIntegratorFee: type: object properties: token: type: - string - 'null' description: >- The contract address of the token in which the integrator collected a fee amount: type: - string - 'null' description: The amount of the integrator fee, formatted by the token decimals amountUsd: type: - string - 'null' description: The amount of the integrator fee in USD. required: - token - amount - amountUsd TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsFeesZeroExFee: type: object properties: token: type: - string - 'null' description: The contract address of the token in which 0x collected a fee amount: type: - string - 'null' description: The amount of the 0x fee, formatted by the token decimals amountUsd: type: - string - 'null' description: The amount of the 0x fee in USD. required: - token - amount - amountUsd TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsFees: type: object properties: integratorFee: oneOf: - $ref: >- #/components/schemas/TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsFeesIntegratorFee - type: 'null' description: The details about the fee collected by integrator zeroExFee: oneOf: - $ref: >- #/components/schemas/TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsFeesZeroExFee - type: 'null' description: The details about the fee collected by 0x required: - integratorFee - zeroExFee TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsProtocolVersion: type: string enum: - value: 0xv4 - value: Settler TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsTokensItems: type: object properties: address: type: string description: The contract address of the token symbol: type: - string - 'null' description: The symbol of the token required: - address - symbol TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsService: type: string enum: - value: swap TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItems: type: object properties: appName: type: string description: The name of the app that initiated the trade blockNumber: type: string description: The block number at which the trade was executed buyToken: type: string description: The contract address of the token received by the taker buyAmount: type: - string - 'null' description: >- The settled amount on the `buyToken`, formatted by the token decimals chainId: type: integer description: The ID of the chain where the trade was executed chainName: type: string description: The name of the chain where the trade was executed fees: $ref: >- #/components/schemas/TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsFees description: The details about fees collected for the trade gasUsed: type: string description: The amount of gas used in the trade protocolVersion: $ref: >- #/components/schemas/TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsProtocolVersion description: The version of the 0x protocol used to execute the trade sellToken: type: string description: The contract address of the token spent by the taker sellAmount: type: - string - 'null' description: The amount of the `sellToken`, formatted by the token decimals slippageBps: type: - string - 'null' description: The slippage of the `buyToken` in bps taker: type: string description: The wallet address of the taker​ timestamp: type: integer description: The timestamp of the block containing the trade tokens: type: array items: $ref: >- #/components/schemas/TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsTokensItems description: Properties of the tokens involved in the trade transactionHash: type: string description: The trade's transaction hash volumeUsd: type: - string - 'null' description: >- The total volume of the trade in USD. This value is based on an estimate of the token price at the point of execution. zid: type: string description: The `zid` corresponding to the trade service: $ref: >- #/components/schemas/TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItemsService required: - appName - blockNumber - buyToken - buyAmount - chainId - chainName - fees - gasUsed - protocolVersion - sellToken - sellAmount - slippageBps - taker - timestamp - tokens - transactionHash - volumeUsd - zid - service Trade Analytics_tradeAnalytics::swap_Response_200: type: object properties: nextCursor: type: - string - 'null' description: >- The cursor to fetch the next page of trades. If not present, there are no more trades to fetch for given parameters. trades: type: array items: $ref: >- #/components/schemas/TradeAnalyticsSwapGetResponsesContentApplicationJsonSchemaTradesItems zid: type: string description: The unique ZeroEx identifier of the request required: - nextCursor - trades - zid ``` ## SDK Code Examples ```python import requests url = "https://api.0x.org/trade-analytics/swap" querystring = {"cursor":"eyJ0aW1lc3RhbXAiOjE3MjkwMzIyMTAsInppZCI6IjB4N2FjM2NlMzExNjA2NzU5MGY5M2U3MWVmIn0=","startTimestamp":"1729032210","endTimestamp":"1729032211"} headers = { "0x-api-key": "0x-api-key", "0x-version": "v2" } response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` ```javascript const url = 'https://api.0x.org/trade-analytics/swap?cursor=eyJ0aW1lc3RhbXAiOjE3MjkwMzIyMTAsInppZCI6IjB4N2FjM2NlMzExNjA2NzU5MGY5M2U3MWVmIn0%3D&startTimestamp=1729032210&endTimestamp=1729032211'; const options = {method: 'GET', headers: {'0x-api-key': '0x-api-key', '0x-version': 'v2'}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.0x.org/trade-analytics/swap?cursor=eyJ0aW1lc3RhbXAiOjE3MjkwMzIyMTAsInppZCI6IjB4N2FjM2NlMzExNjA2NzU5MGY5M2U3MWVmIn0%3D&startTimestamp=1729032210&endTimestamp=1729032211" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("0x-api-key", "0x-api-key") req.Header.Add("0x-version", "v2") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.0x.org/trade-analytics/swap?cursor=eyJ0aW1lc3RhbXAiOjE3MjkwMzIyMTAsInppZCI6IjB4N2FjM2NlMzExNjA2NzU5MGY5M2U3MWVmIn0%3D&startTimestamp=1729032210&endTimestamp=1729032211") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["0x-api-key"] = '0x-api-key' request["0x-version"] = 'v2' response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://api.0x.org/trade-analytics/swap?cursor=eyJ0aW1lc3RhbXAiOjE3MjkwMzIyMTAsInppZCI6IjB4N2FjM2NlMzExNjA2NzU5MGY5M2U3MWVmIn0%3D&startTimestamp=1729032210&endTimestamp=1729032211") .header("0x-api-key", "0x-api-key") .header("0x-version", "v2") .asString(); ``` ```php request('GET', 'https://api.0x.org/trade-analytics/swap?cursor=eyJ0aW1lc3RhbXAiOjE3MjkwMzIyMTAsInppZCI6IjB4N2FjM2NlMzExNjA2NzU5MGY5M2U3MWVmIn0%3D&startTimestamp=1729032210&endTimestamp=1729032211', [ 'headers' => [ '0x-api-key' => '0x-api-key', '0x-version' => 'v2', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.0x.org/trade-analytics/swap?cursor=eyJ0aW1lc3RhbXAiOjE3MjkwMzIyMTAsInppZCI6IjB4N2FjM2NlMzExNjA2NzU5MGY5M2U3MWVmIn0%3D&startTimestamp=1729032210&endTimestamp=1729032211"); var request = new RestRequest(Method.GET); request.AddHeader("0x-api-key", "0x-api-key"); request.AddHeader("0x-version", "v2"); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "0x-api-key": "0x-api-key", "0x-version": "v2" ] let request = NSMutableURLRequest(url: NSURL(string: "https://api.0x.org/trade-analytics/swap?cursor=eyJ0aW1lc3RhbXAiOjE3MjkwMzIyMTAsInppZCI6IjB4N2FjM2NlMzExNjA2NzU5MGY5M2U3MWVmIn0%3D&startTimestamp=1729032210&endTimestamp=1729032211")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers 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() ```