Package org.stellar.sdk.requests
Class TradesRequestBuilder
java.lang.Object
org.stellar.sdk.requests.RequestBuilder
org.stellar.sdk.requests.TradesRequestBuilder
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.stellar.sdk.requests.RequestBuilder
RequestBuilder.Order -
Constructor Summary
ConstructorsConstructorDescriptionTradesRequestBuilder(okhttp3.OkHttpClient httpClient, okhttp3.HttpUrl serverURI) -
Method Summary
Modifier and TypeMethodDescriptionFilters trades to only those involving the given base asset.counterAsset(Asset asset) Filters trades to only those involving the given counter asset.Setscursorparameter on the request.execute()Build and execute request.static Page<TradeResponse> execute(okhttp3.OkHttpClient httpClient, okhttp3.HttpUrl uri) forAccount(@NonNull String account) Builds request toGET /accounts/{account}/tradesforLiquidityPool(String liquidityPoolId) Builds request toGET /liquidity_pools/{poolID}/tradesforTradeType(@NonNull String tradeType) Returns all trades that of a specific type.limit(int number) Setslimitparameter on the request.Filters trades to only those that originated from the given offer.stream(EventListener<TradeResponse> listener) An overloaded version ofstream(EventListener, long)with default reconnect timeout.stream(EventListener<TradeResponse> listener, long reconnectTimeout) Allows to stream SSE events from horizon.Methods inherited from class org.stellar.sdk.requests.RequestBuilder
order, setAssetParameter, setAssetsParameter
-
Constructor Details
-
TradesRequestBuilder
public TradesRequestBuilder(okhttp3.OkHttpClient httpClient, okhttp3.HttpUrl serverURI)
-
-
Method Details
-
baseAsset
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
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
Builds request toGET /accounts/{account}/trades- Parameters:
account- Account for which to get trades- Returns:
- this builder instance for chaining
- See Also:
-
forLiquidityPool
Builds request toGET /liquidity_pools/{poolID}/trades- Parameters:
liquidityPoolId- Liquidity pool for which to get trades- Returns:
- this builder instance for chaining
- See Also:
-
forTradeType
Returns all trades that of a specific type.- Parameters:
tradeType- type- Returns:
- current
TradesRequestBuilderinstance - See Also:
-
execute
- Parameters:
httpClient-OkHttpClientto use to send the request.uri-HttpUrlURI to send the request to.- Returns:
PageofTradeResponse- Throws:
NetworkException- All the exceptions below are subclasses of NetworkExceptionBadRequestException- 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 serverRequestTimeoutException- When Horizon returns aTimeoutor connection timeout occurredUnknownResponseException- if the server returns an unknown status codeConnectionErrorException- When the request cannot be executed due to cancellation or connectivity problems, etc.
-
execute
Build and execute request.- Returns:
PageofTradeResponse- Throws:
NetworkException- All the exceptions below are subclasses of NetworkExceptionBadRequestException- 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 serverRequestTimeoutException- When Horizon returns aTimeoutor connection timeout occurredUnknownResponseException- if the server returns an unknown status codeConnectionErrorException- When the request cannot be executed due to cancellation or connectivity problems, etc.
-
offerId
Filters trades to only those that originated from the given offer. Passnullto clear a previously set offer ID filter.- Parameters:
offerId- the offer ID to filter by, ornullto remove the filter- Returns:
- this builder instance for chaining
-
cursor
Description copied from class:RequestBuilderSetscursorparameter 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:
cursorin classRequestBuilder- 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
Description copied from class:RequestBuilderSetslimitparameter on the request. It defines maximum number of records to return. For range and default values check documentation of the endpoint requested.- Overrides:
limitin classRequestBuilder- 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-EventListenerimplementation withTradeResponsetypereconnectTimeout- Custom stream connection timeout in ms- Returns:
- EventSource object, so you can
close()connection when not needed anymore - See Also:
-
stream
An overloaded version ofstream(EventListener, long)with default reconnect timeout.- Parameters:
listener- the event listener to receive events- Returns:
- an
SSEStreamfor real-time event streaming
-