Update orderbook docs and params (#2294)

* Update orderbook docs and params
This commit is contained in:
Jackson Mills
2023-05-09 08:29:53 -07:00
committed by GitHub
parent 0b929dde85
commit 2e6d2dc805
2 changed files with 14 additions and 13 deletions

View File

@@ -102,6 +102,7 @@ Wallet.fromMmnemonic()
## 2.2.1 (2022-04-21) ## 2.2.1 (2022-04-21)
### Fixed ### Fixed
* Fix return field of NFT offer * Fix return field of NFT offer
* Updated `getOrderbook` docs and param names to reflect actual behavior of checking both sides of order book.
## 2.2.0 (2022-04-19) ## 2.2.0 (2022-04-19)
### Added ### Added

View File

@@ -31,28 +31,28 @@ const getOrderbookOptionsSet = new Set([
]) ])
/** /**
* Fetch orderbook (buy/sell orders) between two accounts. * Fetch orderbook (buy/sell orders) between two currency pairs. This checks both sides of the orderbook
* by making two `order_book` requests (with the second reversing takerPays and takerGets). Returned offers are
* not normalized in this function, so either currency could be takerGets or takerPays.
* *
* @param this - Client. * @param this - Client.
* @param takerPays - Specification of which currency the account taking the * @param currency1 - Specification of one currency involved. (With a currency code and optionally an issuer)
* offer would pay, as an object with `currency` and `issuer` fields. * @param currency2 - Specification of a second currency involved. (With a currency code and optionally an issuer)
* @param takerGets - Specification of which currency the account taking the
* offer would receive, as an object with `currency` and `issuer` fields.
* @param options - Options allowing the client to specify ledger_index, * @param options - Options allowing the client to specify ledger_index,
* ledger_hash, filter by taker, and/or limit number of orders. * ledger_hash, filter by taker, and/or limit number of orders.
* @param options.ledger_index - Retrieve the orderbook at a given ledger_index. * @param options.ledger_index - Retrieve the orderbook at a given ledger_index.
* @param options.ledger_hash - Retrieve the orderbook at the ledger with a * @param options.ledger_hash - Retrieve the orderbook at the ledger with a
* given ledger_hash. * given ledger_hash.
* @param options.taker - Filter orders by taker. * @param options.taker - Filter orders by taker.
* @param options.limit - Limit number of order books to fetch for each side of * @param options.limit - The limit passed into each book_offers request.
* the order book. Defaults to 20. * Can return more than this due to two calls being made. Defaults to 20.
* @returns An object containing buy and sell objects. * @returns An object containing buy and sell objects.
*/ */
// eslint-disable-next-line max-params, complexity -- Once bound to Client, getOrderbook only has 3 parameters. // eslint-disable-next-line max-params, complexity -- Once bound to Client, getOrderbook only has 3 parameters.
async function getOrderbook( async function getOrderbook(
this: Client, this: Client,
takerPays: TakerAmount, currency1: TakerAmount,
takerGets: TakerAmount, currency2: TakerAmount,
options: { options: {
limit?: number limit?: number
ledger_index?: LedgerIndex ledger_index?: LedgerIndex
@@ -104,8 +104,8 @@ async function getOrderbook(
const request: BookOffersRequest = { const request: BookOffersRequest = {
command: 'book_offers', command: 'book_offers',
taker_pays: takerPays, taker_pays: currency1,
taker_gets: takerGets, taker_gets: currency2,
ledger_index: options.ledger_index ?? 'validated', ledger_index: options.ledger_index ?? 'validated',
ledger_hash: options.ledger_hash === null ? undefined : options.ledger_hash, ledger_hash: options.ledger_hash === null ? undefined : options.ledger_hash,
limit: options.limit ?? DEFAULT_LIMIT, limit: options.limit ?? DEFAULT_LIMIT,
@@ -113,8 +113,8 @@ async function getOrderbook(
} }
// 2. Make Request // 2. Make Request
const directOfferResults = await this.requestAll(request) const directOfferResults = await this.requestAll(request)
request.taker_gets = takerPays request.taker_gets = currency1
request.taker_pays = takerGets request.taker_pays = currency2
const reverseOfferResults = await this.requestAll(request) const reverseOfferResults = await this.requestAll(request)
// 3. Return Formatted Response // 3. Return Formatted Response
const directOffers = flatMap( const directOffers = flatMap(