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
Parameter | Type | Description |
---|---|---|
environment | Environment | The environment of the TegroDEX platform to connect to. |
walletPrivateKey | string | The private key of the user's wallet. |
Returns
Properties
Property | Modifier | Type |
---|---|---|
callbacks | private | RealtimeEventCallback [] |
environment | private | Environment |
wallet | private | Wallet |
web3SignData? | private | { domain : TypedDataDomain ; types : Record <string , TypedDataField []>; } |
web3SignData.domain | private | TypedDataDomain |
web3SignData.types | public | Record <string , TypedDataField []> |
websocket | public | undefined | WebSocket |
Methods
cancelAllOrdersInAMarket()
cancelAllOrdersInAMarket(chainId, marketSymbol)
cancelAllOrdersInAMarket(chainId, marketSymbol): Promise<undefined>
Cancels all orders for the current wallet address in the given market.
Parameters
Parameter | Type | Description |
---|---|---|
chainId | number | The ID of the blockchain network. |
marketSymbol | string | Symbol 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
Parameter | Type | Description |
---|---|---|
marketId | string | The ID of the market. |
Returns
Promise
<undefined
>
cancelOrder()
cancelOrder(chainId, orderId): Promise<void>
Cancels a specific order.
Parameters
Parameter | Type | Description |
---|---|---|
chainId | number | The ID of the blockchain network. |
orderId | string | The 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
Parameter | Type | Description |
---|---|---|
marketId | string | The ID of the market in which to place the order. |
side | OrderSide | The type of the order (buy or sell). |
pricePerUnit | number | The price per unit of the asset in the order. |
quantity | number | The 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
Parameter | Type | Description |
---|---|---|
chainId | number | The ID of the blockchain network. |
marketSymbol | string | The symbol of the market in which to place the order. |
side | OrderSide | The type of the order (buy or sell). |
pricePerUnit | number | The price per unit of the asset in the order. |
quantity | number | The 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
Parameter | Type | Description |
---|---|---|
chainId | number | The ID of the blockchain network the market is on. |
symbol | string | Symbol 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
Parameter | Type | Description |
---|---|---|
id | string | The 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
Parameter | Type | Default value | Description |
---|---|---|---|
chainId | number | undefined | The ID of the blockchain network. |
page | number | 1 | The page number for pagination. |
pageSize | number | 10 | The 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
Parameter | Type | Description |
---|---|---|
marketId | string | The 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
Parameter | Type | Description |
---|---|---|
chainId | number | The ID of the blockchain network. |
marketSymbol | string | The 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
Parameter | Type | Description |
---|---|---|
chainId | number | The 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
Parameter | Type | Description |
---|---|---|
marketId | string | The 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
Parameter | Type | Default value | Description |
---|---|---|---|
chainId | number | undefined | The ID of the blockchain network. |
page | number | 1 | The page number for pagination. |
pageSize | number | 10 | The 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
Parameter | Type | Description |
---|---|---|
chainId | number | The 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
Returns
Promise
<{
domain
: TypedDataDomain
;
types
: Record
<string
, TypedDataField
[]>;
}>
Member Type domain
TypedDataDomain
types
Record
<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
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
;
}>
Member Type Value chain_id
number
market.chainId market_symbol
string
market.symbol price_precision
string
- raw_order_data
string
- side
number
- signature
string
signature signed_order_type
string
"tegro" volume_precision
string
-
generateSalt()
private generateSalt(): string
Returns
string
subscribeToRealtimeEvents()
subscribeToRealtimeEvents(callback): void
Subscribes a callback function to receive real-time event updates.
Parameters
Parameter | Type | Description |
---|---|---|
callback | RealtimeEventCallback | The 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
Parameter | Type | Description |
---|---|---|
callback | RealtimeEventCallback | The 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
Parameter | Type | Default value | Description |
---|---|---|---|
environment | Environment | undefined | The environment of the TegroDEX platform to connect to. |
chainId | number | undefined | The ID of the blockchain network. |
page | number | 1 | The page number for pagination. |
pageSize | number | 10 | The 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
Parameter | Type | Description |
---|---|---|
environment | Environment | The 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
Parameter | Type | Default value | Description |
---|---|---|---|
environment | Environment | undefined | The environment of the TegroDEX platform to connect to. |
chainId | number | undefined | The ID of the blockchain network. |
page | number | 1 | The page number for pagination. |
pageSize | number | 10 | The 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.