TradesRequestBuilder class
Builds requests for trades.
A trade represents the fulfillment of an offer on the Stellar network. Trades occur when offers are matched, either through direct trading or as part of path payments. Each trade involves two parties and two assets - a base asset and a counter asset.
Trades can be filtered by:
- Account (all trades involving an account)
- Trading pair (base and counter assets)
- Offer ID (trades for a specific offer)
- Liquidity pool (trades involving pool shares)
- Trade type (orderbook trades vs liquidity pool trades)
Example:
// Get recent trades for an account
var trades = await sdk.trades
.forAccount(accountId)
.order(RequestBuilderOrder.DESC)
.limit(20)
.execute();
// Get trades for a specific trading pair
var pairTrades = await sdk.trades
.baseAsset(Asset.createNonNativeAsset('XLM', issuerId))
.counterAsset(Asset.createNonNativeAsset('USDC', issuerId))
.execute();
// Stream new trades in real-time
sdk.trades
.cursor('now')
.stream()
.listen((trade) {
print('Trade: ${trade.baseAmount} ${trade.baseAssetType}');
print('Price: ${trade.price}');
});
See also:
- Inheritance
-
- Object
- RequestBuilder
- TradesRequestBuilder
Constructors
- TradesRequestBuilder(Client httpClient, Uri serverURI)
- Creates a TradesRequestBuilder for querying trades from Horizon.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- httpClient ↔ Client
-
getter/setter pairinherited
-
queryParameters
↔ Map<
String, String> -
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- uriBuilder ↔ Uri
-
getter/setter pairinherited
Methods
-
baseAsset(
Asset asset) → TradesRequestBuilder - Filters trades by base asset.
-
buildUri(
) → Uri -
Constructs the complete URI for the API request.
inherited
-
counterAsset(
Asset asset) → TradesRequestBuilder - Filters trades by counter asset.
-
cursor(
String token) → TradesRequestBuilder -
Sets the cursor for pagination to start returning records from a specific point.
Returns this builder for method chaining.
override
-
encodeAsset(
Asset asset) → String -
Encodes an asset to its string representation for API requests.
inherited
-
encodeAssets(
List< Asset> assets) → String -
Encodes a list of assets to comma-separated string for API requests.
inherited
-
execute(
) → Future< Page< TradeResponse> > - Builds and executes the request.
-
forAccount(
String accountId) → TradesRequestBuilder - Filters trades by account.
-
limit(
int number) → TradesRequestBuilder -
Sets the maximum number of records to return in a single page.
Returns this builder for method chaining.
override
-
liquidityPoolId(
String poolId) → TradesRequestBuilder - Filters trades by liquidity pool.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
offerId(
String offerId) → TradesRequestBuilder - Filters trades by offer ID.
-
order(
RequestBuilderOrder direction) → TradesRequestBuilder -
Sets the sort order for returned records (ascending or descending).
Returns this builder for method chaining.
override
-
setSegments(
List< String> segments) → RequestBuilder -
Sets the URL path segments for this request.
inherited
-
stream(
) → Stream< TradeResponse> - 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. See: Stellar developer docs
-
streamEvents<
T> (T fromJson(dynamic json)) → Stream< T> -
Opens a stream of Server-Sent Events on the URI built by this builder
and emits one
Tper received record, parsed withfromJson.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
tradeType(
String tradeType) → TradesRequestBuilder - Filters trades by trade type.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
requestExecute(
Client httpClient, Uri uri) → Future< Page< TradeResponse> > -
Executes an HTTP request to fetch trades from a specific URI.
override