diff --git a/src/api/dexPriceEstimator/DexPriceEstimatorApi.ts b/src/api/dexPriceEstimator/DexPriceEstimatorApi.ts index dae559194..0c98def5e 100644 --- a/src/api/dexPriceEstimator/DexPriceEstimatorApi.ts +++ b/src/api/dexPriceEstimator/DexPriceEstimatorApi.ts @@ -4,6 +4,7 @@ import { ORDER_BOOK_HOPS_DEFAULT, ORDER_BOOK_HOPS_MAX } from 'const' export interface DexPriceEstimatorApi { getPrice(params: GetPriceParams): Promise + getBestAsk(params: GetBestAskParams): Promise getOrderBookUrl(params: OrderBookParams): string getOrderBookData(params: OrderBookParams): Promise getMinOrderAmounInOWLUrl(networkId: number): string @@ -18,6 +19,8 @@ interface GetPriceParams { inWei?: boolean } +type GetBestAskParams = Omit + interface OrderBookParams { networkId: number baseTokenId: number @@ -125,6 +128,32 @@ export class DexPriceEstimatorApiImpl implements DexPriceEstimatorApi { } } + public async getBestAsk(params: GetBestAskParams): Promise { + const { + networkId, + baseToken: { id: baseTokenId }, + quoteToken: { id: quoteTokenId }, + } = params + + // Query format: markets/7-1/estimated-best-ask-price?unit=baseunits&roundingBuffer=enabled + const queryString = `markets/${baseTokenId}-${quoteTokenId}/estimated-best-ask-price` + + try { + const response = await this.query(networkId, queryString) + + if (response === null) { + return response + } + + return new BigNumber(response) + } catch (e) { + console.error(e) + throw new Error( + `Failed to query best ask for baseToken id ${baseTokenId} quoteToken id ${quoteTokenId}: ${e.message}`, + ) + } + } + public getOrderBookUrl(params: OrderBookParams): string { const { networkId, baseTokenId, quoteTokenId, hops = ORDER_BOOK_HOPS_DEFAULT, batchId } = params assert(hops >= 0, 'Hops should be positive') diff --git a/src/api/dexPriceEstimator/DexPriceEstimatorApiProxy.ts b/src/api/dexPriceEstimator/DexPriceEstimatorApiProxy.ts index 453662d3c..71f92d00b 100644 --- a/src/api/dexPriceEstimator/DexPriceEstimatorApiProxy.ts +++ b/src/api/dexPriceEstimator/DexPriceEstimatorApiProxy.ts @@ -12,6 +12,7 @@ export class DexPriceEstimatorApiProxy extends DexPriceEstimatorApiImpl { this.cache.injectCache(this, [ { method: 'getPrice', ttl: PRICES_CACHE_TIME }, + { method: 'getBestAsk', ttl: PRICES_CACHE_TIME }, { method: 'getMinOrderAmounInOWL', ttl: PRICES_CACHE_TIME }, ]) } diff --git a/src/assets/img/tokens/0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d.png b/src/assets/img/tokens/0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d.png index 31ef3197c..836fe7876 100644 Binary files a/src/assets/img/tokens/0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d.png and b/src/assets/img/tokens/0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d.png differ