API Reference

TegroDexClient class provides an interface to interact with the Tegro DEX API.

Constructors

new TegroDexClient(environment, walletPrivateKey)

new TegroDexClient(environment, walletPrivateKey): TegroDexClient

Constructor for TegroDexClient.

Parameters

ParameterTypeDescription
environmentEnvironmentThe environment of the TegroDEX platform to connect to.
walletPrivateKeystringThe private key of the user's wallet.

Returns

TegroDexClient

Properties

PropertyModifierType
callbacksprivateRealtimeEventCallback[]
environmentprivateEnvironment
walletprivateWallet
web3SignData?private{ domain: TypedDataDomain; types: Record<string, TypedDataField[]>; }
web3SignData.domainprivateTypedDataDomain
web3SignData.typespublicRecord<string, TypedDataField[]>
websocketpublicundefined | WebSocket

Methods

cancelAllOrdersInAMarket()

cancelAllOrdersInAMarket(chainId, marketSymbol)

cancelAllOrdersInAMarket(chainId, marketSymbol): Promise<undefined>

Cancels all orders for the current wallet address in the given market.

Parameters
ParameterTypeDescription
chainIdnumberThe ID of the blockchain network.
marketSymbolstringSymbol of the market.
Returns

Promise<undefined>

cancelAllOrdersInAMarket(marketId)

cancelAllOrdersInAMarket(marketId): Promise<undefined>

Cancels all orders for the current wallet address in the given market.

Parameters
ParameterTypeDescription
marketIdstringThe ID of the market.
Returns

Promise<undefined>


cancelOrder()

cancelOrder(chainId, orderId): Promise<void>

Cancels a specific order.

Parameters

ParameterTypeDescription
chainIdnumberThe ID of the blockchain network.
orderIdstringThe ID of the order to cancel.

Returns

Promise<void>


createOrder()

createOrder(marketId, side, pricePerUnit, quantity)

createOrder(
   marketId, 
   side, 
   pricePerUnit, 
quantity): Promise<any>

Creates a new order in the specified market.

Parameters
ParameterTypeDescription
marketIdstringThe ID of the market in which to place the order.
sideOrderSideThe type of the order (buy or sell).
pricePerUnitnumberThe price per unit of the asset in the order.
quantitynumberThe quantity of the asset to buy or sell.
Returns

Promise<any>

A Promise resolving to the created Order object.

createOrder(chainId, marketSymbol, side, pricePerUnit, quantity)

createOrder(
   chainId, 
   marketSymbol, 
   side, 
   pricePerUnit, 
quantity): Promise<any>

Creates a new order in the specified market.

Parameters
ParameterTypeDescription
chainIdnumberThe ID of the blockchain network.
marketSymbolstringThe symbol of the market in which to place the order.
sideOrderSideThe type of the order (buy or sell).
pricePerUnitnumberThe price per unit of the asset in the order.
quantitynumberThe quantity of the asset to buy or sell.
Returns

Promise<any>

A Promise resolving to the created Order object.


disableRealtimeEvents()

disableRealtimeEvents(): void

Disables real-time events by closing the WebSocket connection.
If real-time updates are already disabled, a warning message will be logged.

Returns

void


enableRealtimeEvents()

enableRealtimeEvents(): void

Enables real-time events by establishing a WebSocket connection and subscribing to the wallet address channel.
The connection will automatically attempt to reconnect in case of closure.

Returns

void


fetchMarket()

fetchMarket(chainId, symbol)

fetchMarket(chainId, symbol): Promise<Market>

Fetches a specific verified market by its symbol and chain id.

Parameters
ParameterTypeDescription
chainIdnumberThe ID of the blockchain network the market is on.
symbolstringSymbol of the market to fetch.
Returns

Promise<Market>

A Promise resolving to a Market object or undefined if not found.

fetchMarket(id)

fetchMarket(id): Promise<Market>

Fetches a specific verified market by its ID.

Parameters
ParameterTypeDescription
idstringThe ID of the market.
Returns

Promise<Market>

