@andy-liquid-labs/lighter-ts-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +381 -0
- package/dist/index.d.mts +3686 -0
- package/dist/index.d.ts +3686 -0
- package/dist/index.js +6168 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5939 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
- package/src/api/exchange/change-account-tier.ts +38 -0
- package/src/api/exchange/fastwithdraw.ts +38 -0
- package/src/api/exchange/index.ts +7 -0
- package/src/api/exchange/notification-ack.ts +36 -0
- package/src/api/exchange/send-tx-batch.ts +53 -0
- package/src/api/exchange/send-tx.ts +105 -0
- package/src/api/exchange/tokens-create.ts +50 -0
- package/src/api/exchange/tokens-revoke.ts +38 -0
- package/src/api/index.ts +3 -0
- package/src/api/info/account-by-l1-address.ts +23 -0
- package/src/api/info/account.ts +80 -0
- package/src/api/info/announcement.ts +24 -0
- package/src/api/info/api-keys.ts +32 -0
- package/src/api/info/asset-details.ts +42 -0
- package/src/api/info/candles.ts +31 -0
- package/src/api/info/exchange-stats.ts +16 -0
- package/src/api/info/fastbridge-info.ts +15 -0
- package/src/api/info/funding-rates.ts +22 -0
- package/src/api/info/fundings.ts +29 -0
- package/src/api/info/index.ts +20 -0
- package/src/api/info/next-nonce.ts +26 -0
- package/src/api/info/order-book-details.ts +125 -0
- package/src/api/info/order-books.ts +23 -0
- package/src/api/info/recent-trades.ts +24 -0
- package/src/api/info/root-info.ts +13 -0
- package/src/api/info/root-status.ts +13 -0
- package/src/api/info/tx-from-l1-hash.ts +20 -0
- package/src/api/info/tx.ts +45 -0
- package/src/api/info/txs.ts +19 -0
- package/src/api/info/withdrawal-delay.ts +13 -0
- package/src/api/info-private/account-active-orders.ts +31 -0
- package/src/api/info-private/account-inactive-orders.ts +83 -0
- package/src/api/info-private/account-limits.ts +35 -0
- package/src/api/info-private/account-metadata.ts +43 -0
- package/src/api/info-private/deposit-history.ts +49 -0
- package/src/api/info-private/export.ts +41 -0
- package/src/api/info-private/fastwithdraw-info.ts +35 -0
- package/src/api/info-private/index.ts +18 -0
- package/src/api/info-private/l1-metadata.ts +35 -0
- package/src/api/info-private/liquidations.ts +96 -0
- package/src/api/info-private/pnl.ts +52 -0
- package/src/api/info-private/position-funding.ts +54 -0
- package/src/api/info-private/public-pools-metadata.ts +46 -0
- package/src/api/info-private/referral-points.ts +43 -0
- package/src/api/info-private/tokens.ts +44 -0
- package/src/api/info-private/trades.ts +66 -0
- package/src/api/info-private/transfer-fee-info.ts +37 -0
- package/src/api/info-private/transfer-history.ts +54 -0
- package/src/api/info-private/withdraw-history.ts +49 -0
- package/src/client/clientManager.ts +121 -0
- package/src/client/exchange-client.ts +637 -0
- package/src/client/http/client.ts +137 -0
- package/src/client/http/index.ts +6 -0
- package/src/client/http/interface.ts +89 -0
- package/src/client/index.ts +11 -0
- package/src/client/info-client.ts +383 -0
- package/src/client/info-private-client.ts +444 -0
- package/src/client/txClient.ts +597 -0
- package/src/client/ws-client.ts +457 -0
- package/src/crypto/ecgfp5.ts +722 -0
- package/src/crypto/goldilocks.ts +136 -0
- package/src/crypto/gorand.ts +777 -0
- package/src/crypto/index.ts +6 -0
- package/src/crypto/poseidon2.ts +365 -0
- package/src/crypto/scalar.ts +375 -0
- package/src/index.ts +112 -0
- package/src/signer/index.ts +5 -0
- package/src/signer/keyManager.ts +132 -0
- package/src/types/bridge.ts +24 -0
- package/src/types/constants.ts +252 -0
- package/src/types/errors.ts +168 -0
- package/src/types/index.ts +12 -0
- package/src/types/requests.ts +197 -0
- package/src/types/txInfo.ts +1277 -0
- package/src/types/txInfoPools.ts +502 -0
- package/src/types/txInfoSerializer.ts +348 -0
- package/src/types/ws.ts +407 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Client implementation for Lighter API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
MinimalHTTPClient,
|
|
7
|
+
NextNonceResponse,
|
|
8
|
+
AccountApiKeysResponse,
|
|
9
|
+
GetAccountResponse,
|
|
10
|
+
LighterAccount,
|
|
11
|
+
} from './interface';
|
|
12
|
+
|
|
13
|
+
const CODE_OK = 200;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* HTTP Client for Lighter exchange API
|
|
17
|
+
*/
|
|
18
|
+
export class HttpClient implements MinimalHTTPClient {
|
|
19
|
+
private readonly endpoint: string;
|
|
20
|
+
private readonly timeout: number;
|
|
21
|
+
|
|
22
|
+
constructor(baseUrl: string, timeout: number = 30000) {
|
|
23
|
+
if (!baseUrl) {
|
|
24
|
+
throw new Error('Base URL is required');
|
|
25
|
+
}
|
|
26
|
+
this.endpoint = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
|
|
27
|
+
this.timeout = timeout;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Make a GET request to the API
|
|
32
|
+
*/
|
|
33
|
+
private async get<T>(
|
|
34
|
+
path: string,
|
|
35
|
+
params: Record<string, string | number | bigint>
|
|
36
|
+
): Promise<T> {
|
|
37
|
+
const url = new URL(path, this.endpoint);
|
|
38
|
+
for (const [key, value] of Object.entries(params)) {
|
|
39
|
+
url.searchParams.set(key, String(value));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const controller = new AbortController();
|
|
43
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const response = await fetch(url.toString(), {
|
|
47
|
+
method: 'GET',
|
|
48
|
+
headers: {
|
|
49
|
+
Accept: 'application/json',
|
|
50
|
+
},
|
|
51
|
+
signal: controller.signal,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
const text = await response.text();
|
|
56
|
+
throw new Error(`HTTP ${response.status}: ${text}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const data = (await response.json()) as T & { code?: number; message?: string };
|
|
60
|
+
|
|
61
|
+
// Check result code
|
|
62
|
+
if (data.code !== undefined && data.code !== CODE_OK) {
|
|
63
|
+
throw new Error(data.message || `API error: ${data.code}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return data;
|
|
67
|
+
} finally {
|
|
68
|
+
clearTimeout(timeoutId);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get the next nonce for an account and API key
|
|
74
|
+
*/
|
|
75
|
+
async getNextNonce(accountIndex: bigint, apiKeyIndex: number): Promise<bigint> {
|
|
76
|
+
const result = await this.get<NextNonceResponse>('/api/v1/nextNonce', {
|
|
77
|
+
account_index: accountIndex,
|
|
78
|
+
api_key_index: apiKeyIndex,
|
|
79
|
+
});
|
|
80
|
+
return BigInt(result.nonce);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Get the public key for an account and API key
|
|
85
|
+
*/
|
|
86
|
+
async getApiKey(accountIndex: bigint, apiKeyIndex: number): Promise<string> {
|
|
87
|
+
const result = await this.get<AccountApiKeysResponse>('/api/v1/apikeys', {
|
|
88
|
+
account_index: accountIndex,
|
|
89
|
+
api_key_index: apiKeyIndex,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (!result.api_keys || result.api_keys.length === 0) {
|
|
93
|
+
throw new Error('No API keys returned');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return result.api_keys[0].public_key;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get account information by L1 address or account index
|
|
101
|
+
*/
|
|
102
|
+
async getAccount(
|
|
103
|
+
by: 'l1_address' | 'account_index',
|
|
104
|
+
value: string
|
|
105
|
+
): Promise<LighterAccount[]> {
|
|
106
|
+
const result = await this.get<GetAccountResponse>('/api/v1/account', {
|
|
107
|
+
by,
|
|
108
|
+
value,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return result.accounts ?? [];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Get account information by L1 address (convenience method)
|
|
116
|
+
*/
|
|
117
|
+
async getAccountByL1Address(l1Address: string): Promise<LighterAccount[]> {
|
|
118
|
+
return this.getAccount('l1_address', l1Address);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Get account information by account index (convenience method)
|
|
123
|
+
*/
|
|
124
|
+
async getAccountByIndex(accountIndex: string): Promise<LighterAccount[]> {
|
|
125
|
+
return this.getAccount('account_index', accountIndex);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Create a new HTTP client
|
|
131
|
+
*/
|
|
132
|
+
export function newHttpClient(baseUrl: string): MinimalHTTPClient | null {
|
|
133
|
+
if (!baseUrl) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
return new HttpClient(baseUrl);
|
|
137
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal HTTP Client interface for Lighter API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface MinimalHTTPClient {
|
|
6
|
+
/**
|
|
7
|
+
* Get the next nonce for an account and API key
|
|
8
|
+
*/
|
|
9
|
+
getNextNonce(accountIndex: bigint, apiKeyIndex: number): Promise<bigint>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get the public key for an account and API key
|
|
13
|
+
*/
|
|
14
|
+
getApiKey(accountIndex: bigint, apiKeyIndex: number): Promise<string>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get account information by L1 address or account index
|
|
18
|
+
*/
|
|
19
|
+
getAccount(by: 'l1_address' | 'account_index', value: string): Promise<LighterAccount[]>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* HTTP response types
|
|
24
|
+
*/
|
|
25
|
+
export interface ResultCode {
|
|
26
|
+
code: number;
|
|
27
|
+
message?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface NextNonceResponse extends ResultCode {
|
|
31
|
+
nonce: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ApiKey {
|
|
35
|
+
account_index: number;
|
|
36
|
+
api_key_index: number;
|
|
37
|
+
nonce: number;
|
|
38
|
+
public_key: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface AccountApiKeysResponse extends ResultCode {
|
|
42
|
+
api_keys: ApiKey[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface LighterAsset {
|
|
46
|
+
symbol: string;
|
|
47
|
+
asset_id: number;
|
|
48
|
+
balance: string;
|
|
49
|
+
locked_balance: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface LighterPosition {
|
|
53
|
+
// Add position fields as needed
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface LighterShare {
|
|
57
|
+
// Add share fields as needed
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface LighterAccount {
|
|
61
|
+
code: number;
|
|
62
|
+
account_type: number;
|
|
63
|
+
index: number;
|
|
64
|
+
l1_address: string;
|
|
65
|
+
cancel_all_time: number;
|
|
66
|
+
total_order_count: number;
|
|
67
|
+
total_isolated_order_count: number;
|
|
68
|
+
pending_order_count: number;
|
|
69
|
+
available_balance: string;
|
|
70
|
+
status: number;
|
|
71
|
+
collateral: string;
|
|
72
|
+
transaction_time: number;
|
|
73
|
+
account_index: number;
|
|
74
|
+
name: string;
|
|
75
|
+
description: string;
|
|
76
|
+
can_invite: boolean;
|
|
77
|
+
referral_points_percentage: string;
|
|
78
|
+
positions: LighterPosition[];
|
|
79
|
+
assets: LighterAsset[];
|
|
80
|
+
total_asset_value: string;
|
|
81
|
+
cross_asset_value: string;
|
|
82
|
+
shares: LighterShare[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface GetAccountResponse extends ResultCode {
|
|
86
|
+
total?: number;
|
|
87
|
+
accounts?: LighterAccount[];
|
|
88
|
+
}
|
|
89
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client module exports
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from "./http";
|
|
6
|
+
export * from "./txClient";
|
|
7
|
+
export * from "./clientManager";
|
|
8
|
+
export * from "./info-client";
|
|
9
|
+
export * from "./info-private-client";
|
|
10
|
+
export * from "./exchange-client";
|
|
11
|
+
export * from "./ws-client";
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import axios, { AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AccountAccountByL1AddressResponse,
|
|
5
|
+
AccountByL1AddressRequest,
|
|
6
|
+
AccountRequest,
|
|
7
|
+
AccountResponse,
|
|
8
|
+
AnnouncementsResponse,
|
|
9
|
+
ApiKeysRequest,
|
|
10
|
+
ApiKeysResponse,
|
|
11
|
+
AssetDetailsRequest,
|
|
12
|
+
AssetDetailsResponse,
|
|
13
|
+
CandlesRequest,
|
|
14
|
+
CandlesResponse,
|
|
15
|
+
ExchangeStatsResponse,
|
|
16
|
+
FastBridgeInfoResponse,
|
|
17
|
+
FundingRatesResponse,
|
|
18
|
+
FundingsRequest,
|
|
19
|
+
FundingsResponse,
|
|
20
|
+
getAccountByL1Address,
|
|
21
|
+
getAccountInfo,
|
|
22
|
+
getAnnouncements,
|
|
23
|
+
getApiKeys,
|
|
24
|
+
getAssetDetails,
|
|
25
|
+
getCandlesticks,
|
|
26
|
+
getExchangeStats,
|
|
27
|
+
getFastBridgeInfo,
|
|
28
|
+
getFundingRates,
|
|
29
|
+
getFundings,
|
|
30
|
+
getNextNonce,
|
|
31
|
+
getOrderBookDetails,
|
|
32
|
+
getOrderBookOrders,
|
|
33
|
+
getOrderBooks,
|
|
34
|
+
getRecentTrades,
|
|
35
|
+
getRootStatus,
|
|
36
|
+
getTransaction,
|
|
37
|
+
getTransactionFromL1TxHash,
|
|
38
|
+
getTransactions,
|
|
39
|
+
getWithdrawalDelay,
|
|
40
|
+
NextNonceRequest,
|
|
41
|
+
NextNonceResponse,
|
|
42
|
+
OrderBookDetailsRequest,
|
|
43
|
+
OrderBookDetailsResponse,
|
|
44
|
+
OrderBookOrdersRequest,
|
|
45
|
+
OrderBookOrdersResponse,
|
|
46
|
+
OrderBooksResponse,
|
|
47
|
+
RecentTradesRequest,
|
|
48
|
+
RecentTradesResponse,
|
|
49
|
+
RootStatusResponse,
|
|
50
|
+
Transaction,
|
|
51
|
+
TransactionFromL1TxHashRequest,
|
|
52
|
+
TransactionRequest,
|
|
53
|
+
TransactionsRequest,
|
|
54
|
+
TransactionsResponse,
|
|
55
|
+
WithdrawalDelayResponse,
|
|
56
|
+
} from "../api/info";
|
|
57
|
+
|
|
58
|
+
export interface InfoClientConfig {
|
|
59
|
+
baseURL?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* InfoClient - Client for public info endpoints
|
|
64
|
+
*
|
|
65
|
+
* Provides access to all public API endpoints that don't require authentication.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const client = new InfoClient({
|
|
70
|
+
* baseURL: "https://mainnet.zklighter.elliot.ai"
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const account = await client.getAccountInfo({ by: "index", value: "0" });
|
|
74
|
+
* const orderBooks = await client.getOrderBooks();
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export class InfoClient {
|
|
78
|
+
private readonly config: InfoClientConfig;
|
|
79
|
+
private readonly axiosInstance: AxiosInstance;
|
|
80
|
+
|
|
81
|
+
constructor(config?: InfoClientConfig) {
|
|
82
|
+
this.config = {
|
|
83
|
+
baseURL: config?.baseURL || "https://mainnet.zklighter.elliot.ai",
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
this.axiosInstance = this.createAxiosInstance();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private createAxiosInstance(): AxiosInstance {
|
|
90
|
+
return axios.create({
|
|
91
|
+
baseURL: this.config.baseURL,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get account information by index or L2 address
|
|
97
|
+
* @param params - Account lookup parameters (by index or L2 address)
|
|
98
|
+
* @returns Account information including balances and positions
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const account = await client.getAccountInfo({ by: "index", value: "0" });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
public async getAccountInfo(
|
|
105
|
+
params: AccountRequest,
|
|
106
|
+
): Promise<AccountResponse> {
|
|
107
|
+
return getAccountInfo(this.axiosInstance, params);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get account information by L1 address
|
|
112
|
+
* @param params - L1 address lookup parameters
|
|
113
|
+
* @returns Account information associated with the L1 address
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const account = await client.getAccountByL1Address({ l1_address: "0x..." });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
public async getAccountByL1Address(
|
|
120
|
+
params: AccountByL1AddressRequest,
|
|
121
|
+
): Promise<AccountAccountByL1AddressResponse> {
|
|
122
|
+
return getAccountByL1Address(this.axiosInstance, params);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get API keys for an account
|
|
127
|
+
* @param params - Account index to retrieve API keys for
|
|
128
|
+
* @returns List of API keys associated with the account
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const keys = await client.getApiKeys({ account_index: 0 });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
public async getApiKeys(params: ApiKeysRequest): Promise<ApiKeysResponse> {
|
|
135
|
+
return getApiKeys(this.axiosInstance, params);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get system announcements
|
|
140
|
+
* @returns List of active announcements
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const announcements = await client.getAnnouncements();
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
public async getAnnouncements(): Promise<AnnouncementsResponse> {
|
|
147
|
+
return getAnnouncements(this.axiosInstance);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get asset details for a specific asset or all assets
|
|
152
|
+
* @param params - Optional asset_index to get details for a specific asset
|
|
153
|
+
* @returns Asset details including symbol, decimals, limits, and pricing information
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // Get all assets
|
|
157
|
+
* const allAssets = await client.getAssetDetails();
|
|
158
|
+
*
|
|
159
|
+
* // Get specific asset
|
|
160
|
+
* const asset = await client.getAssetDetails({ asset_index: 0 });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
public async getAssetDetails(
|
|
164
|
+
params?: AssetDetailsRequest,
|
|
165
|
+
): Promise<AssetDetailsResponse> {
|
|
166
|
+
return getAssetDetails(this.axiosInstance, params);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Get candlestick data for a market
|
|
171
|
+
* @param params - Candlestick query parameters including market_id, resolution, and time range
|
|
172
|
+
* @returns Array of candlestick data
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const candles = await client.getCandlesticks({
|
|
176
|
+
* market_id: 1,
|
|
177
|
+
* resolution: "1h",
|
|
178
|
+
* start_timestamp: 1234567890,
|
|
179
|
+
* end_timestamp: 1234567900
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
public async getCandlesticks(
|
|
184
|
+
params: CandlesRequest,
|
|
185
|
+
): Promise<CandlesResponse> {
|
|
186
|
+
return getCandlesticks(this.axiosInstance, params);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get funding history for a market
|
|
191
|
+
* @param params - Funding query parameters including market_id and time range
|
|
192
|
+
* @returns Array of funding data
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const fundings = await client.getFundings({
|
|
196
|
+
* market_id: 1,
|
|
197
|
+
* start_timestamp: 1234567890,
|
|
198
|
+
* end_timestamp: 1234567900
|
|
199
|
+
* });
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
public async getFundings(params: FundingsRequest): Promise<FundingsResponse> {
|
|
203
|
+
return getFundings(this.axiosInstance, params);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Get exchange statistics
|
|
208
|
+
* @returns Exchange-wide statistics including volume, fees, and markets
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const stats = await client.getExchangeStats();
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
public async getExchangeStats(): Promise<ExchangeStatsResponse> {
|
|
215
|
+
return getExchangeStats(this.axiosInstance);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Get fast bridge information
|
|
220
|
+
* @returns Fast bridge configuration and status
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const bridgeInfo = await client.getFastBridgeInfo();
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
public async getFastBridgeInfo(): Promise<FastBridgeInfoResponse> {
|
|
227
|
+
return getFastBridgeInfo(this.axiosInstance);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Get current funding rates for all markets
|
|
232
|
+
* @returns Funding rates for all markets
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const rates = await client.getFundingRates();
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
public async getFundingRates(): Promise<FundingRatesResponse> {
|
|
239
|
+
return getFundingRates(this.axiosInstance);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Get the next nonce for an account
|
|
244
|
+
* @param params - Account index to get nonce for
|
|
245
|
+
* @returns Next nonce value
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* const nonce = await client.getNextNonce({ account_index: 0 });
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
public async getNextNonce(
|
|
252
|
+
params: NextNonceRequest,
|
|
253
|
+
): Promise<NextNonceResponse> {
|
|
254
|
+
return getNextNonce(this.axiosInstance, params);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Get all order books
|
|
259
|
+
* @returns List of all order books with their configurations
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const orderBooks = await client.getOrderBooks();
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
public async getOrderBooks(): Promise<OrderBooksResponse> {
|
|
266
|
+
return getOrderBooks(this.axiosInstance);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Get detailed information about a specific order book
|
|
271
|
+
* @param params - Optional market_id to get details for a specific market
|
|
272
|
+
* @returns Order book details including market information
|
|
273
|
+
* @example
|
|
274
|
+
* ```typescript
|
|
275
|
+
* const details = await client.getOrderBookDetails({ market_id: 1 });
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
public async getOrderBookDetails(
|
|
279
|
+
params?: OrderBookDetailsRequest,
|
|
280
|
+
): Promise<OrderBookDetailsResponse> {
|
|
281
|
+
return getOrderBookDetails(this.axiosInstance, params);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Get orders in an order book
|
|
286
|
+
* @param params - Market ID and optional depth/limit parameters
|
|
287
|
+
* @returns Bids and asks in the order book
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* const orders = await client.getOrderBookOrders({ market_id: 1, limit: 50 });
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
public async getOrderBookOrders(
|
|
294
|
+
params: OrderBookOrdersRequest,
|
|
295
|
+
): Promise<OrderBookOrdersResponse> {
|
|
296
|
+
return getOrderBookOrders(this.axiosInstance, params);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Get recent trades for a market
|
|
301
|
+
* @param params - Market ID and optional limit
|
|
302
|
+
* @returns Recent trades for the market
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* const trades = await client.getRecentTrades({ market_id: 1, limit: 50 });
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
public async getRecentTrades(
|
|
309
|
+
params: RecentTradesRequest,
|
|
310
|
+
): Promise<RecentTradesResponse> {
|
|
311
|
+
return getRecentTrades(this.axiosInstance, params);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Get a specific transaction by hash
|
|
316
|
+
* @param params - Transaction hash to look up
|
|
317
|
+
* @returns Transaction details
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* const tx = await client.getTransaction({ tx_hash: "0x..." });
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
public async getTransaction(
|
|
324
|
+
params: TransactionRequest,
|
|
325
|
+
): Promise<Transaction> {
|
|
326
|
+
return getTransaction(this.axiosInstance, params);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Get transactions with optional filtering
|
|
331
|
+
* @param params - Optional filter parameters for transaction queries
|
|
332
|
+
* @returns List of transactions
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* const txs = await client.getTransactions({ limit: 50 });
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
public async getTransactions(
|
|
339
|
+
params?: TransactionsRequest,
|
|
340
|
+
): Promise<TransactionsResponse> {
|
|
341
|
+
return getTransactions(this.axiosInstance, params);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Get L2 transaction from L1 transaction hash
|
|
346
|
+
* @param params - L1 transaction hash
|
|
347
|
+
* @returns Corresponding L2 transaction
|
|
348
|
+
* @example
|
|
349
|
+
* ```typescript
|
|
350
|
+
* const tx = await client.getTransactionFromL1TxHash({ l1_tx_hash: "0x..." });
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
public async getTransactionFromL1TxHash(
|
|
354
|
+
params: TransactionFromL1TxHashRequest,
|
|
355
|
+
): Promise<Transaction> {
|
|
356
|
+
return getTransactionFromL1TxHash(this.axiosInstance, params);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Get withdrawal delay in seconds
|
|
361
|
+
* @returns Withdrawal delay configuration
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* const delay = await client.getWithdrawalDelay();
|
|
365
|
+
* console.log(`Withdrawal delay: ${delay.seconds} seconds`);
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
public async getWithdrawalDelay(): Promise<WithdrawalDelayResponse> {
|
|
369
|
+
return getWithdrawalDelay(this.axiosInstance);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Get root status information
|
|
374
|
+
* @returns Root status including network status, network_id, and timestamp
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* const status = await client.getRootStatus();
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
public async getRootStatus(): Promise<RootStatusResponse> {
|
|
381
|
+
return getRootStatus(this.axiosInstance);
|
|
382
|
+
}
|
|
383
|
+
}
|