klingex 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 +310 -0
- package/dist/index.d.mts +895 -0
- package/dist/index.d.ts +895 -0
- package/dist/index.js +1098 -0
- package/dist/index.mjs +1061 -0
- package/package.json +60 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,895 @@
|
|
|
1
|
+
interface KlingExConfig {
|
|
2
|
+
/** API key for authentication */
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
/** JWT token for authentication (alternative to apiKey) */
|
|
5
|
+
jwt?: string;
|
|
6
|
+
/** Base URL for the API (default: https://api.klingex.io) */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** WebSocket URL (default: wss://api.klingex.io) */
|
|
9
|
+
wsUrl?: string;
|
|
10
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Use human-readable values for orders by default (default: true) */
|
|
13
|
+
humanReadable?: boolean;
|
|
14
|
+
}
|
|
15
|
+
interface ApiResponse<T> {
|
|
16
|
+
success?: boolean;
|
|
17
|
+
data?: T;
|
|
18
|
+
error?: string;
|
|
19
|
+
message?: string;
|
|
20
|
+
}
|
|
21
|
+
interface PaginatedResponse<T> {
|
|
22
|
+
data: T[];
|
|
23
|
+
total: number;
|
|
24
|
+
limit: number;
|
|
25
|
+
offset: number;
|
|
26
|
+
}
|
|
27
|
+
interface Asset {
|
|
28
|
+
id: number;
|
|
29
|
+
symbol: string;
|
|
30
|
+
name: string;
|
|
31
|
+
decimals: number;
|
|
32
|
+
min_deposit: string;
|
|
33
|
+
min_withdrawal: string;
|
|
34
|
+
withdrawal_fee: string;
|
|
35
|
+
is_active?: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface AssetsResponse {
|
|
38
|
+
assets: Asset[];
|
|
39
|
+
}
|
|
40
|
+
interface Market {
|
|
41
|
+
id: number;
|
|
42
|
+
base_asset_id: number;
|
|
43
|
+
quote_asset_id: number;
|
|
44
|
+
min_trade_amount: string;
|
|
45
|
+
max_trade_amount: string;
|
|
46
|
+
tick_size: string;
|
|
47
|
+
step_size: string;
|
|
48
|
+
maker_fee_rate: string;
|
|
49
|
+
taker_fee_rate: string;
|
|
50
|
+
price_decimals: number;
|
|
51
|
+
is_active: boolean;
|
|
52
|
+
created_at: string;
|
|
53
|
+
updated_at: string;
|
|
54
|
+
base_asset_symbol: string;
|
|
55
|
+
base_asset_name: string;
|
|
56
|
+
quote_asset_symbol: string;
|
|
57
|
+
quote_asset_name: string;
|
|
58
|
+
volume_24h: string;
|
|
59
|
+
priceChange24h: string;
|
|
60
|
+
last_price: string;
|
|
61
|
+
base_decimals: number;
|
|
62
|
+
quote_decimals: number;
|
|
63
|
+
volume_24h_human: string;
|
|
64
|
+
}
|
|
65
|
+
interface Ticker {
|
|
66
|
+
ticker_id: string;
|
|
67
|
+
base_currency: string;
|
|
68
|
+
target_currency: string;
|
|
69
|
+
last_price: string;
|
|
70
|
+
base_volume: string;
|
|
71
|
+
target_volume: string;
|
|
72
|
+
bid: string;
|
|
73
|
+
ask: string;
|
|
74
|
+
high: string;
|
|
75
|
+
low: string;
|
|
76
|
+
}
|
|
77
|
+
interface OrderbookEntry {
|
|
78
|
+
price: string;
|
|
79
|
+
quantity: string;
|
|
80
|
+
}
|
|
81
|
+
interface Orderbook {
|
|
82
|
+
trading_pair_id: number;
|
|
83
|
+
base_symbol: string;
|
|
84
|
+
quote_symbol: string;
|
|
85
|
+
bids: OrderbookEntry[];
|
|
86
|
+
asks: OrderbookEntry[];
|
|
87
|
+
}
|
|
88
|
+
interface OrderbookRaw {
|
|
89
|
+
trading_pair_id: number;
|
|
90
|
+
base_symbol: string;
|
|
91
|
+
quote_symbol: string;
|
|
92
|
+
bids: string[][];
|
|
93
|
+
asks: string[][];
|
|
94
|
+
}
|
|
95
|
+
interface OHLCV {
|
|
96
|
+
time_bucket: string;
|
|
97
|
+
open_price: string;
|
|
98
|
+
high_price: string;
|
|
99
|
+
low_price: string;
|
|
100
|
+
close_price: string;
|
|
101
|
+
volume: string;
|
|
102
|
+
number_of_trades: number;
|
|
103
|
+
}
|
|
104
|
+
type Timeframe = '1m' | '5m' | '15m' | '30m' | '1h' | '4h' | '1d' | '1w';
|
|
105
|
+
type OrderSide = 'buy' | 'sell' | 'BUY' | 'SELL';
|
|
106
|
+
type OrderStatus = 'pending' | 'partial' | 'filled' | 'cancelled' | 'rejected';
|
|
107
|
+
type OrderType = 'limit' | 'market';
|
|
108
|
+
interface SubmitOrderParams {
|
|
109
|
+
/** Trading pair symbol (e.g., "BTC-USDT") */
|
|
110
|
+
symbol: string;
|
|
111
|
+
/** Trading pair ID */
|
|
112
|
+
tradingPairId: number;
|
|
113
|
+
/** Order side */
|
|
114
|
+
side: OrderSide;
|
|
115
|
+
/** Order quantity (human-readable by default, e.g., "1.5") */
|
|
116
|
+
quantity: string;
|
|
117
|
+
/** Order price (human-readable by default, e.g., "50000.00"). Use "0" for market orders */
|
|
118
|
+
price: string;
|
|
119
|
+
/** If true, quantity/price are in base units. If false (default), human-readable */
|
|
120
|
+
rawValues?: boolean;
|
|
121
|
+
/** Slippage tolerance for market orders (0-1) */
|
|
122
|
+
slippage?: number;
|
|
123
|
+
}
|
|
124
|
+
interface Order {
|
|
125
|
+
id: string;
|
|
126
|
+
trading_pair_id: number;
|
|
127
|
+
side: 'buy' | 'sell';
|
|
128
|
+
type: OrderType;
|
|
129
|
+
price: string;
|
|
130
|
+
amount: string;
|
|
131
|
+
filled_amount: string;
|
|
132
|
+
status: OrderStatus;
|
|
133
|
+
created_at: string;
|
|
134
|
+
updated_at: string;
|
|
135
|
+
human_price?: string;
|
|
136
|
+
human_amount?: string;
|
|
137
|
+
human_filled_amount?: string;
|
|
138
|
+
human_remaining?: string;
|
|
139
|
+
human_total?: string;
|
|
140
|
+
}
|
|
141
|
+
interface UserOrdersResponse {
|
|
142
|
+
orders: Order[];
|
|
143
|
+
}
|
|
144
|
+
interface SubmitOrderResponse {
|
|
145
|
+
message: string;
|
|
146
|
+
order_id: string;
|
|
147
|
+
}
|
|
148
|
+
interface CancelOrderParams {
|
|
149
|
+
orderId: string;
|
|
150
|
+
tradingPairId: number;
|
|
151
|
+
}
|
|
152
|
+
interface CancelOrderResponse {
|
|
153
|
+
message: string;
|
|
154
|
+
released_balance: string;
|
|
155
|
+
}
|
|
156
|
+
interface GetOrdersParams {
|
|
157
|
+
tradingPairId?: number;
|
|
158
|
+
status?: OrderStatus;
|
|
159
|
+
limit?: number;
|
|
160
|
+
}
|
|
161
|
+
interface Balance {
|
|
162
|
+
balance: string;
|
|
163
|
+
locked_balance: string;
|
|
164
|
+
wallet_id: string;
|
|
165
|
+
deposit_address: string;
|
|
166
|
+
id: number;
|
|
167
|
+
symbol: string;
|
|
168
|
+
name: string;
|
|
169
|
+
decimals: number;
|
|
170
|
+
min_deposit: string;
|
|
171
|
+
min_withdrawal: string;
|
|
172
|
+
withdrawal_fee: string;
|
|
173
|
+
available_balance?: string;
|
|
174
|
+
human_balance?: string;
|
|
175
|
+
human_locked?: string;
|
|
176
|
+
human_available?: string;
|
|
177
|
+
}
|
|
178
|
+
interface DepositAddress {
|
|
179
|
+
address: string;
|
|
180
|
+
memo?: string;
|
|
181
|
+
network?: string;
|
|
182
|
+
}
|
|
183
|
+
interface WithdrawParams {
|
|
184
|
+
assetId: number;
|
|
185
|
+
symbol: string;
|
|
186
|
+
address: string;
|
|
187
|
+
amount: string;
|
|
188
|
+
memo?: string;
|
|
189
|
+
}
|
|
190
|
+
interface WithdrawResponse {
|
|
191
|
+
message: string;
|
|
192
|
+
withdrawal_id?: string;
|
|
193
|
+
requires_2fa?: boolean;
|
|
194
|
+
session_token?: string;
|
|
195
|
+
}
|
|
196
|
+
type InvoiceStatus = 'pending' | 'paid' | 'expired' | 'cancelled' | 'overpaid' | 'underpaid';
|
|
197
|
+
interface CreateInvoiceParams {
|
|
198
|
+
/** Amount in the specified asset */
|
|
199
|
+
amount: string;
|
|
200
|
+
/** Asset symbol (e.g., "USDT") */
|
|
201
|
+
asset: string;
|
|
202
|
+
/** Optional description */
|
|
203
|
+
description?: string;
|
|
204
|
+
/** External reference ID */
|
|
205
|
+
external_id?: string;
|
|
206
|
+
/** Webhook URL for payment notifications */
|
|
207
|
+
webhook_url?: string;
|
|
208
|
+
/** Redirect URL after payment */
|
|
209
|
+
redirect_url?: string;
|
|
210
|
+
/** Expiration time in minutes (default: 60) */
|
|
211
|
+
expires_in?: number;
|
|
212
|
+
}
|
|
213
|
+
interface Invoice {
|
|
214
|
+
id: string;
|
|
215
|
+
amount: string;
|
|
216
|
+
asset: string;
|
|
217
|
+
status: InvoiceStatus;
|
|
218
|
+
description?: string;
|
|
219
|
+
external_id?: string;
|
|
220
|
+
payment_address: string;
|
|
221
|
+
payment_amount?: string;
|
|
222
|
+
paid_at?: string;
|
|
223
|
+
expires_at: string;
|
|
224
|
+
created_at: string;
|
|
225
|
+
webhook_url?: string;
|
|
226
|
+
redirect_url?: string;
|
|
227
|
+
}
|
|
228
|
+
interface InvoiceFees {
|
|
229
|
+
network_fee: string;
|
|
230
|
+
service_fee: string;
|
|
231
|
+
total_fee: string;
|
|
232
|
+
}
|
|
233
|
+
type WebSocketChannel = 'orderbook' | 'trades' | 'ticker' | 'user.orders' | 'user.balances';
|
|
234
|
+
interface WebSocketMessage<T = unknown> {
|
|
235
|
+
channel: WebSocketChannel;
|
|
236
|
+
event: string;
|
|
237
|
+
data: T;
|
|
238
|
+
timestamp: string;
|
|
239
|
+
}
|
|
240
|
+
interface WebSocketOptions {
|
|
241
|
+
/** Reconnect automatically on disconnect (default: true) */
|
|
242
|
+
reconnect?: boolean;
|
|
243
|
+
/** Reconnect interval in milliseconds (default: 5000) */
|
|
244
|
+
reconnectInterval?: number;
|
|
245
|
+
/** Maximum reconnection attempts (default: 10) */
|
|
246
|
+
maxReconnectAttempts?: number;
|
|
247
|
+
}
|
|
248
|
+
declare class KlingExError extends Error {
|
|
249
|
+
code?: string | undefined;
|
|
250
|
+
statusCode?: number | undefined;
|
|
251
|
+
details?: unknown | undefined;
|
|
252
|
+
constructor(message: string, code?: string | undefined, statusCode?: number | undefined, details?: unknown | undefined);
|
|
253
|
+
}
|
|
254
|
+
declare class AuthenticationError extends KlingExError {
|
|
255
|
+
constructor(message?: string);
|
|
256
|
+
}
|
|
257
|
+
declare class RateLimitError extends KlingExError {
|
|
258
|
+
retryAfter?: number | undefined;
|
|
259
|
+
constructor(message?: string, retryAfter?: number | undefined);
|
|
260
|
+
}
|
|
261
|
+
declare class ValidationError extends KlingExError {
|
|
262
|
+
constructor(message: string, details?: unknown);
|
|
263
|
+
}
|
|
264
|
+
declare class InsufficientFundsError extends KlingExError {
|
|
265
|
+
constructor(message?: string);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
type MessageHandler<T = unknown> = (data: T) => void;
|
|
269
|
+
type ErrorHandler = (error: Error) => void;
|
|
270
|
+
declare class KlingExWebSocket {
|
|
271
|
+
private ws;
|
|
272
|
+
private url;
|
|
273
|
+
private apiKey?;
|
|
274
|
+
private jwt?;
|
|
275
|
+
private options;
|
|
276
|
+
private subscriptions;
|
|
277
|
+
private reconnectAttempts;
|
|
278
|
+
private reconnectTimeout;
|
|
279
|
+
private pingInterval;
|
|
280
|
+
private isConnecting;
|
|
281
|
+
private errorHandler?;
|
|
282
|
+
constructor(url: string, auth: {
|
|
283
|
+
apiKey?: string;
|
|
284
|
+
jwt?: string;
|
|
285
|
+
}, options?: WebSocketOptions);
|
|
286
|
+
/**
|
|
287
|
+
* Connect to WebSocket server
|
|
288
|
+
*/
|
|
289
|
+
connect(): Promise<void>;
|
|
290
|
+
/**
|
|
291
|
+
* Disconnect from WebSocket server
|
|
292
|
+
*/
|
|
293
|
+
disconnect(): void;
|
|
294
|
+
/**
|
|
295
|
+
* Set error handler
|
|
296
|
+
*/
|
|
297
|
+
onError(handler: ErrorHandler): void;
|
|
298
|
+
/**
|
|
299
|
+
* Subscribe to orderbook updates
|
|
300
|
+
* @param symbol - Trading pair symbol
|
|
301
|
+
* @param handler - Callback for orderbook updates
|
|
302
|
+
*/
|
|
303
|
+
orderbook(symbol: string, handler: MessageHandler<Orderbook>): () => void;
|
|
304
|
+
/**
|
|
305
|
+
* Subscribe to trade updates
|
|
306
|
+
* @param symbol - Trading pair symbol
|
|
307
|
+
* @param handler - Callback for trade updates
|
|
308
|
+
*/
|
|
309
|
+
trades(symbol: string, handler: MessageHandler<{
|
|
310
|
+
id: string;
|
|
311
|
+
price: string;
|
|
312
|
+
quantity: string;
|
|
313
|
+
side: 'buy' | 'sell';
|
|
314
|
+
timestamp: string;
|
|
315
|
+
}>): () => void;
|
|
316
|
+
/**
|
|
317
|
+
* Subscribe to ticker updates
|
|
318
|
+
* @param symbol - Trading pair symbol
|
|
319
|
+
* @param handler - Callback for ticker updates
|
|
320
|
+
*/
|
|
321
|
+
ticker(symbol: string, handler: MessageHandler<Ticker>): () => void;
|
|
322
|
+
/**
|
|
323
|
+
* Subscribe to user order updates (requires auth)
|
|
324
|
+
* @param handler - Callback for order updates
|
|
325
|
+
*/
|
|
326
|
+
userOrders(handler: MessageHandler<Order>): () => void;
|
|
327
|
+
/**
|
|
328
|
+
* Subscribe to user balance updates (requires auth)
|
|
329
|
+
* @param handler - Callback for balance updates
|
|
330
|
+
*/
|
|
331
|
+
userBalances(handler: MessageHandler<Balance>): () => void;
|
|
332
|
+
private subscribe;
|
|
333
|
+
private sendSubscribe;
|
|
334
|
+
private sendUnsubscribe;
|
|
335
|
+
private send;
|
|
336
|
+
private handleMessage;
|
|
337
|
+
private resubscribeAll;
|
|
338
|
+
private scheduleReconnect;
|
|
339
|
+
private startPingInterval;
|
|
340
|
+
private stopPingInterval;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
interface HttpClientConfig {
|
|
344
|
+
baseUrl: string;
|
|
345
|
+
apiKey?: string;
|
|
346
|
+
jwt?: string;
|
|
347
|
+
timeout: number;
|
|
348
|
+
}
|
|
349
|
+
interface RequestOptions {
|
|
350
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
351
|
+
body?: unknown;
|
|
352
|
+
params?: Record<string, string | number | boolean | undefined>;
|
|
353
|
+
headers?: Record<string, string>;
|
|
354
|
+
}
|
|
355
|
+
declare class HttpClient {
|
|
356
|
+
private config;
|
|
357
|
+
constructor(config: HttpClientConfig);
|
|
358
|
+
/**
|
|
359
|
+
* Update authentication credentials
|
|
360
|
+
*/
|
|
361
|
+
setAuth(auth: {
|
|
362
|
+
apiKey?: string;
|
|
363
|
+
jwt?: string;
|
|
364
|
+
}): void;
|
|
365
|
+
/**
|
|
366
|
+
* Make an HTTP request to the API
|
|
367
|
+
*/
|
|
368
|
+
request<T>(endpoint: string, options?: RequestOptions): Promise<T>;
|
|
369
|
+
/**
|
|
370
|
+
* Handle HTTP error responses
|
|
371
|
+
*/
|
|
372
|
+
private handleError;
|
|
373
|
+
/**
|
|
374
|
+
* Extract error message from response
|
|
375
|
+
*/
|
|
376
|
+
private extractErrorMessage;
|
|
377
|
+
/**
|
|
378
|
+
* Extract retry-after value from rate limit response
|
|
379
|
+
*/
|
|
380
|
+
private extractRetryAfter;
|
|
381
|
+
get<T>(endpoint: string, params?: Record<string, string | number | boolean | undefined>): Promise<T>;
|
|
382
|
+
post<T>(endpoint: string, body?: unknown): Promise<T>;
|
|
383
|
+
put<T>(endpoint: string, body?: unknown): Promise<T>;
|
|
384
|
+
delete<T>(endpoint: string, body?: unknown): Promise<T>;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
declare class MarketsEndpoint {
|
|
388
|
+
private http;
|
|
389
|
+
constructor(http: HttpClient);
|
|
390
|
+
/**
|
|
391
|
+
* Get all available markets/trading pairs
|
|
392
|
+
* @example
|
|
393
|
+
* const markets = await client.markets.list();
|
|
394
|
+
* // Returns full market info including:
|
|
395
|
+
* // - base_asset_symbol, quote_asset_symbol
|
|
396
|
+
* // - maker_fee_rate, taker_fee_rate
|
|
397
|
+
* // - last_price, volume_24h, priceChange24h
|
|
398
|
+
*/
|
|
399
|
+
list(): Promise<Market[]>;
|
|
400
|
+
/**
|
|
401
|
+
* Get a specific market by ID
|
|
402
|
+
* @param marketId - The market/trading pair ID
|
|
403
|
+
*/
|
|
404
|
+
get(marketId: number): Promise<Market | undefined>;
|
|
405
|
+
/**
|
|
406
|
+
* Find a market by symbol pair
|
|
407
|
+
* @param baseSymbol - Base asset symbol (e.g., "BTC")
|
|
408
|
+
* @param quoteSymbol - Quote asset symbol (e.g., "USDT")
|
|
409
|
+
*/
|
|
410
|
+
findBySymbols(baseSymbol: string, quoteSymbol: string): Promise<Market | undefined>;
|
|
411
|
+
/**
|
|
412
|
+
* Get all tickers with 24h price data (CMC format)
|
|
413
|
+
* @example
|
|
414
|
+
* const tickers = await client.markets.tickers();
|
|
415
|
+
* // Returns ticker_id as "BTC_USDT" format
|
|
416
|
+
*/
|
|
417
|
+
tickers(): Promise<Ticker[]>;
|
|
418
|
+
/**
|
|
419
|
+
* Get ticker for a specific symbol pair
|
|
420
|
+
* @param tickerId - Ticker ID in CMC format (e.g., "BTC_USDT")
|
|
421
|
+
*/
|
|
422
|
+
ticker(tickerId: string): Promise<Ticker | undefined>;
|
|
423
|
+
/**
|
|
424
|
+
* Get ticker by base and quote currency
|
|
425
|
+
* @param baseCurrency - Base currency symbol (e.g., "BTC")
|
|
426
|
+
* @param targetCurrency - Target/quote currency symbol (e.g., "USDT")
|
|
427
|
+
*/
|
|
428
|
+
tickerByPair(baseCurrency: string, targetCurrency: string): Promise<Ticker | undefined>;
|
|
429
|
+
/**
|
|
430
|
+
* Get orderbook for a trading pair
|
|
431
|
+
* @param marketId - The market/trading pair ID
|
|
432
|
+
* @param options - Options for the orderbook request
|
|
433
|
+
* @example
|
|
434
|
+
* const orderbook = await client.markets.orderbook(1);
|
|
435
|
+
* console.log('Best bid:', orderbook.bids[0]);
|
|
436
|
+
* console.log('Best ask:', orderbook.asks[0]);
|
|
437
|
+
*/
|
|
438
|
+
orderbook(marketId: number, options?: {
|
|
439
|
+
isCmc?: boolean;
|
|
440
|
+
}): Promise<Orderbook>;
|
|
441
|
+
/**
|
|
442
|
+
* Get raw orderbook (original API format with arrays)
|
|
443
|
+
* @param marketId - The market/trading pair ID
|
|
444
|
+
*/
|
|
445
|
+
orderbookRaw(marketId: number, options?: {
|
|
446
|
+
isCmc?: boolean;
|
|
447
|
+
}): Promise<OrderbookRaw>;
|
|
448
|
+
/**
|
|
449
|
+
* Get OHLCV (candlestick) data
|
|
450
|
+
* @param marketId - Trading pair ID
|
|
451
|
+
* @param timeframe - Candle timeframe (e.g., "1h", "1d")
|
|
452
|
+
* @param options - Additional options
|
|
453
|
+
* @example
|
|
454
|
+
* const candles = await client.markets.ohlcv(1, '1h');
|
|
455
|
+
*/
|
|
456
|
+
ohlcv(marketId: number, timeframe: Timeframe, options?: {
|
|
457
|
+
limit?: number;
|
|
458
|
+
startDate?: string;
|
|
459
|
+
endDate?: string;
|
|
460
|
+
}): Promise<OHLCV[]>;
|
|
461
|
+
/**
|
|
462
|
+
* Get all available assets
|
|
463
|
+
* @example
|
|
464
|
+
* const assets = await client.markets.assets();
|
|
465
|
+
*/
|
|
466
|
+
assets(): Promise<Asset[]>;
|
|
467
|
+
/**
|
|
468
|
+
* Get a specific asset by symbol
|
|
469
|
+
* @param symbol - Asset symbol (e.g., "BTC")
|
|
470
|
+
*/
|
|
471
|
+
asset(symbol: string): Promise<Asset | undefined>;
|
|
472
|
+
/**
|
|
473
|
+
* Get recent trades for a trading pair
|
|
474
|
+
* @param marketId - Trading pair ID
|
|
475
|
+
* @param limit - Number of trades to return
|
|
476
|
+
*/
|
|
477
|
+
trades(marketId: number, limit?: number): Promise<Array<{
|
|
478
|
+
id: string;
|
|
479
|
+
price: string;
|
|
480
|
+
quantity: string;
|
|
481
|
+
side: 'buy' | 'sell';
|
|
482
|
+
timestamp: string;
|
|
483
|
+
}>>;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
declare class OrdersEndpoint {
|
|
487
|
+
private http;
|
|
488
|
+
private humanReadableDefault;
|
|
489
|
+
constructor(http: HttpClient, humanReadableDefault?: boolean);
|
|
490
|
+
/**
|
|
491
|
+
* Submit a new order
|
|
492
|
+
* @param params - Order parameters
|
|
493
|
+
* @example
|
|
494
|
+
* // Buy 1.5 BTC at $50,000 (human-readable values)
|
|
495
|
+
* const order = await client.orders.submit({
|
|
496
|
+
* symbol: 'BTC-USDT',
|
|
497
|
+
* tradingPairId: 1,
|
|
498
|
+
* side: 'BUY',
|
|
499
|
+
* quantity: '1.5',
|
|
500
|
+
* price: '50000.00'
|
|
501
|
+
* });
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* // Market order (price = 0)
|
|
505
|
+
* const order = await client.orders.submit({
|
|
506
|
+
* symbol: 'BTC-USDT',
|
|
507
|
+
* tradingPairId: 1,
|
|
508
|
+
* side: 'BUY',
|
|
509
|
+
* quantity: '1.0',
|
|
510
|
+
* price: '0',
|
|
511
|
+
* slippage: 0.01 // 1% slippage tolerance
|
|
512
|
+
* });
|
|
513
|
+
*/
|
|
514
|
+
submit(params: SubmitOrderParams): Promise<SubmitOrderResponse>;
|
|
515
|
+
/**
|
|
516
|
+
* Cancel an existing order
|
|
517
|
+
* @param params - Order ID and trading pair ID
|
|
518
|
+
* @example
|
|
519
|
+
* const result = await client.orders.cancel({
|
|
520
|
+
* orderId: '7c9e6679-7425-40de-944b-e07fc1f90ae7',
|
|
521
|
+
* tradingPairId: 1
|
|
522
|
+
* });
|
|
523
|
+
* console.log(`Released balance: ${result.released_balance}`);
|
|
524
|
+
*/
|
|
525
|
+
cancel(params: CancelOrderParams): Promise<CancelOrderResponse>;
|
|
526
|
+
/**
|
|
527
|
+
* Cancel all open orders for a trading pair
|
|
528
|
+
* @param tradingPairId - Trading pair ID
|
|
529
|
+
* @example
|
|
530
|
+
* const result = await client.orders.cancelAll(1);
|
|
531
|
+
* console.log(`Cancelled ${result.cancelledCount} orders`);
|
|
532
|
+
*/
|
|
533
|
+
cancelAll(tradingPairId: number): Promise<{
|
|
534
|
+
message: string;
|
|
535
|
+
cancelledCount: number;
|
|
536
|
+
totalOrders: number;
|
|
537
|
+
cancelledOrderIds: string[];
|
|
538
|
+
totalReleasedBalance: string;
|
|
539
|
+
}>;
|
|
540
|
+
/**
|
|
541
|
+
* Get your open orders
|
|
542
|
+
* @param params - Filter parameters
|
|
543
|
+
* @example
|
|
544
|
+
* // Get all open orders
|
|
545
|
+
* const orders = await client.orders.list();
|
|
546
|
+
*
|
|
547
|
+
* // Get orders for specific trading pair
|
|
548
|
+
* const orders = await client.orders.list({ tradingPairId: 1 });
|
|
549
|
+
*/
|
|
550
|
+
list(params?: GetOrdersParams): Promise<Order[]>;
|
|
551
|
+
/**
|
|
552
|
+
* Get order history (including filled/cancelled orders)
|
|
553
|
+
* @param params - Filter and pagination parameters
|
|
554
|
+
*/
|
|
555
|
+
history(params?: {
|
|
556
|
+
tradingPairId?: number;
|
|
557
|
+
status?: string;
|
|
558
|
+
limit?: number;
|
|
559
|
+
offset?: number;
|
|
560
|
+
}): Promise<{
|
|
561
|
+
orders: Order[];
|
|
562
|
+
total: number;
|
|
563
|
+
limit: number;
|
|
564
|
+
offset: number;
|
|
565
|
+
}>;
|
|
566
|
+
/**
|
|
567
|
+
* Get a specific order by ID
|
|
568
|
+
* @param orderId - Order UUID
|
|
569
|
+
*/
|
|
570
|
+
get(orderId: string): Promise<Order | undefined>;
|
|
571
|
+
/**
|
|
572
|
+
* Place a limit buy order (human-readable values)
|
|
573
|
+
* @param symbol - Trading pair symbol (e.g., "BTC-USDT")
|
|
574
|
+
* @param tradingPairId - Trading pair ID
|
|
575
|
+
* @param quantity - Amount to buy
|
|
576
|
+
* @param price - Price per unit
|
|
577
|
+
*/
|
|
578
|
+
limitBuy(symbol: string, tradingPairId: number, quantity: string, price: string): Promise<SubmitOrderResponse>;
|
|
579
|
+
/**
|
|
580
|
+
* Place a limit sell order (human-readable values)
|
|
581
|
+
* @param symbol - Trading pair symbol (e.g., "BTC-USDT")
|
|
582
|
+
* @param tradingPairId - Trading pair ID
|
|
583
|
+
* @param quantity - Amount to sell
|
|
584
|
+
* @param price - Price per unit
|
|
585
|
+
*/
|
|
586
|
+
limitSell(symbol: string, tradingPairId: number, quantity: string, price: string): Promise<SubmitOrderResponse>;
|
|
587
|
+
/**
|
|
588
|
+
* Place a market buy order
|
|
589
|
+
* @param symbol - Trading pair symbol (e.g., "BTC-USDT")
|
|
590
|
+
* @param tradingPairId - Trading pair ID
|
|
591
|
+
* @param quantity - Amount to buy
|
|
592
|
+
* @param slippage - Slippage tolerance (0-1, e.g., 0.01 for 1%)
|
|
593
|
+
*/
|
|
594
|
+
marketBuy(symbol: string, tradingPairId: number, quantity: string, slippage?: number): Promise<SubmitOrderResponse>;
|
|
595
|
+
/**
|
|
596
|
+
* Place a market sell order
|
|
597
|
+
* @param symbol - Trading pair symbol (e.g., "BTC-USDT")
|
|
598
|
+
* @param tradingPairId - Trading pair ID
|
|
599
|
+
* @param quantity - Amount to sell
|
|
600
|
+
* @param slippage - Slippage tolerance (0-1, e.g., 0.01 for 1%)
|
|
601
|
+
*/
|
|
602
|
+
marketSell(symbol: string, tradingPairId: number, quantity: string, slippage?: number): Promise<SubmitOrderResponse>;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
declare class WalletEndpoint {
|
|
606
|
+
private http;
|
|
607
|
+
constructor(http: HttpClient);
|
|
608
|
+
/**
|
|
609
|
+
* Get all wallet balances
|
|
610
|
+
* Each balance includes:
|
|
611
|
+
* - balance: Total balance (raw value)
|
|
612
|
+
* - locked_balance: Locked in orders (raw value)
|
|
613
|
+
* - wallet_id: UUID of the wallet
|
|
614
|
+
* - deposit_address: Deposit address for this asset
|
|
615
|
+
* - id, symbol, name, decimals: Asset info
|
|
616
|
+
* - min_deposit, min_withdrawal, withdrawal_fee: Limits
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* const balances = await client.wallet.balances();
|
|
620
|
+
* const ethBalance = balances.find(b => b.symbol === 'ETH');
|
|
621
|
+
* console.log(`ETH Balance: ${ethBalance?.balance}`);
|
|
622
|
+
* console.log(`Deposit Address: ${ethBalance?.deposit_address}`);
|
|
623
|
+
*/
|
|
624
|
+
balances(): Promise<Balance[]>;
|
|
625
|
+
/**
|
|
626
|
+
* Get balance for a specific asset
|
|
627
|
+
* @param symbol - Asset symbol (e.g., "BTC", "ETH", "USDT")
|
|
628
|
+
*/
|
|
629
|
+
balance(symbol: string): Promise<Balance | undefined>;
|
|
630
|
+
/**
|
|
631
|
+
* Get deposit address for an asset (from balance data)
|
|
632
|
+
* The deposit_address is included in the balance response
|
|
633
|
+
* @param symbol - Asset symbol (e.g., "BTC")
|
|
634
|
+
* @example
|
|
635
|
+
* const address = await client.wallet.depositAddress('ETH');
|
|
636
|
+
* console.log(`Send ETH to: ${address.address}`);
|
|
637
|
+
*/
|
|
638
|
+
depositAddress(symbol: string): Promise<DepositAddress | undefined>;
|
|
639
|
+
/**
|
|
640
|
+
* Generate a new deposit address (if supported)
|
|
641
|
+
* @param assetId - Asset ID
|
|
642
|
+
*/
|
|
643
|
+
generateDepositAddress(assetId: number): Promise<DepositAddress>;
|
|
644
|
+
/**
|
|
645
|
+
* Submit a withdrawal request
|
|
646
|
+
* @param params - Withdrawal parameters
|
|
647
|
+
* @example
|
|
648
|
+
* const result = await client.wallet.withdraw({
|
|
649
|
+
* assetId: 2,
|
|
650
|
+
* symbol: 'ETH',
|
|
651
|
+
* address: '0x...',
|
|
652
|
+
* amount: '0.1'
|
|
653
|
+
* });
|
|
654
|
+
*
|
|
655
|
+
* if (result.requires_2fa) {
|
|
656
|
+
* // Need to complete 2FA verification
|
|
657
|
+
* await client.wallet.confirm2FA(result.session_token, '123456');
|
|
658
|
+
* }
|
|
659
|
+
*/
|
|
660
|
+
withdraw(params: WithdrawParams): Promise<WithdrawResponse>;
|
|
661
|
+
/**
|
|
662
|
+
* Complete withdrawal 2FA verification
|
|
663
|
+
* @param sessionToken - Session token from withdraw response
|
|
664
|
+
* @param code - 2FA code from authenticator app
|
|
665
|
+
*/
|
|
666
|
+
confirm2FA(sessionToken: string, code: string): Promise<{
|
|
667
|
+
message: string;
|
|
668
|
+
}>;
|
|
669
|
+
/**
|
|
670
|
+
* Get deposit history
|
|
671
|
+
* @param options - Pagination options
|
|
672
|
+
*/
|
|
673
|
+
deposits(options?: {
|
|
674
|
+
limit?: number;
|
|
675
|
+
offset?: number;
|
|
676
|
+
}): Promise<{
|
|
677
|
+
deposits: Array<{
|
|
678
|
+
id: string;
|
|
679
|
+
asset_id: number;
|
|
680
|
+
symbol: string;
|
|
681
|
+
amount: string;
|
|
682
|
+
address: string;
|
|
683
|
+
tx_hash?: string;
|
|
684
|
+
status: string;
|
|
685
|
+
confirmations: number;
|
|
686
|
+
created_at: string;
|
|
687
|
+
}>;
|
|
688
|
+
total: number;
|
|
689
|
+
}>;
|
|
690
|
+
/**
|
|
691
|
+
* Get withdrawal history
|
|
692
|
+
* @param options - Pagination options
|
|
693
|
+
*/
|
|
694
|
+
withdrawals(options?: {
|
|
695
|
+
limit?: number;
|
|
696
|
+
offset?: number;
|
|
697
|
+
}): Promise<{
|
|
698
|
+
withdrawals: Array<{
|
|
699
|
+
id: string;
|
|
700
|
+
asset_id: number;
|
|
701
|
+
symbol: string;
|
|
702
|
+
amount: string;
|
|
703
|
+
fee: string;
|
|
704
|
+
address: string;
|
|
705
|
+
tx_hash?: string;
|
|
706
|
+
status: string;
|
|
707
|
+
created_at: string;
|
|
708
|
+
}>;
|
|
709
|
+
total: number;
|
|
710
|
+
}>;
|
|
711
|
+
/**
|
|
712
|
+
* Get transaction history (deposits + withdrawals + trades)
|
|
713
|
+
*/
|
|
714
|
+
history(): Promise<Array<{
|
|
715
|
+
id: string;
|
|
716
|
+
type: 'deposit' | 'withdrawal' | 'trade';
|
|
717
|
+
asset: string;
|
|
718
|
+
amount: string;
|
|
719
|
+
status: string;
|
|
720
|
+
created_at: string;
|
|
721
|
+
}>>;
|
|
722
|
+
/**
|
|
723
|
+
* Format raw units to human-readable decimal string
|
|
724
|
+
* @param value - Raw value as string
|
|
725
|
+
* @param decimals - Number of decimals
|
|
726
|
+
*/
|
|
727
|
+
private formatUnits;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
declare class InvoicesEndpoint {
|
|
731
|
+
private http;
|
|
732
|
+
constructor(http: HttpClient);
|
|
733
|
+
/**
|
|
734
|
+
* Create a new payment invoice
|
|
735
|
+
* @param params - Invoice parameters
|
|
736
|
+
* @example
|
|
737
|
+
* const invoice = await client.invoices.create({
|
|
738
|
+
* amount: '100.00',
|
|
739
|
+
* asset: 'USDT',
|
|
740
|
+
* description: 'Order #12345',
|
|
741
|
+
* external_id: 'order-12345',
|
|
742
|
+
* webhook_url: 'https://yoursite.com/webhook'
|
|
743
|
+
* });
|
|
744
|
+
*
|
|
745
|
+
* console.log(`Payment address: ${invoice.payment_address}`);
|
|
746
|
+
* console.log(`Expires: ${invoice.expires_at}`);
|
|
747
|
+
*/
|
|
748
|
+
create(params: CreateInvoiceParams): Promise<Invoice>;
|
|
749
|
+
/**
|
|
750
|
+
* Get all invoices
|
|
751
|
+
* @param options - Pagination and filter options
|
|
752
|
+
*/
|
|
753
|
+
list(options?: {
|
|
754
|
+
limit?: number;
|
|
755
|
+
offset?: number;
|
|
756
|
+
status?: string;
|
|
757
|
+
}): Promise<PaginatedResponse<Invoice>>;
|
|
758
|
+
/**
|
|
759
|
+
* Get a specific invoice by ID
|
|
760
|
+
* @param invoiceId - Invoice UUID
|
|
761
|
+
*/
|
|
762
|
+
get(invoiceId: string): Promise<Invoice>;
|
|
763
|
+
/**
|
|
764
|
+
* Get invoice status (for polling)
|
|
765
|
+
* @param invoiceId - Invoice UUID
|
|
766
|
+
*/
|
|
767
|
+
status(invoiceId: string): Promise<{
|
|
768
|
+
status: string;
|
|
769
|
+
paid_amount?: string;
|
|
770
|
+
confirmations?: number;
|
|
771
|
+
}>;
|
|
772
|
+
/**
|
|
773
|
+
* Cancel a pending invoice
|
|
774
|
+
* @param invoiceId - Invoice UUID
|
|
775
|
+
*/
|
|
776
|
+
cancel(invoiceId: string): Promise<{
|
|
777
|
+
message: string;
|
|
778
|
+
}>;
|
|
779
|
+
/**
|
|
780
|
+
* Get invoice PDF
|
|
781
|
+
* @param invoiceId - Invoice UUID
|
|
782
|
+
* @returns PDF blob
|
|
783
|
+
*/
|
|
784
|
+
pdf(invoiceId: string): Promise<Blob>;
|
|
785
|
+
/**
|
|
786
|
+
* Get estimated fees for an invoice
|
|
787
|
+
* @param asset - Asset symbol
|
|
788
|
+
* @param amount - Invoice amount
|
|
789
|
+
*/
|
|
790
|
+
fees(asset: string, amount: string): Promise<InvoiceFees>;
|
|
791
|
+
/**
|
|
792
|
+
* Get public invoice payment page data (no auth required)
|
|
793
|
+
* @param invoiceId - Invoice UUID
|
|
794
|
+
*/
|
|
795
|
+
paymentPage(invoiceId: string): Promise<{
|
|
796
|
+
invoice: Invoice;
|
|
797
|
+
qr_code?: string;
|
|
798
|
+
payment_uri?: string;
|
|
799
|
+
}>;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* KlingEx API Client
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* // Initialize with API key
|
|
807
|
+
* const client = new KlingEx({
|
|
808
|
+
* apiKey: 'your-api-key-here'
|
|
809
|
+
* });
|
|
810
|
+
*
|
|
811
|
+
* // Get markets
|
|
812
|
+
* const markets = await client.markets.list();
|
|
813
|
+
*
|
|
814
|
+
* // Place an order (human-readable values)
|
|
815
|
+
* const order = await client.orders.submit({
|
|
816
|
+
* symbol: 'BTC-USDT',
|
|
817
|
+
* tradingPairId: 1,
|
|
818
|
+
* side: 'buy',
|
|
819
|
+
* quantity: '1.5',
|
|
820
|
+
* price: '50000.00'
|
|
821
|
+
* });
|
|
822
|
+
*
|
|
823
|
+
* // Subscribe to real-time orderbook
|
|
824
|
+
* await client.ws.connect();
|
|
825
|
+
* client.ws.orderbook('BTC-USDT', (data) => {
|
|
826
|
+
* console.log('Orderbook update:', data);
|
|
827
|
+
* });
|
|
828
|
+
*/
|
|
829
|
+
declare class KlingEx {
|
|
830
|
+
private http;
|
|
831
|
+
private _ws;
|
|
832
|
+
private config;
|
|
833
|
+
/** Market data endpoints */
|
|
834
|
+
readonly markets: MarketsEndpoint;
|
|
835
|
+
/** Order management endpoints */
|
|
836
|
+
readonly orders: OrdersEndpoint;
|
|
837
|
+
/** Wallet/balance endpoints */
|
|
838
|
+
readonly wallet: WalletEndpoint;
|
|
839
|
+
/** Invoice/payment endpoints */
|
|
840
|
+
readonly invoices: InvoicesEndpoint;
|
|
841
|
+
constructor(config?: KlingExConfig);
|
|
842
|
+
/**
|
|
843
|
+
* WebSocket client for real-time data
|
|
844
|
+
* Note: Call ws.connect() before subscribing to channels
|
|
845
|
+
*/
|
|
846
|
+
get ws(): KlingExWebSocket;
|
|
847
|
+
/**
|
|
848
|
+
* Create WebSocket connection with custom options
|
|
849
|
+
*/
|
|
850
|
+
createWebSocket(options?: WebSocketOptions): KlingExWebSocket;
|
|
851
|
+
/**
|
|
852
|
+
* Update authentication credentials
|
|
853
|
+
*/
|
|
854
|
+
setAuth(auth: {
|
|
855
|
+
apiKey?: string;
|
|
856
|
+
jwt?: string;
|
|
857
|
+
}): void;
|
|
858
|
+
/**
|
|
859
|
+
* Check if client has authentication configured
|
|
860
|
+
*/
|
|
861
|
+
get isAuthenticated(): boolean;
|
|
862
|
+
/**
|
|
863
|
+
* Get the configured base URL
|
|
864
|
+
*/
|
|
865
|
+
get baseUrl(): string;
|
|
866
|
+
/**
|
|
867
|
+
* Get current user profile
|
|
868
|
+
*/
|
|
869
|
+
getProfile(): Promise<{
|
|
870
|
+
id: string;
|
|
871
|
+
email: string;
|
|
872
|
+
created_at: string;
|
|
873
|
+
two_fa_enabled: boolean;
|
|
874
|
+
}>;
|
|
875
|
+
/**
|
|
876
|
+
* Get current user info
|
|
877
|
+
*/
|
|
878
|
+
getUser(): Promise<{
|
|
879
|
+
id: string;
|
|
880
|
+
email: string;
|
|
881
|
+
is_active: boolean;
|
|
882
|
+
is_email_verified: boolean;
|
|
883
|
+
created_at: string;
|
|
884
|
+
}>;
|
|
885
|
+
/**
|
|
886
|
+
* Get API key statistics
|
|
887
|
+
*/
|
|
888
|
+
getApiKeyStats(): Promise<{
|
|
889
|
+
total_keys: number;
|
|
890
|
+
active_keys: number;
|
|
891
|
+
last_used_at?: string;
|
|
892
|
+
}>;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
export { type ApiResponse, type Asset, type AssetsResponse, AuthenticationError, type Balance, type CancelOrderParams, type CancelOrderResponse, type CreateInvoiceParams, type DepositAddress, type GetOrdersParams, InsufficientFundsError, type Invoice, type InvoiceFees, type InvoiceStatus, InvoicesEndpoint, KlingEx, type KlingExConfig, KlingExError, KlingExWebSocket, type Market, MarketsEndpoint, type OHLCV, type Order, type OrderSide, type OrderStatus, type OrderType, type Orderbook, type OrderbookEntry, type OrderbookRaw, OrdersEndpoint, type PaginatedResponse, RateLimitError, type SubmitOrderParams, type SubmitOrderResponse, type Ticker, type Timeframe, type UserOrdersResponse, ValidationError, WalletEndpoint, type WebSocketChannel, type WebSocketMessage, type WebSocketOptions, type WithdrawParams, type WithdrawResponse, KlingEx as default };
|