diff --git a/packages/xrpl/src/models/common/index.ts b/packages/xrpl/src/models/common/index.ts index 3a60588f96..d9ebc7fe7a 100644 --- a/packages/xrpl/src/models/common/index.ts +++ b/packages/xrpl/src/models/common/index.ts @@ -54,6 +54,7 @@ export interface Memo { } export type StreamType = + | 'book_changes' | 'consensus' | 'ledger' | 'manifests' diff --git a/packages/xrpl/src/models/methods/subscribe.ts b/packages/xrpl/src/models/methods/subscribe.ts index 38b3565d7a..ff7f0a2714 100644 --- a/packages/xrpl/src/models/methods/subscribe.ts +++ b/packages/xrpl/src/models/methods/subscribe.ts @@ -92,6 +92,87 @@ interface BaseStream { type: string } +/** + * The book_changes stream sends bookChanges messages whenever a new ledger + * is validated. This message contains a summary of all changes to order books + * in the decentralized exchange that occurred in that ledger. + * + * @category Streams + */ +export interface BookChangesStream extends BaseStream { + type: 'bookChanges' + /** The ledger index of the ledger with these changes. */ + ledger_index: number + /** The identifying hash of the ledger with these changes. */ + ledger_hash: string + /** + * The official close time of the ledger with these changes, + * in seconds since the Ripple Epoch. + */ + ledger_time: number + /** + * List of Book Update Objects, containing one entry for each order book + * that was updated in this ledger version. The array is empty if no + * order books were updated. + */ + changes: BookUpdateObject[] +} + +/** + * A Book Update Object represents the changes to a single order book + * in a single ledger version. + * + * @category Streams + */ +export interface BookUpdateObject { + /** + * An identifier for the first of the two currencies in the order book. + * For XRP, this is the string "XRP_drops". For tokens, this is formatted as + * the address of the issuer in base58, followed by a forward-slash ("/"), + * followed by the Currency Code for the token, which can be a 3-character + * standard code or a 20-character hexadecimal code. + */ + currency_a: string + /** + * An identifier for the second of two currencies in the order book. + * This is in the same format as currency_a, except currency_b can never be XRP. + */ + currency_b: string + /** + * The total amount, or volume, of the first currency (that is, currency_a) + * that moved as a result of trades through this order book in this ledger. + */ + volume_a: string + /** + * The volume of the second currency (that is, currency_b) that moved + * as a result of trades through this order book in this ledger. + */ + volume_b: string + /** + * The highest exchange rate among all offers matched in this ledger, + * as a ratio of the first currency to the second currency. + * (In other words, currency_a : currency_b.) + */ + high: string + /** + * The lowest exchange rate among all offers matched in this ledger, + * as a ratio of the first currency to the second currency. + */ + low: string + /** + * The exchange rate at the top of this order book before processing + * the transactions in this ledger, as a ratio of the first currency + * to the second currency. + */ + open: string + /** + * The exchange rate at the top of this order book after processing + * the transactions in this ledger, as a ratio of the first currency + * to the second currency. + */ + close: string +} + /** * The `ledger` stream only sends `ledgerClosed` messages when the consensus * process declares a new validated ledger. The message identifies the ledger