@axis-markets/client 0.3.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/src/index.d.ts ADDED
@@ -0,0 +1,584 @@
1
+ /**
2
+ * Trading order type - instructions to contract how to execute the trade
3
+ */
4
+ export enum OrderKind {
5
+ Limit = 1,
6
+ Fill = 2,
7
+ FillOrKill = 3,
8
+ }
9
+ /**
10
+ * Trade direction instructions
11
+ */
12
+ export enum TradeDirection {
13
+ Sell = 1,
14
+ Buy = 2,
15
+ }
16
+
17
+ /**
18
+ * Order properties, stored on-chain
19
+ */
20
+ export interface Order {
21
+ /**
22
+ * Amount left to sell/buy
23
+ */
24
+ amount: bigint;
25
+ /**
26
+ * Buying token address
27
+ */
28
+ buying: string;
29
+ /**
30
+ * expiration timestamp
31
+ */
32
+ expires: bigint;
33
+ /**
34
+ * Unique order identifier
35
+ */
36
+ id: bigint;
37
+ /**
38
+ * Order type
39
+ */
40
+ kind: OrderKind;
41
+ /**
42
+ * Maker address
43
+ */
44
+ owner: string;
45
+ /**
46
+ * Order price
47
+ */
48
+ price: bigint;
49
+ /**
50
+ * Initial selling/buying amount
51
+ */
52
+ quote: bigint;
53
+ /**
54
+ * Selling token address
55
+ */
56
+ selling: string;
57
+ }
58
+
59
+ /**
60
+ * Orderbook trade event
61
+ */
62
+ export interface Trade {
63
+ /**
64
+ * Bought tokens amount
65
+ */
66
+ bought: bigint;
67
+ /**
68
+ * Bought asset address
69
+ */
70
+ buying: string;
71
+ /**
72
+ * Unique trade id
73
+ */
74
+ id: bigint;
75
+ /**
76
+ * Seller account address
77
+ */
78
+ maker: string;
79
+ /**
80
+ * Order id
81
+ */
82
+ order: bigint;
83
+ /**
84
+ * Sold asset address
85
+ */
86
+ selling: string;
87
+ /**
88
+ * Sold tokens amount
89
+ */
90
+ sold: bigint;
91
+ /**
92
+ * Trader account address
93
+ */
94
+ taker: string;
95
+ }
96
+
97
+ /**
98
+ * A trade step in a multi-market swap path.
99
+ */
100
+ export interface TradeStep {
101
+ /**
102
+ * Asset to buy at this step
103
+ */
104
+ asset: string;
105
+ /**
106
+ * Maker order IDs to match
107
+ */
108
+ orders: Array<bigint>;
109
+ }
110
+
111
+ /**
112
+ * Orderbook swap event
113
+ */
114
+ export interface Swap {
115
+ /**
116
+ * Amount of `buying` tokens received
117
+ */
118
+ bought: bigint;
119
+ /**
120
+ * Amount of `selling` tokens sold
121
+ */
122
+ sold: bigint;
123
+ /**
124
+ * Trader account address
125
+ */
126
+ trader: string;
127
+ }
128
+
129
+ /**
130
+ * Standard contract errors
131
+ */
132
+ export declare const ContractErrors: {
133
+ 701: {message: "NotAuthorized"};
134
+ 702: {message: "InsufficientBalance"};
135
+ 703: {message: "OrderNotFound"};
136
+ 704: {message: "Overflow"};
137
+ 705: {message: "InvalidMatch"};
138
+ 706: {message: "InvalidPrice"};
139
+ }
140
+
141
+ export interface ClientInitializationParams {
142
+ /** Public key of the account that will interact with the contract */
143
+ publicKey: string;
144
+ /** Callback for signing transactions generated by the client */
145
+ signTransaction: SignTransactionCallback;
146
+ /** URL of the RPC server */
147
+ rpcUrl: string;
148
+ /** DEX contract ID */
149
+ contractId: string;
150
+ /** Network passphrase (Pubnet passphrase by default) */
151
+ networkPassphrase?: string;
152
+ /** Transaction fee (0.1 XLM by default) */
153
+ fee?: string;
154
+ }
155
+
156
+ export type SignTransactionCallback = (
157
+ tx: string,
158
+ context: {network: string; networkPassphrase: string; accountToSign: string}
159
+ ) => Promise<{signedTxXdr: string; signerAddress?: string}>;
160
+
161
+ export interface TradeArguments {
162
+ /** Trading order behavior */
163
+ kind: OrderKind,
164
+ /** Trader address */
165
+ trader: string;
166
+ /** Tokens amount */
167
+ amount: bigint;
168
+ /** Selling token address */
169
+ selling: string;
170
+ /** Buying token address */
171
+ buying: string;
172
+ /** Price a trader willing to accept */
173
+ price: bigint;
174
+ /** List of order IDs to match before creating the order on-chain */
175
+ orders: Array<bigint>;
176
+ }
177
+
178
+ export interface SellTradeArguments extends TradeArguments {
179
+ /** Amount of `selling` tokens to sell */
180
+ amount: bigint;
181
+ /** Price a trader willing to accept, minimum `buying` tokens per 1 `selling` */
182
+ price: bigint;
183
+ }
184
+
185
+ export interface BuyTradeArguments extends TradeArguments {
186
+ /** Amount of `buying` tokens to acquire */
187
+ amount: bigint;
188
+ /** Price a trader willing to accept, maximum `selling` tokens per 1 `buying` */
189
+ price: bigint;
190
+ }
191
+
192
+ export interface SwapArguments {
193
+ /** Trade direction: `Sell` or `Buy` */
194
+ direction: TradeDirection,
195
+ /** Trader address */
196
+ trader: string,
197
+ /** Token address sent by the trader */
198
+ selling: string,
199
+ /** Maximum amount of selling tokens to send */
200
+ sellingAmount: bigint,
201
+ /** Minimum amount of buying tokens to receive */
202
+ buyingAmount: bigint,
203
+ /** Ordered list of the trade route steps */
204
+ path: Array<TradeStep>
205
+ }
206
+
207
+ export declare class AxisContractClient {
208
+ constructor(params: ClientInitializationParams);
209
+
210
+ /**
211
+ * Retrieve last order id
212
+ * @returns Last created order id
213
+ */
214
+ last(): Promise<bigint>;
215
+
216
+ /**
217
+ * Fetch existing order
218
+ * @param id - ID of the order to fetch
219
+ * @returns Order fetched from the storage
220
+ */
221
+ order(id: bigint): Promise<Order>;
222
+
223
+ /**
224
+ * Cancel existing order
225
+ * @param ids - ID of the order to cancel
226
+ * @param trader - Trader address
227
+ */
228
+ cancel(ids: Array<bigint>, trader: string): Promise<void>;
229
+
230
+ /**
231
+ * Fill existing orders using another matching order from the orderbook
232
+ * @param trader - Trader address
233
+ * @param takerOrderId - ID of the order that serves as a taker
234
+ * @param orders - List of order IDs to match
235
+ * @returns Amount of sold and bought tokens
236
+ */
237
+ fill_order(trader: string, takerOrderId: bigint, orders: Array<bigint>): Promise<[bigint, bigint]>;
238
+
239
+ /**
240
+ * Trade with DEX and create buy limit order if quote not executed in full
241
+ * @param params - Trade parameters
242
+ * @returns Amount of sold tokens, bought tokens, and ID of the newly created order if any
243
+ */
244
+ buy(params: BuyTradeArguments): Promise<[bigint, bigint, bigint]>;
245
+
246
+ /**
247
+ * Trade with DEX and create sell limit order if quote not executed in full
248
+ * @param params - Trade parameters
249
+ * @returns Amount of sold tokens, bought tokens, and ID of the newly created order if any
250
+ */
251
+ sell(params: SellTradeArguments): Promise<[bigint, bigint, bigint]>;
252
+
253
+ /**
254
+ * Swap tokens across several markets.
255
+ * @param params - Trade parameters
256
+ * @returns Amount of sold tokens and bought tokens
257
+ */
258
+ swap(params: SwapArguments): Promise<[bigint, bigint]>;
259
+ }
260
+
261
+ /**
262
+ * Error thrown when the Aggregator API responds with a non-success HTTP status
263
+ */
264
+ export declare class AxisApiError extends Error {
265
+ constructor(message: string, status: number);
266
+
267
+ /** HTTP status code associated with the error */
268
+ readonly status: number;
269
+ }
270
+
271
+ export interface QuoteParams {
272
+ /** Asset to sell (`XLM` | `CODE:Issuer` | `CODE-Issuer` | contractId) */
273
+ sellingAsset: string;
274
+ /** Asset to buy (same format as `sellingAsset`) */
275
+ buyingAsset: string;
276
+ /** Trade amount in stroops (1 unit = 10,000,000 stroops) */
277
+ amount: string | number;
278
+ /** Restrict to the direct market only (no intermediate-asset routes) */
279
+ direct?: boolean;
280
+ }
281
+
282
+ export interface QuotePathStep {
283
+ /** Selling asset contract id at this hop */
284
+ selling: string;
285
+ /** Buying asset contract id at this hop */
286
+ buying: string;
287
+ /** Maker order IDs matched at this hop */
288
+ orders: string[];
289
+ }
290
+
291
+ export interface QuotePath {
292
+ /** Amount sold, in stroops */
293
+ sold: string;
294
+ /** Amount bought, in stroops */
295
+ bought: string;
296
+ /** Ordered list of hops in the route */
297
+ path: QuotePathStep[];
298
+ }
299
+
300
+ export interface QuoteResult {
301
+ /** Base58-encoded quote id */
302
+ id: string;
303
+ /** Quote status */
304
+ status: 'success' | 'unfeasible' | 'rejected';
305
+ /** Trade direction */
306
+ direction: 'strict_send' | 'strict_receive';
307
+ /** Selling asset contract id */
308
+ sellingAsset: string;
309
+ /** Buying asset contract id */
310
+ buyingAsset: string;
311
+ /** Ledger sequence the quote was computed for */
312
+ ledger: number;
313
+ /** Candidate routes ranked by profitability (up to 10) */
314
+ paths: QuotePath[];
315
+ /** Error message (present only if status is not `success`) */
316
+ error?: string;
317
+ }
318
+
319
+ export interface DepthParams {
320
+ /** Market identifier `BASE/QUOTE` */
321
+ market: string;
322
+ /** Percentage band (±) around the center price (0 < depth ≤ 100, default 20) */
323
+ depth?: number;
324
+ }
325
+
326
+ export interface OrderbookDepth {
327
+ /** Ledger sequence */
328
+ ledger: number;
329
+ /** UNIX timestamp (seconds) */
330
+ timestamp: number;
331
+ /** `[price, quantity]` pairs sorted descending by price */
332
+ bids: Array<[string, string]>;
333
+ /** `[price, quantity]` pairs sorted ascending by price */
334
+ asks: Array<[string, string]>;
335
+ }
336
+
337
+ export interface CandlesParams {
338
+ /** Market identifier `BASE/QUOTE` */
339
+ market: string;
340
+ /** Lower boundary (UNIX seconds, default 0) */
341
+ from?: number;
342
+ /** Upper boundary (UNIX seconds, defaults to `from + resolution * 200`) */
343
+ to?: number;
344
+ /** Resolution in seconds or alias (`5m`,`15m`,`30m`,`1h`,`2h`,`4h`,`12h`,`1d`,`3d`,`1w`,`2w`, default `auto`) */
345
+ resolution?: number | string;
346
+ /** Sort order (default `desc`) */
347
+ order?: 'asc' | 'desc';
348
+ }
349
+
350
+ /**
351
+ * OHLCVT candle row: `[timestamp, open, high, low, close, baseVolume, quoteVolume, tradeCount]`
352
+ */
353
+ export type Candle = [number, string, string, string, string, string, string, number];
354
+
355
+ export interface TickerEntry {
356
+ /** Market symbol `BASE/QUOTE` */
357
+ symbol: string;
358
+ /** Opening price 24h ago */
359
+ openPrice: string;
360
+ /** Highest price in the 24h window */
361
+ highPrice: string;
362
+ /** Lowest price in the 24h window */
363
+ lowPrice: string;
364
+ /** Most recent trade price */
365
+ lastPrice: string;
366
+ /** 24h base asset volume */
367
+ volume: string;
368
+ /** 24h quote asset volume */
369
+ quoteVolume: string;
370
+ /** 24h price change (percent) */
371
+ change: number;
372
+ /** Volume-weighted average price */
373
+ avgPrice: string;
374
+ /** 24h trade count */
375
+ trades: number;
376
+ }
377
+
378
+ export interface Ticker24hResult {
379
+ /** Ledger sequence */
380
+ ledger: number;
381
+ /** UNIX timestamp (seconds) */
382
+ timestamp: number;
383
+ /** Per-market 24h stats, sorted by trade count descending */
384
+ ticker: TickerEntry[];
385
+ }
386
+
387
+ export interface MarketsParams {
388
+ /** Pagination cursor (`baseAsset-quoteAsset`) */
389
+ cursor?: string;
390
+ /** Max markets to return */
391
+ limit?: number | string;
392
+ }
393
+
394
+ export interface MarketInfo {
395
+ /** Base asset contract id */
396
+ baseAsset: string;
397
+ /** Quote asset contract id */
398
+ quoteAsset: string;
399
+ /** Pagination cursor for this market */
400
+ cursor: string;
401
+ /** Supported order types */
402
+ orderTypes: string[];
403
+ }
404
+
405
+ export interface OrdersParams {
406
+ /** Filter by order owner address */
407
+ owner?: string;
408
+ /** Filter by asset(s) - matches orders selling or buying any of them */
409
+ asset?: string | string[];
410
+ /** Pagination cursor (order id) */
411
+ cursor?: string | bigint;
412
+ /** Max orders to return */
413
+ limit?: number | string;
414
+ }
415
+
416
+ export interface OrderHistoryParams {
417
+ /** Filter by order owner address */
418
+ owner?: string;
419
+ /** Asset pair `[base, quote]` (contract ids) */
420
+ pair?: string[];
421
+ /** Pagination cursor (order id) */
422
+ cursor?: string | bigint;
423
+ /** Max orders to return */
424
+ limit?: number | string;
425
+ }
426
+
427
+ export interface TradesParams {
428
+ /** Filter by trader address */
429
+ trader?: string;
430
+ /** Asset pair `[base, quote]` (contract ids) */
431
+ pair?: string[];
432
+ /** Pagination cursor (trade id) */
433
+ cursor?: string | bigint;
434
+ /** Max trades to return */
435
+ limit?: number | string;
436
+ }
437
+
438
+ /**
439
+ * Serialized order returned by the API
440
+ */
441
+ export interface ApiOrder {
442
+ /** Order ID */
443
+ id: string;
444
+ /** Order status (`ACTIVE`|`FILLED`|`CANCELED`) */
445
+ status: string;
446
+ /** Order kind (`LIMIT`) */
447
+ kind: string;
448
+ /** Buying asset contract id */
449
+ buying: string;
450
+ /** Selling asset contract id */
451
+ selling: string;
452
+ /** Order price */
453
+ price: string;
454
+ /** Rational price representation */
455
+ rprice: string;
456
+ /** Total quote amount */
457
+ quote: string;
458
+ /** Amount left to sell/buy */
459
+ amount: string;
460
+ /** Maker address */
461
+ owner: string;
462
+ /** Expiration timestamp (UTC) */
463
+ expires?: string;
464
+ /** Iceberg amount */
465
+ iceberg?: string;
466
+ /** Stop price */
467
+ stop?: string;
468
+ /** Creation timestamp (UTC) */
469
+ created?: string;
470
+ /** Last update timestamp (UTC) */
471
+ updated?: string;
472
+ /** Pagination cursor */
473
+ cursor?: string;
474
+ }
475
+
476
+ /**
477
+ * Serialized trade returned by the API
478
+ */
479
+ export interface ApiTrade {
480
+ /** Trade ID */
481
+ id: string;
482
+ /** Matched order ID */
483
+ order: string;
484
+ /** Taker account address */
485
+ taker: string;
486
+ /** Maker account address */
487
+ maker: string;
488
+ /** Sold asset contract id */
489
+ soldAsset: string;
490
+ /** Bought asset contract id */
491
+ boughtAsset: string;
492
+ /** Sold tokens amount */
493
+ sold: string;
494
+ /** Bought tokens amount */
495
+ bought: string;
496
+ /** Approximate trade price */
497
+ price: string;
498
+ /** Pagination cursor */
499
+ cursor?: string;
500
+ /** Trade timestamp (UTC) */
501
+ timestamp: string;
502
+ }
503
+
504
+ /**
505
+ * HTTP client for the AXIS Aggregator REST API
506
+ */
507
+ export declare class ApiClient {
508
+ /**
509
+ * @param serverUrl - Base URL of the Aggregator server
510
+ */
511
+ constructor(serverUrl: string);
512
+
513
+ /** Base URL of the Aggregator server */
514
+ readonly serverUrl: string;
515
+
516
+ /**
517
+ * Price quote and candidate trade routes for selling a fixed amount of the source asset
518
+ * @param params - Quote request parameters
519
+ * @returns Best routes ranked by profitability
520
+ */
521
+ quoteSell(params: QuoteParams): Promise<QuoteResult>;
522
+
523
+ /**
524
+ * Price quote and candidate trade routes for buying a fixed amount of the destination asset
525
+ * @param params - Quote request parameters
526
+ * @returns Best routes ranked by profitability
527
+ */
528
+ quoteBuy(params: QuoteParams): Promise<QuoteResult>;
529
+
530
+ /**
531
+ * Order book depth aggregated into price buckets around the mid price
532
+ * @param params - Depth request parameters
533
+ * @returns Aggregated bids and asks
534
+ */
535
+ getDepth(params: DepthParams): Promise<OrderbookDepth>;
536
+
537
+ /**
538
+ * OHLCVT candlestick data (open, high, low, close, base volume, quote volume, trade count)
539
+ * @param params - Candles request parameters
540
+ * @returns Time-bucketed candles, max 200 per response
541
+ */
542
+ getCandles(params: CandlesParams): Promise<Candle[]>;
543
+
544
+ /**
545
+ * 24-hour ticker statistics for every available market
546
+ * @returns Aggregated 24h stats per market
547
+ */
548
+ getTicker24h(): Promise<Ticker24hResult>;
549
+
550
+ /**
551
+ * List all active markets with pagination
552
+ * @param params - Pagination parameters
553
+ * @returns Active markets
554
+ */
555
+ getMarkets(params?: MarketsParams): Promise<MarketInfo[]>;
556
+
557
+ /**
558
+ * Retrieve active orders, filterable by owner or asset
559
+ * @param params - Filter parameters
560
+ * @returns Active orders matching the filter
561
+ */
562
+ getOrders(params?: OrdersParams): Promise<ApiOrder[]>;
563
+
564
+ /**
565
+ * Retrieve a single order by ID
566
+ * @param id - Order ID
567
+ * @returns Order, or null if not found
568
+ */
569
+ getOrder(id: bigint | string | number): Promise<ApiOrder | null>;
570
+
571
+ /**
572
+ * Retrieve archived/historical orders
573
+ * @param params - Filter parameters
574
+ * @returns Archived orders matching the filter
575
+ */
576
+ getOrderHistory(params?: OrderHistoryParams): Promise<ApiOrder[]>;
577
+
578
+ /**
579
+ * Retrieve recent trades
580
+ * @param params - Filter parameters
581
+ * @returns Recent trades matching the filter
582
+ */
583
+ getTrades(params?: TradesParams): Promise<ApiTrade[]>;
584
+ }