A Promise resolving to a Market object or undefined if not found.


fetchMarkets()

fetchMarkets(
   chainId, 
   page, 
   pageSize, 
   sortBy, 
sortOrder): Promise<Market[]>

Fetches the list of verified markets.

Parameters

ParameterTypeDefault valueDescription
chainIdnumberundefinedThe ID of the blockchain network.
pagenumber1The page number for pagination.
pageSizenumber10The number of markets to fetch per page.
sortBy"volume"'volume'The field to sort by (default is 'volume').
sortOrder"asc" | "desc"'desc'The order for sorting ('asc' or 'desc', default is 'desc').

Returns

Promise<Market[]>

A Promise resolving to an array of Market objects.


fetchOrderBookDepthForMarket()

fetchOrderBookDepthForMarket(marketId)

fetchOrderBookDepthForMarket(marketId): Promise<Orderbook>

Fetches the order book depth for a specific market by its ID.

Parameters
ParameterTypeDescription
marketIdstringThe ID of the market.
Returns

Promise<Orderbook>

A Promise resolving to an Orderbook object.

Throws

ReferenceError if the market is not found.

fetchOrderBookDepthForMarket(chainId, marketSymbol)

fetchOrderBookDepthForMarket(chainId, marketSymbol): Promise<Orderbook>

Fetches the order book depth for a specific market by chain ID and market symbol.

Parameters
ParameterTypeDescription
chainIdnumberThe ID of the blockchain network.
marketSymbolstringThe symbol of the market.
Returns

Promise<Orderbook>

A Promise resolving to an Orderbook object.

Throws

ReferenceError if the market is not found.


fetchOrders()

fetchOrders(chainId, status, page, pageSize)

fetchOrders(
   chainId, 
   status?, 
   page?, 
pageSize?): Promise<Order[]>

Fetches the list of user's orders in a chain.

Parameters
ParameterTypeDescription
chainIdnumberThe ID of the blockchain network.
status?OrderStatus(Optional) The status of the orders to fetch (default is OrderStatus.ACTIVE).
page?number(Optional) The page number for pagination (default is 1).
pageSize?number(Optional) The number of orders to fetch per page (default is 10).
Returns

Promise<Order[]>

A Promise resolving to an array of Order objects.

fetchOrders(marketId, status, page, pageSize)

fetchOrders(
   marketId, 
   status?, 
   page?, 
pageSize?): Promise<Order[]>

Fetches the list of user's orders for a specific market.

Parameters
ParameterTypeDescription
marketIdstringThe ID of the market.
status?OrderStatus(Optional) The status of the orders to fetch (default is OrderStatus.ACTIVE).
page?number(Optional) The page number for pagination (default is 1).
pageSize?number(Optional) The number of orders to fetch per page (default is 10).
Returns

Promise<Order[]>

A Promise resolving to an array of Order objects.


fetchSupportedChains()

fetchSupportedChains(): Promise<Chain[]>

Fetches the list of supported chains.

Returns

Promise<Chain[]>

A Promise resolving to an array of Chain objects.


fetchSupportedTokens()

fetchSupportedTokens(
   chainId, 
   page, 
   pageSize, 
   sortBy, 
sortOrder): Promise<Token[]>

Fetches the list of supported tokens.

Parameters

ParameterTypeDefault valueDescription
chainIdnumberundefinedThe ID of the blockchain network.
pagenumber1The page number for pagination.
pageSizenumber10The number of tokens to fetch per page.
sortBy"name"'name'The field to sort by (default is 'name').
sortOrder"asc" | "desc"'desc'The order for sorting ('asc' or 'desc', default is 'desc').

Returns

Promise<Token[]>

A Promise resolving to an array of Token objects.


fetchWalletBalances()

fetchWalletBalances(chainId): Promise<TokenBalance[]>

Fetches the balances of tokens held in the user's wallet on a specific blockchain network.

Parameters

ParameterTypeDescription
chainIdnumberThe ID of the blockchain network.

Returns

Promise<TokenBalance[]>

