Skip to main content

Class: Market

gSwap SDK 2.0.0-rc.4


gSwap SDK 2.0.0-rc.4 / Market

Class: Market

Defined in: packages/gswap-sdk/dist/index.d.ts:2152

Market data from the swap backend: USD prices (GET /market/price), price series (GET /market/price-series) and the platform volume totals (GET /v2/trade/volume). Public reads: no signer, no wallet.

A token is named by a symbol (GALA) or a class key (GALA$Unit$none$none, GALA|Unit|none|none or the object). The backend answers each token under the exact id it was asked for, so the answer is read back under that id: a token the backend has no entry for is undefined, never another token's price.

Constructors​

Constructor​

new Market(dexBackendBaseUrl, httpClient, options?): Market

Defined in: packages/gswap-sdk/dist/index.d.ts:2165

Creates a market service. options.onInvalidEntry is told about every price or price point that was skipped as unusable.

Parameters​

dexBackendBaseUrl​

string

httpClient​

HttpClient

options?​
onInvalidEntry?​

InvalidEntryHandler

Returns​

Market

Example​

const market = new Market('https://dex-backend-prod1.defi.gala.com', httpClient);

Methods​

getPrice()​

getPrice(token, options?): Promise<MarketPrice | undefined>

Defined in: packages/gswap-sdk/dist/index.d.ts:2192

The USD price of one token, or undefined when the backend has no entry for it (see Market.getPrices).

Parameters​

token​

TokenRef

options?​

MarketListOptions

Returns​

Promise<MarketPrice | undefined>

Example​

const gala = await gSwap.market.getPrice('GALA$Unit$none$none');
if (gala?.price != null) console.log(`GALA: $${gala.price}`);

getPrices()​

getPrices(tokens, options?): Promise<(MarketPrice | undefined)[]>

Defined in: packages/gswap-sdk/dist/index.d.ts:2181

USD prices of 1 to 500 tokens, in the order asked (a token named twice is asked for once). The ids go in as many requests as their length needs (see MARKET_PRICE_QUERY_BYTES), one after another; any request failing fails the call. A token the backend did not answer for is undefined; one it answered for unusably is undefined too, and reported to onInvalidEntry. An answer that is not an object is INVALID_CHAIN_RESPONSE.

Parameters​

tokens​

readonly TokenRef[]

options?​

MarketListOptions

Returns​

Promise<(MarketPrice | undefined)[]>

Example​

const [gala, gusdc] = await gSwap.market.getPrices(['GALA$Unit$none$none', 'GUSDC$Unit$none$none']);
console.log(gala?.price, gusdc?.price);

getPriceSeries()​

getPriceSeries(token, timeframe, options?): Promise<PriceSeries>

Defined in: packages/gswap-sdk/dist/index.d.ts:2205

A token's USD price line for one window (1D, 1W, 1M, 1Y or ALL; any other is INVALID_TIMEFRAME before anything is sent). The whole series in one answer, oldest first; a token the backend has no prices for is an empty series. An unusable point is skipped and reported to onInvalidEntry; an answer that is not a series is INVALID_CHAIN_RESPONSE.

Parameters​

token​

TokenRef

timeframe​

"1D" | "1W" | "1M" | "1Y" | "ALL"

options?​

MarketListOptions

Returns​

Promise<PriceSeries>

Example​

const series = await gSwap.market.getPriceSeries('GALA$Unit$none$none', '1W');
console.log(series.prices.length, series.currentPrice);

getVolumeSummary()​

getVolumeSummary(options?): Promise<VolumeSummary>

Defined in: packages/gswap-sdk/dist/index.d.ts:2216

TVL, volume and trade totals across every current-contract pool. Every field must be a finite number, or the answer is INVALID_CHAIN_RESPONSE.

Parameters​

options?​

MarketReadOptions

Returns​

Promise<VolumeSummary>

Example​

const volume = await gSwap.market.getVolumeSummary();
console.log(`24h: $${volume.volume1d.toFixed(0)} (${(volume.volume1dDelta * 100).toFixed(1)} %)`);