Class TradesRequestBuilder

java.lang.Object
org.stellar.sdk.requests.RequestBuilder
org.stellar.sdk.requests.TradesRequestBuilder

public class TradesRequestBuilder extends RequestBuilder
Builds requests to the Horizon /trades endpoint.

Retrieves completed trades on the Stellar DEX, with optional filters by asset pair, offer, account, or liquidity pool.

See Also:
  • Constructor Details

    • TradesRequestBuilder

      public TradesRequestBuilder(okhttp3.OkHttpClient httpClient, okhttp3.HttpUrl serverURI)
  • Method Details

    • baseAsset

      public TradesRequestBuilder baseAsset(Asset asset)
      Filters trades to only those involving the given base asset.
      Parameters:
      asset - the base asset to filter by
      Returns:
      this builder instance for chaining
    • counterAsset

      public TradesRequestBuilder counterAsset(Asset asset)
      Filters trades to only those involving the given counter asset.
      Parameters:
      asset - the counter asset to filter by
      Returns:
      this builder instance for chaining
    • forAccount

      public TradesRequestBuilder forAccount(@NonNull @NonNull String account)
      Builds request to GET /accounts/{account}/trades
      Parameters:
      account - Account for which to get trades
      Returns:
      this builder instance for chaining
      See Also:
    • forLiquidityPool

      public TradesRequestBuilder forLiquidityPool(String liquidityPoolId)
      Builds request to GET /liquidity_pools/{poolID}/trades
      Parameters:
      liquidityPoolId - Liquidity pool for which to get trades
      Returns:
      this builder instance for chaining
      See Also:
    • forTradeType

      public TradesRequestBuilder forTradeType(@NonNull @NonNull String tradeType)
      Returns all trades that of a specific type.
      Parameters:
      tradeType - type
      Returns:
      current TradesRequestBuilder instance
      See Also:
    • execute

      public static Page<TradeResponse> execute(okhttp3.OkHttpClient httpClient, okhttp3.HttpUrl uri)
      Requests specific uri and returns Page of TradeResponse.
      Parameters:
      httpClient - OkHttpClient to use to send the request.
      uri - HttpUrl URI to send the request to.
      Returns:
      Page of TradeResponse
      Throws:
      NetworkException - All the exceptions below are subclasses of NetworkException
      BadRequestException - if the request fails due to a bad request (4xx)
      BadResponseException - if the request fails due to a bad response from the server (5xx)
      TooManyRequestsException - if the request fails due to too many requests sent to the server
      RequestTimeoutException - When Horizon returns a Timeout or connection timeout occurred
      UnknownResponseException - if the server returns an unknown status code
      ConnectionErrorException - When the request cannot be executed due to cancellation or connectivity problems, etc.
    • execute

      public Page<TradeResponse> execute()
      Build and execute request.
      Returns:
      Page of TradeResponse
      Throws:
      NetworkException - All the exceptions below are subclasses of NetworkException
      BadRequestException - if the request fails due to a bad request (4xx)
      BadResponseException - if the request fails due to a bad response from the server (5xx)
      TooManyRequestsException - if the request fails due to too many requests sent to the server
      RequestTimeoutException - When Horizon returns a Timeout or connection timeout occurred
      UnknownResponseException - if the server returns an unknown status code
      ConnectionErrorException - When the request cannot be executed due to cancellation or connectivity problems, etc.
    • offerId

      public TradesRequestBuilder offerId(Long offerId)
      Filters trades to only those that originated from the given offer. Pass null to clear a previously set offer ID filter.
      Parameters:
      offerId - the offer ID to filter by, or null to remove the filter
      Returns:
      this builder instance for chaining
    • cursor

      public TradesRequestBuilder cursor(String token)
      Description copied from class: RequestBuilder
      Sets cursor parameter on the request. A cursor is a value that points to a specific location in a collection of resources. The cursor attribute itself is an opaque value meaning that users should not try to parse it.
      Overrides:
      cursor in class RequestBuilder
      Parameters:
      token - A cursor is a value that points to a specific location in a collection of resources.
      Returns:
      this builder instance for chaining
      See Also:
    • limit

      public TradesRequestBuilder limit(int number)
      Description copied from class: RequestBuilder
      Sets limit parameter on the request. It defines maximum number of records to return. For range and default values check documentation of the endpoint requested.
      Overrides:
      limit in class RequestBuilder
      Parameters:
      number - maximum number of records to return
      Returns:
      this builder instance for chaining
    • stream

      public SSEStream<TradeResponse> stream(EventListener<TradeResponse> listener, long reconnectTimeout)
      Allows to stream SSE events from horizon. Certain endpoints in Horizon can be called in streaming mode using Server-Sent Events. This mode will keep the connection to horizon open and horizon will continue to return responses as ledgers close.
      Parameters:
      listener - EventListener implementation with TradeResponse type
      reconnectTimeout - Custom stream connection timeout in ms
      Returns:
      EventSource object, so you can close() connection when not needed anymore
      See Also:
    • stream

      public SSEStream<TradeResponse> stream(EventListener<TradeResponse> listener)
      An overloaded version of stream(EventListener, long) with default reconnect timeout.
      Parameters:
      listener - the event listener to receive events
      Returns:
      an SSEStream for real-time event streaming