A Promise resolving to an array of TokenBalance objects representing the balances of tokens held in the user's wallet.


fetchWeb3SignData()

private fetchWeb3SignData(
   market, 
   orderType, 
   price, 
   quantity): Promise<{
  domain: TypedDataDomain;
  types: Record<string, TypedDataField[]>;
}>

Parameters

ParameterType
marketMarket
orderTypeOrderSide
pricenumber
quantitynumber

Returns

Promise<{
domain: TypedDataDomain;
types: Record<string, TypedDataField[]>;
}>

MemberType
domainTypedDataDomain
typesRecord<string, TypedDataField[]>

generateOrderCreationPayload()

private generateOrderCreationPayload(
   market, 
   orderSide, 
   price, 
   quantity): Promise<{
  chain_id: market.chainId;
  market_symbol: market.symbol;
  price_precision: string;
  raw_order_data: string;
  side: number;
  signature: signature;
  signed_order_type: "tegro";
  volume_precision: string;
}>

Parameters

ParameterType
marketMarket
orderSideOrderSide
pricenumber
quantitynumber

Returns

Promise<{
chain_id: market.chainId;
market_symbol: market.symbol;
price_precision: string;
raw_order_data: string;
side: number;
signature: signature;
signed_order_type: "tegro";
volume_precision: string;
}>

MemberTypeValue
chain_idnumbermarket.chainId
market_symbolstringmarket.symbol
price_precisionstring-
raw_order_datastring-
sidenumber-
signaturestringsignature
signed_order_typestring"tegro"
volume_precisionstring-

generateSalt()

private generateSalt(): string

Returns

string


subscribeToRealtimeEvents()

subscribeToRealtimeEvents(callback): void

Subscribes a callback function to receive real-time event updates.

Parameters

ParameterTypeDescription
callbackRealtimeEventCallbackThe callback function to be notified on real-time events.

Returns

void


unsubscribeFromRealtimeEvents()

unsubscribeFromRealtimeEvents(callback): void

Unsubscribes a callback function from receiving real-time event updates.

Parameters

ParameterTypeDescription
callbackRealtimeEventCallbackThe callback function to be removed from the subscribers.

Returns

void


fetchMarkets()

static fetchMarkets(
   environment, 
   chainId, 
   page, 
   pageSize, 
   sortBy, 
sortOrder): Promise<Market[]>

Fetches the list of verified markets.

Parameters

ParameterTypeDefault valueDescription
environmentEnvironmentundefinedThe environment of the TegroDEX platform to connect to.
chainIdnumberundefinedThe ID of the blockchain network.
pagenumber1The page number for pagination.
pageSizenumber10The number of markets to fetch per page.
sortBy"volume"'volume'The field to sort by (default is 'volume').
sortOrder"asc" | "desc"'desc'The order for sorting ('asc' or 'desc', default is 'desc').

Returns

Promise<Market[]>

A Promise resolving to an array of Market objects.


fetchSupportedChains()

static fetchSupportedChains(environment): Promise<Chain[]>

Fetches the list of supported chains.

Parameters

ParameterTypeDescription
environmentEnvironmentThe environment of the TegroDEX platform to connect to.

Returns

Promise<Chain[]>

A Promise resolving to an array of Chain objects.


fetchSupportedTokens()

static fetchSupportedTokens(
   environment, 
   chainId, 
   page, 
   pageSize, 
   sortBy, 
sortOrder): Promise<Token[]>

Fetches the list of supported tokens.

Parameters

ParameterTypeDefault valueDescription
environmentEnvironmentundefinedThe environment of the TegroDEX platform to connect to.
chainIdnumberundefinedThe ID of the blockchain network.
pagenumber1The page number for pagination.
pageSizenumber10The number of tokens to fetch per page.
sortBy"name"'name'The field to sort by (default is 'name').
sortOrder"asc" | "desc"'desc'The order for sorting ('asc' or 'desc', default is 'desc').

Returns

Promise<Token[]>

A Promise resolving to an array of Token objects.