Class: GdexStreamService
Client for the gSwap realtime stream (gdex WebSocket Protocol v1): JSON-RPC 2.0 over one raw WebSocket, with automatic reconnect and resubscribe.
Example
const stream = new GdexStreamService();
await stream.connect();
await stream.subscribeLiquidity(event => console.log(event.action, event.owner), {
owner: 'client|618ae395c1c653111d3315be',
});
Constructors
Constructor
new GdexStreamService(
config?):GdexStreamService
Parameters
| Parameter | Type |
|---|---|
config? | GdexStreamConfig |
Returns
GdexStreamService
gdex stream service config
Methods
connect()
connect():
Promise<void>
Open the connection. Resolves at once when already connected.
Returns
Promise<void>
disconnect()
disconnect():
void
Close the connection and stop reconnecting.
Returns
void
getBalance()
getBalance(
owner,tokenClassKey?):Promise<Record<string,unknown>>
gdex_getBalance: an owner's balances, or only the one of tokenClassKey when given.
Parameters
| Parameter | Type |
|---|---|
owner | string |
tokenClassKey? | string |
Returns
Promise<Record<string, unknown>>
get balance token class key gdex
getBlockHeight()
getBlockHeight():
Promise<{blockNumber:number;timestamp:string; }>
gdex_getBlockHeight: the block number the server reports, with its timestamp.
Returns
Promise<{ blockNumber: number; timestamp: string; }>
get block height number gdex
getPool()
getPool(
selector):Promise<Record<string,unknown>>
gdex_getPool: the current state of one pool, selected by its key or hash.
Parameters
| Parameter | Type |
|---|---|
selector | GdexPoolSelector |
Returns
Promise<Record<string, unknown>>
get pool gdex selector
getPositions()
getPositions(
opts):Promise<{bookmark:string;positions:Record<string,unknown>[]; }>
gdex_getPositions: an owner's positions, optionally in one pool, a page at a time. Pass the
returned bookmark back in as bookmark for the next page.
Parameters
| Parameter | Type |
|---|---|
opts | { bookmark?: string; limit?: number; owner: string; pool?: GdexPoolKey; poolHash?: string; } |
opts.bookmark? | string |
opts.limit? | number |
opts.owner | string |
opts.pool? | GdexPoolKey |
opts.poolHash? | string |
Returns
Promise<{ bookmark: string; positions: Record<string, unknown>[]; }>
get positions gdex pool key hash
getToken()
getToken(
tokenClassKey):Promise<Record<string,unknown>>
gdex_getToken: the server's record of one token class, as it sends it.
Parameters
| Parameter | Type |
|---|---|
tokenClassKey | string |
Returns
Promise<Record<string, unknown>>
get token class key gdex
isConnected()
isConnected():
boolean
true while the socket is open (false while connecting, reconnecting or after disconnect()).
Returns
boolean
is connected
ping()
ping():
Promise<{pong:boolean;serverTime:string; }>
gdex_ping: a round trip that answers { pong, serverTime }.
Returns
Promise<{ pong: boolean; serverTime: string; }>
server time gdex ping
quote()
quote(
params):Promise<Record<string,unknown>>
gdex_quote: a quote over the stream; give exactly one of amountIn or amountOut.
Parameters
| Parameter | Type |
|---|---|
params | { amountIn?: string; amountOut?: string; fee?: number; tokenIn: string; tokenOut: string; } |
params.amountIn? | string |
params.amountOut? | string |
params.fee? | number |
params.tokenIn | string |
params.tokenOut | string |
Returns
Promise<Record<string, unknown>>
gdex quote amount in out token
request()
request<
T>(method,params?):Promise<T>
Raw JSON-RPC escape hatch.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters
| Parameter | Type |
|---|---|
method | string |
params? | Record<string, unknown> |
Returns
Promise<T>
serverInfo()
serverInfo():
Promise<Record<string,unknown>>
gdex_serverInfo: the server's own description of itself, as it sends it.
Returns
Promise<Record<string, unknown>>
server info gdex
subscribeBalances()
subscribeBalances(
owner,cb,opts?):Promise<GdexSubscription>
Balance changes of one wallet.
Parameters
| Parameter | Type |
|---|---|
owner | string |
cb | (event) => void |
opts? | GdexSubscribeOptions & object |
Returns
Promise<GdexSubscription>
subscribe balances gdex subscription options
subscribeBlocks()
subscribeBlocks(
cb,opts?):Promise<GdexSubscription>
Each block-height advance.
Parameters
| Parameter | Type |
|---|---|
cb | (event) => void |
opts? | GdexSubscribeOptions |
Returns
Promise<GdexSubscription>
subscribe blocks gdex subscription options
subscribeLiquidity()
subscribeLiquidity(
cb,opts?):Promise<GdexSubscription>
One event per committed AddLiquidity, RemoveLiquidity and CollectPositionFees, on both contract
versions. Every filter is optional; with none, every liquidity event arrives. These events never
appear on subscribeSwaps. There is no snapshot: read positions with getPositions.
Deduplicate by transactionId plus positionId: a v1 BatchSubmit can hold several operations
under one transaction id.
Parameters
| Parameter | Type |
|---|---|
cb | (event) => void |
opts? | GdexSubscribeOptions & GdexLiquidityFilter |
Returns
Promise<GdexSubscription>
subscribe liquidity gdex subscription transaction id position options filter
subscribePool()
subscribePool(
selector,cb,opts?):Promise<GdexSubscription>
State changes of one pool (price, tick, reserves, liquidity). These events carry no acting wallet:
on v2 creator is whoever created the pool, not whoever just traded or added liquidity. For
"who did it", use subscribeLiquidity (owner) or subscribeSwaps (sender).
Parameters
| Parameter | Type |
|---|---|
selector | GdexPoolSelector |
cb | (event) => void |
opts? | GdexSubscribeOptions |
Returns
Promise<GdexSubscription>
subscribe pool gdex subscription selector options
subscribePoolCreated()
subscribePoolCreated(
cb,opts?):Promise<GdexSubscription>
Each newly created pool.
Parameters
| Parameter | Type |
|---|---|
cb | (event) => void |
opts? | GdexSubscribeOptions & object |
Returns
Promise<GdexSubscription>
subscribe pool created gdex subscription options
subscribeSwaps()
subscribeSwaps(
cb,opts?):Promise<GdexSubscription>
One event per committed swap. Omit the pool to receive every pool's swaps.
Parameters
| Parameter | Type |
|---|---|
cb | (event) => void |
opts? | GdexSubscribeOptions & object |
Returns
Promise<GdexSubscription>
subscribe swaps gdex subscription options