-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
540 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/oracle/AggregatePriceSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.xrpl.xrpl4j.model.client.oracle; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.google.common.annotations.Beta; | ||
import com.google.common.primitives.UnsignedLong; | ||
import org.immutables.value.Value.Immutable; | ||
import org.immutables.value.Value.Lazy; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* Statistics from collected oracle prices. | ||
*/ | ||
@Beta | ||
@Immutable | ||
@JsonSerialize(as = ImmutableAggregatePriceSet.class) | ||
@JsonDeserialize(as = ImmutableAggregatePriceSet.class) | ||
public interface AggregatePriceSet { | ||
|
||
/** | ||
* Construct a {@code AggregatePriceSet} builder. | ||
* | ||
* @return An {@link ImmutableAggregatePriceSet.Builder}. | ||
*/ | ||
static ImmutableAggregatePriceSet.Builder builder() { | ||
return ImmutableAggregatePriceSet.builder(); | ||
} | ||
|
||
/** | ||
* The simple mean price. | ||
* | ||
* @return A {@link String}. | ||
*/ | ||
@JsonProperty("mean") | ||
String meanString(); | ||
|
||
/** | ||
* The simple mean price as a {@link BigDecimal}. | ||
* | ||
* @return A {@link BigDecimal}. | ||
*/ | ||
@Lazy | ||
@JsonIgnore | ||
default BigDecimal mean() { | ||
return new BigDecimal(meanString()); | ||
} | ||
|
||
/** | ||
* The size of the data set to calculate the mean. | ||
* | ||
* @return An {@link UnsignedLong}. | ||
*/ | ||
UnsignedLong size(); | ||
|
||
/** | ||
* The standard deviation. | ||
* | ||
* @return A {@link String}. | ||
*/ | ||
@JsonProperty("standard_deviation") | ||
String standardDeviationString(); | ||
|
||
/** | ||
* The standard deviation as a {@link BigDecimal}. | ||
* | ||
* @return A {@link BigDecimal}. | ||
*/ | ||
@Lazy | ||
@JsonIgnore | ||
default BigDecimal standardDeviation() { | ||
return new BigDecimal(standardDeviationString()); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...ore/src/main/java/org/xrpl/xrpl4j/model/client/oracle/GetAggregatePriceRequestParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.xrpl.xrpl4j.model.client.oracle; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.google.common.annotations.Beta; | ||
import com.google.common.primitives.UnsignedInteger; | ||
import org.immutables.value.Value.Immutable; | ||
import org.xrpl.xrpl4j.model.client.XrplRequestParams; | ||
import org.xrpl.xrpl4j.model.client.common.LedgerSpecifier; | ||
import org.xrpl.xrpl4j.model.client.ledger.OracleLedgerEntryParams; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Request parameters for the {@code get_aggregate_price} RPC method. | ||
*/ | ||
@Beta | ||
@Immutable | ||
@JsonSerialize(as = ImmutableGetAggregatePriceRequestParams.class) | ||
@JsonDeserialize(as = ImmutableGetAggregatePriceRequestParams.class) | ||
public interface GetAggregatePriceRequestParams extends XrplRequestParams { | ||
|
||
/** | ||
* Construct a {@code GetAggregatePriceRequestParams} builder. | ||
* | ||
* @return An {@link ImmutableGetAggregatePriceRequestParams.Builder}. | ||
*/ | ||
static ImmutableGetAggregatePriceRequestParams.Builder builder() { | ||
return ImmutableGetAggregatePriceRequestParams.builder(); | ||
} | ||
|
||
/** | ||
* Specifies the ledger version to request. A ledger version can be specified by ledger hash, | ||
* numerical ledger index, or a shortcut value. | ||
* | ||
* @return A {@link LedgerSpecifier} specifying the ledger version to request. | ||
*/ | ||
@JsonUnwrapped | ||
LedgerSpecifier ledgerSpecifier(); | ||
|
||
/** | ||
* The currency code of the asset to be priced. | ||
* | ||
* @return A {@link String}. | ||
*/ | ||
@JsonProperty("base_asset") | ||
String baseAsset(); | ||
|
||
/** | ||
* The currency code of the asset to quote the price of the base asset. | ||
* | ||
* @return A {@link String}. | ||
*/ | ||
@JsonProperty("quote_asset") | ||
String quoteAsset(); | ||
|
||
/** | ||
* The percentage of outliers to trim. Valid trim range is 1-25. If included, the API returns statistics for the | ||
* trimmed mean. | ||
* | ||
* @return An {@link Optional} {@link UnsignedInteger}. | ||
*/ | ||
Optional<UnsignedInteger> trim(); | ||
|
||
/** | ||
* Defines a time range in seconds for filtering out older price data. Default value is 0, which doesn't filter any | ||
* data. | ||
* | ||
* @return An {@link Optional} {@link UnsignedInteger}. | ||
*/ | ||
@JsonProperty("trim_threshold") | ||
Optional<UnsignedInteger> trimThreshold(); | ||
|
||
/** | ||
* A list of oracle identifiers. | ||
* | ||
* @return A {@link List} of {@link OracleLedgerEntryParams}. | ||
*/ | ||
List<OracleLedgerEntryParams> oracles(); | ||
|
||
} |
160 changes: 160 additions & 0 deletions
160
xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/oracle/GetAggregatePriceResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package org.xrpl.xrpl4j.model.client.oracle; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.google.common.annotations.Beta; | ||
import com.google.common.primitives.UnsignedInteger; | ||
import org.immutables.value.Value; | ||
import org.immutables.value.Value.Immutable; | ||
import org.immutables.value.Value.Lazy; | ||
import org.xrpl.xrpl4j.model.client.XrplResult; | ||
import org.xrpl.xrpl4j.model.client.common.LedgerIndex; | ||
import org.xrpl.xrpl4j.model.transactions.Hash256; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Result object for {@code get_aggregate_price} RPC calls. | ||
*/ | ||
@Beta | ||
@Immutable | ||
@JsonSerialize(as = ImmutableGetAggregatePriceResult.class) | ||
@JsonDeserialize(as = ImmutableGetAggregatePriceResult.class) | ||
public interface GetAggregatePriceResult extends XrplResult { | ||
|
||
/** | ||
* Construct a {@code GetAggregatePriceResult} builder. | ||
* | ||
* @return An {@link ImmutableGetAggregatePriceResult.Builder}. | ||
*/ | ||
static ImmutableGetAggregatePriceResult.Builder builder() { | ||
return ImmutableGetAggregatePriceResult.builder(); | ||
} | ||
|
||
/** | ||
* The statistics from the collected oracle prices. | ||
* | ||
* @return An {@link AggregatePriceSet}. | ||
*/ | ||
@JsonProperty("entire_set") | ||
AggregatePriceSet entireSet(); | ||
|
||
/** | ||
* The trimmed statistics from the collected oracle prices. Only appears if the trim field was specified in the | ||
* request. | ||
* | ||
* @return An {@link Optional} {@link AggregatePriceSet}. | ||
*/ | ||
@JsonProperty("trimmed_set") | ||
Optional<AggregatePriceSet> trimmedSet(); | ||
|
||
/** | ||
* The median price, as a {@link String}. | ||
* | ||
* @return A {@link String}. | ||
*/ | ||
@JsonProperty("median") | ||
String medianString(); | ||
|
||
/** | ||
* Get the median price as a {@link BigDecimal}. | ||
* | ||
* @return A {@link BigDecimal}. | ||
*/ | ||
@Lazy | ||
@JsonIgnore | ||
default BigDecimal median() { | ||
return new BigDecimal(medianString()); | ||
} | ||
|
||
/** | ||
* The most recent timestamp out of all LastUpdateTime values. | ||
* | ||
* @return An {@link UnsignedInteger}. | ||
*/ | ||
UnsignedInteger time(); | ||
|
||
/** | ||
* The identifying Hash of the ledger version used to generate this response. | ||
* | ||
* @return A {@link Hash256} containing the ledger hash. | ||
*/ | ||
@JsonProperty("ledger_hash") | ||
Optional<Hash256> ledgerHash(); | ||
|
||
/** | ||
* Get {@link #ledgerHash()}, or throw an {@link IllegalStateException} if {@link #ledgerHash()} is empty. | ||
* | ||
* @return The value of {@link #ledgerHash()}. | ||
* | ||
* @throws IllegalStateException If {@link #ledgerHash()} is empty. | ||
*/ | ||
@JsonIgnore | ||
@Value.Auxiliary | ||
default Hash256 ledgerHashSafe() { | ||
return ledgerHash() | ||
.orElseThrow(() -> new IllegalStateException("Result did not contain a ledgerHash.")); | ||
} | ||
|
||
/** | ||
* The Ledger Index of the ledger version used to generate this response. Only present in responses to requests with | ||
* ledger_index = "validated" or "closed". | ||
* | ||
* @return A {@link LedgerIndex}. | ||
*/ | ||
@JsonProperty("ledger_index") | ||
Optional<LedgerIndex> ledgerIndex(); | ||
|
||
/** | ||
* Get {@link #ledgerIndex()}, or throw an {@link IllegalStateException} if {@link #ledgerIndex()} is empty. | ||
* | ||
* @return The value of {@link #ledgerIndex()}. | ||
* | ||
* @throws IllegalStateException If {@link #ledgerIndex()} is empty. | ||
*/ | ||
@JsonIgnore | ||
@Value.Auxiliary | ||
default LedgerIndex ledgerIndexSafe() { | ||
return ledgerIndex() | ||
.orElseThrow(() -> new IllegalStateException("Result did not contain a ledgerIndex.")); | ||
} | ||
|
||
/** | ||
* The ledger index of the current open ledger, which was used when retrieving this information. Only present in | ||
* responses to requests with ledger_index = "current". | ||
* | ||
* @return An optionally-present {@link LedgerIndex} representing the current ledger index. | ||
*/ | ||
@JsonProperty("ledger_current_index") | ||
Optional<LedgerIndex> ledgerCurrentIndex(); | ||
|
||
/** | ||
* Get {@link #ledgerCurrentIndex()}, or throw an {@link IllegalStateException} if {@link #ledgerCurrentIndex()} is | ||
* empty. | ||
* | ||
* @return The value of {@link #ledgerCurrentIndex()}. | ||
* | ||
* @throws IllegalStateException If {@link #ledgerCurrentIndex()} is empty. | ||
*/ | ||
@JsonIgnore | ||
@Value.Auxiliary | ||
default LedgerIndex ledgerCurrentIndexSafe() { | ||
return ledgerCurrentIndex() | ||
.orElseThrow(() -> new IllegalStateException("Result did not contain a ledgerCurrentIndex.")); | ||
} | ||
|
||
/** | ||
* If true, the information in this response comes from a validated ledger version. Otherwise, the information is | ||
* subject to change. | ||
* | ||
* @return {@code true} if the information in this response comes from a validated ledger version, {@code false} if | ||
* not. | ||
*/ | ||
@Value.Default | ||
default boolean validated() { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.