@nadohq/engine-client 0.1.0-alpha.5 → 0.1.0-alpha.50

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.
Files changed (78) hide show
  1. package/dist/EngineBaseClient.d.cts +1 -1
  2. package/dist/EngineBaseClient.d.ts +1 -1
  3. package/dist/EngineExecuteBuilder.cjs +9 -6
  4. package/dist/EngineExecuteBuilder.cjs.map +1 -1
  5. package/dist/EngineExecuteBuilder.js +9 -6
  6. package/dist/EngineExecuteBuilder.js.map +1 -1
  7. package/dist/EngineExecuteClient.cjs +6 -6
  8. package/dist/EngineExecuteClient.cjs.map +1 -1
  9. package/dist/EngineExecuteClient.d.cts +1 -1
  10. package/dist/EngineExecuteClient.d.ts +1 -1
  11. package/dist/EngineExecuteClient.js +6 -6
  12. package/dist/EngineExecuteClient.js.map +1 -1
  13. package/dist/EngineQueryClient.cjs +48 -4
  14. package/dist/EngineQueryClient.cjs.map +1 -1
  15. package/dist/EngineQueryClient.d.cts +18 -2
  16. package/dist/EngineQueryClient.d.ts +18 -2
  17. package/dist/EngineQueryClient.js +50 -4
  18. package/dist/EngineQueryClient.js.map +1 -1
  19. package/dist/endpoints.cjs +6 -6
  20. package/dist/endpoints.cjs.map +1 -1
  21. package/dist/endpoints.js +6 -6
  22. package/dist/endpoints.js.map +1 -1
  23. package/dist/index.cjs +4 -4
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +9 -9
  26. package/dist/index.d.ts +9 -9
  27. package/dist/index.js +2 -2
  28. package/dist/index.js.map +1 -1
  29. package/dist/types/clientExecuteTypes.cjs.map +1 -1
  30. package/dist/types/clientExecuteTypes.d.cts +8 -1
  31. package/dist/types/clientExecuteTypes.d.ts +8 -1
  32. package/dist/types/clientQueryTypes.cjs.map +1 -1
  33. package/dist/types/clientQueryTypes.d.cts +37 -5
  34. package/dist/types/clientQueryTypes.d.ts +37 -5
  35. package/dist/types/index.cjs +10 -10
  36. package/dist/types/index.cjs.map +1 -1
  37. package/dist/types/index.d.cts +6 -6
  38. package/dist/types/index.d.ts +6 -6
  39. package/dist/types/index.js +5 -5
  40. package/dist/types/index.js.map +1 -1
  41. package/dist/types/serverExecuteTypes.cjs.map +1 -1
  42. package/dist/types/serverExecuteTypes.d.cts +8 -1
  43. package/dist/types/serverExecuteTypes.d.ts +8 -1
  44. package/dist/types/serverQueryModelTypes.cjs.map +1 -1
  45. package/dist/types/serverQueryModelTypes.d.cts +24 -1
  46. package/dist/types/serverQueryModelTypes.d.ts +24 -1
  47. package/dist/types/serverQueryTypes.cjs.map +1 -1
  48. package/dist/types/serverQueryTypes.d.cts +47 -22
  49. package/dist/types/serverQueryTypes.d.ts +47 -22
  50. package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -1
  51. package/dist/types/serverSubscriptionEventTypes.d.cts +86 -22
  52. package/dist/types/serverSubscriptionEventTypes.d.ts +86 -22
  53. package/dist/types/serverSubscriptionTypes.cjs.map +1 -1
  54. package/dist/types/serverSubscriptionTypes.d.cts +21 -4
  55. package/dist/types/serverSubscriptionTypes.d.ts +21 -4
  56. package/dist/utils/index.d.cts +2 -2
  57. package/dist/utils/index.d.ts +2 -2
  58. package/dist/utils/queryDataMappers.cjs +66 -19
  59. package/dist/utils/queryDataMappers.cjs.map +1 -1
  60. package/dist/utils/queryDataMappers.d.cts +7 -5
  61. package/dist/utils/queryDataMappers.d.ts +7 -5
  62. package/dist/utils/queryDataMappers.js +64 -19
  63. package/dist/utils/queryDataMappers.js.map +1 -1
  64. package/package.json +8 -4
  65. package/src/EngineExecuteBuilder.ts +9 -6
  66. package/src/EngineExecuteClient.ts +7 -7
  67. package/src/EngineQueryClient.ts +63 -1
  68. package/src/endpoints.ts +6 -6
  69. package/src/index.ts +2 -2
  70. package/src/types/clientExecuteTypes.ts +9 -2
  71. package/src/types/clientQueryTypes.ts +48 -4
  72. package/src/types/index.ts +5 -5
  73. package/src/types/serverExecuteTypes.ts +9 -2
  74. package/src/types/serverQueryModelTypes.ts +25 -0
  75. package/src/types/serverQueryTypes.ts +64 -25
  76. package/src/types/serverSubscriptionEventTypes.ts +122 -21
  77. package/src/types/serverSubscriptionTypes.ts +23 -3
  78. package/src/utils/queryDataMappers.ts +85 -20
@@ -1,6 +1,9 @@
1
1
  import { HealthStatus } from '@nadohq/shared';
2
2
  import {
3
3
  EngineServerHealthBreakdown,
4
+ EngineServerNlpBalance,
5
+ EngineServerNlpLockedBalance,
6
+ EngineServerOrder,
4
7
  EngineServerPerpBalance,
5
8
  EngineServerPerpProduct,
6
9
  EngineServerProductType,
@@ -22,6 +25,8 @@ export interface EngineServerSubaccountInfoQueryParams {
22
25
  v_quote_delta: string;
23
26
  };
24
27
  }>;
28
+ // If not given, engine defaults to 'false'
29
+ pre_state?: string;
25
30
  }
26
31
 
27
32
  export interface EngineServerIsolatedPositionsQueryParams {
@@ -89,6 +94,10 @@ export interface EngineServerMaxOrderSizeQueryParams {
89
94
  // If not given, engine defaults to false. If true, the max order size will be capped to the subaccount's current position size;
90
95
  // If no position exists, it will return 0.
91
96
  reduce_only: string | null;
97
+ isolated: string | null;
98
+ // For isolated, max order size includes available collateral to transfer from parent cross subaccount
99
+ // If not given, engine defaults to true (borrow enabled)
100
+ borrow_margin: string | null;
92
101
  }
93
102
 
94
103
  export interface EngineServerLinkedSignerParams {
@@ -101,6 +110,14 @@ export interface EngineServerMaxMintNlpQueryParams {
101
110
  spot_leverage: string | null;
102
111
  }
103
112
 
113
+ export interface EngineServerMaxBurnNlpQueryParams {
114
+ sender: string;
115
+ }
116
+
117
+ export interface EngineServerNlpLockedBalancesQueryParams {
118
+ subaccount: string;
119
+ }
120
+
104
121
  export interface EngineServerQueryRequestByType {
105
122
  all_products: Record<string, never>;
106
123
  contracts: Record<string, never>;
@@ -113,8 +130,11 @@ export interface EngineServerQueryRequestByType {
113
130
  market_liquidity: EngineServerMarketLiquidityQueryParams;
114
131
  market_price: EngineServerMarketPriceQueryParams;
115
132
  market_prices: EngineServerMarketPricesQueryParams;
133
+ max_nlp_burnable: EngineServerMaxBurnNlpQueryParams;
116
134
  max_nlp_mintable: EngineServerMaxMintNlpQueryParams;
117
135
  max_order_size: EngineServerMaxOrderSizeQueryParams;
136
+ nlp_locked_balances: EngineServerNlpLockedBalancesQueryParams;
137
+ nlp_pool_info: Record<string, never>;
118
138
  max_withdrawable: EngineServerMaxWithdrawableQueryParams;
119
139
  nonces: EngineServerNoncesParams;
120
140
  order: EngineServerGetOrderQueryParams;
@@ -156,9 +176,19 @@ export interface EngineServerNoncesResponse {
156
176
  tx_nonce: string;
157
177
  }
158
178
 
159
- export interface EngineServerSubaccountInfoResponse {
179
+ export interface EngineServerSubaccountInfoResponse extends EngineServerSubaccountInfoState {
160
180
  exists: boolean;
161
181
  subaccount: string;
182
+ spot_count: number;
183
+ perp_count: number;
184
+ spot_products: EngineServerSpotProduct[];
185
+ perp_products: EngineServerPerpProduct[];
186
+
187
+ /** This is set if request has `pre_state` flag set to 'true' */
188
+ pre_state: EngineServerSubaccountInfoState | undefined;
189
+ }
190
+
191
+ export interface EngineServerSubaccountInfoState {
162
192
  healths: [
163
193
  initial: EngineServerHealthBreakdown,
164
194
  maintenance: EngineServerHealthBreakdown,
@@ -166,12 +196,8 @@ export interface EngineServerSubaccountInfoResponse {
166
196
  ];
167
197
  // First index is product ID, each subarray is of length 3 [initial, maintenance, unweighted]
168
198
  health_contributions: string[][];
169
- spot_count: number;
170
- perp_count: number;
171
199
  spot_balances: EngineServerSpotBalance[];
172
200
  perp_balances: EngineServerPerpBalance[];
173
- spot_products: EngineServerSpotProduct[];
174
- perp_products: EngineServerPerpProduct[];
175
201
  }
176
202
 
177
203
  export interface EngineServerIsolatedPosition {
@@ -200,12 +226,12 @@ export interface EngineServerSymbol {
200
226
  price_increment_x18: string;
201
227
  size_increment: string;
202
228
  min_size: string;
203
- min_depth_x18: string;
204
- max_spread_rate_x18: string;
205
229
  maker_fee_rate_x18: string;
206
230
  taker_fee_rate_x18: string;
207
231
  long_weight_initial_x18: string;
208
232
  long_weight_maintenance_x18: string;
233
+ // undefined when there is no max open interest limit (always undefined for spot products)
234
+ max_open_interest_x18: string | undefined;
209
235
  }
210
236
 
211
237
  export interface EngineServerSymbolsResponse {
@@ -253,6 +279,7 @@ export interface EngineServerFeeRatesResponse {
253
279
  withdraw_sequencer_fees: string[];
254
280
  taker_fee_rates_x18: string[];
255
281
  maker_fee_rates_x18: string[];
282
+ fee_tier: number;
256
283
  }
257
284
 
258
285
  export interface EngineServerMarketPrice {
@@ -267,20 +294,6 @@ export interface EngineServerMarketPricesResponse {
267
294
  market_prices: EngineServerMarketPrice[];
268
295
  }
269
296
 
270
- export interface EngineServerOrder {
271
- product_id: number;
272
- sender: string;
273
- price_x18: string;
274
- amount: string;
275
- expiration: string;
276
- nonce: string;
277
- unfilled_amount: string;
278
- digest: string;
279
- placed_at: number;
280
- order_type: string;
281
- appendix: string;
282
- }
283
-
284
297
  export type EngineServerOrderResponse = EngineServerOrder;
285
298
 
286
299
  export interface EngineServerValidateOrderResponse {
@@ -317,10 +330,33 @@ export interface EngineServerEdgeAllProductsResponse {
317
330
  edge_all_products: Record<number, EngineServerAllProductsResponse>;
318
331
  }
319
332
 
333
+ export interface EngineServerMaxBurnNlpResponse {
334
+ max_nlp_amount: string;
335
+ }
336
+
320
337
  export interface EngineServerMaxMintNlpResponse {
321
338
  max_quote_amount: string;
322
339
  }
323
340
 
341
+ export interface EngineServerNlpLockedBalancesResponse {
342
+ balance_locked: EngineServerNlpBalance;
343
+ balance_unlocked: EngineServerNlpBalance;
344
+ locked_balances: EngineServerNlpLockedBalance[];
345
+ }
346
+
347
+ export interface EngineServerNlpPool {
348
+ pool_id: number;
349
+ subaccount: string;
350
+ owner: string;
351
+ balance_weight_x18: string;
352
+ subaccount_info: EngineServerSubaccountInfoResponse;
353
+ open_orders: EngineServerOrder[];
354
+ }
355
+
356
+ export interface EngineServerNlpPoolInfoResponse {
357
+ nlp_pools: EngineServerNlpPool[];
358
+ }
359
+
324
360
  export interface EngineServerQueryResponseByType {
325
361
  all_products: EngineServerAllProductsResponse;
326
362
  contracts: EngineServerContractsResponse;
@@ -333,8 +369,11 @@ export interface EngineServerQueryResponseByType {
333
369
  market_liquidity: EngineServerMarketLiquidityResponse;
334
370
  market_price: EngineServerMarketPriceResponse;
335
371
  market_prices: EngineServerMarketPricesResponse;
372
+ max_nlp_burnable: EngineServerMaxBurnNlpResponse;
336
373
  max_nlp_mintable: EngineServerMaxMintNlpResponse;
337
374
  max_order_size: EngineServerMaxOrderSizeResponse;
375
+ nlp_locked_balances: EngineServerNlpLockedBalancesResponse;
376
+ nlp_pool_info: EngineServerNlpPoolInfoResponse;
338
377
  max_withdrawable: EngineServerMaxWithdrawableResponse;
339
378
  nonces: EngineServerNoncesResponse;
340
379
  order: EngineServerOrderResponse;
@@ -347,8 +386,8 @@ export interface EngineServerQueryResponseByType {
347
386
  }
348
387
 
349
388
  export interface EngineServerQuerySuccessResponse<
350
- TQueryType extends
351
- keyof EngineServerQueryResponseByType = EngineServerQueryRequestType,
389
+ TQueryType extends keyof EngineServerQueryResponseByType =
390
+ EngineServerQueryRequestType,
352
391
  > {
353
392
  status: 'success';
354
393
  data: EngineServerQueryResponseByType[TQueryType];
@@ -361,8 +400,8 @@ export interface EngineServerQueryFailureResponse {
361
400
  }
362
401
 
363
402
  export type EngineServerQueryResponse<
364
- TQueryType extends
365
- keyof EngineServerQueryResponseByType = EngineServerQueryRequestType,
403
+ TQueryType extends keyof EngineServerQueryResponseByType =
404
+ EngineServerQueryRequestType,
366
405
  > =
367
406
  | EngineServerQuerySuccessResponse<TQueryType>
368
407
  | EngineServerQueryFailureResponse;
@@ -1,22 +1,47 @@
1
1
  import { EngineServerPriceTickLiquidity } from './serverQueryTypes';
2
2
 
3
3
  /**
4
- * Event from subscribing to a `order_update` stream.
4
+ * Reasons that can trigger position change events.
5
5
  */
6
- export interface EngineServerSubscriptionOrderUpdateEvent {
7
- timestamp: string;
6
+ export type PositionChangeReason =
7
+ | 'deposit_collateral'
8
+ | 'match_orders'
9
+ | 'withdraw_collateral'
10
+ | 'transfer_quote'
11
+ | 'settle_pnl'
12
+ | 'mint_nlp'
13
+ | 'burn_nlp'
14
+ | 'liquidate_subaccount';
15
+
16
+ /**
17
+ * Possible reasons for order updates.
18
+ */
19
+ export type OrderUpdateReason = 'cancelled' | 'filled' | 'placed';
20
+
21
+ export type EngineServerSubscriptionEventType =
22
+ | 'trade'
23
+ | 'best_bid_offer'
24
+ | 'book_depth'
25
+ | 'fill'
26
+ | 'position_change'
27
+ | 'order_update'
28
+ | 'liquidation'
29
+ | 'latest_candlestick'
30
+ | 'funding_payment';
31
+
32
+ export interface EngineServerSubscriptionBaseEvent<
33
+ T extends EngineServerSubscriptionEventType =
34
+ EngineServerSubscriptionEventType,
35
+ > {
36
+ type: T;
8
37
  product_id: number;
9
- digest: string;
10
- amount: string;
11
- reason: string;
12
38
  }
13
39
 
14
40
  /**
15
41
  * Event from subscribing to a `trade` stream.
16
42
  */
17
- export interface EngineServerSubscriptionTradeEvent {
43
+ export interface EngineServerSubscriptionTradeEvent extends EngineServerSubscriptionBaseEvent<'trade'> {
18
44
  timestamp: string;
19
- product_id: number;
20
45
  price: string;
21
46
  taker_qty: string;
22
47
  maker_qty: string;
@@ -26,49 +51,125 @@ export interface EngineServerSubscriptionTradeEvent {
26
51
  /**
27
52
  * Event from subscribing to a `best_bid_offer` stream.
28
53
  */
29
- export interface EngineServerSubscriptionBestBidOfferEvent {
54
+ export interface EngineServerSubscriptionBestBidOfferEvent extends EngineServerSubscriptionBaseEvent<'best_bid_offer'> {
30
55
  timestamp: string;
31
- product_id: number;
32
56
  bid_price: string;
33
57
  bid_qty: string;
34
58
  ask_price: string;
35
59
  ask_qty: string;
36
60
  }
37
61
 
62
+ /**
63
+ * Event from subscribing to a `book_depth` stream.
64
+ */
65
+ export interface EngineServerSubscriptionBookDepthEvent extends EngineServerSubscriptionBaseEvent<'book_depth'> {
66
+ last_max_timestamp: string;
67
+ min_timestamp: string;
68
+ max_timestamp: string;
69
+ bids: EngineServerPriceTickLiquidity[];
70
+ asks: EngineServerPriceTickLiquidity[];
71
+ }
72
+
38
73
  /**
39
74
  * Event from subscribing to a `fill` stream.
40
75
  */
41
- export interface EngineServerSubscriptionFillEvent {
76
+ export interface EngineServerSubscriptionFillEvent extends EngineServerSubscriptionBaseEvent<'fill'> {
42
77
  // NOTE: `id` is excluded from the response to avoid parsing issues.
43
78
  // type of `id` on the backend is `u64` which can overflow until we introduce proper parsing on the SDK.
44
79
  timestamp: string;
45
- product_id: number;
46
80
  subaccount: string;
47
81
  order_digest: string;
48
82
  filled_qty: string;
49
83
  remaining_qty: string;
84
+ original_qty: string;
50
85
  price: string;
51
86
  is_taker: boolean;
87
+ is_bid: boolean;
88
+ fee: string;
89
+ submission_idx: string;
90
+ appendix: string;
52
91
  }
53
92
 
54
93
  /**
55
94
  * Event from subscribing to a `position_change` stream.
56
95
  */
57
- export interface EngineServerSubscriptionPositionChangeEvent {
96
+ export interface EngineServerSubscriptionPositionChangeEvent extends EngineServerSubscriptionBaseEvent<'position_change'> {
58
97
  timestamp: string;
59
- product_id: number;
60
98
  subaccount: string;
61
99
  amount: string;
100
+ /** Zero for everything except perps */
62
101
  v_quote_amount: string;
102
+ reason: PositionChangeReason;
103
+ /**
104
+ * True if the position change was for an isolated position
105
+ */
106
+ isolated: boolean;
63
107
  }
64
108
 
65
109
  /**
66
- * Event from subscribing to a `book_depth` stream.
110
+ * Event from subscribing to an `order_update` stream.
67
111
  */
68
- export interface EngineServerSubscriptionBookDepthEvent {
69
- min_timestamp: string;
70
- max_timestamp: string;
71
- product_id: number;
72
- bids: EngineServerPriceTickLiquidity[];
73
- asks: EngineServerPriceTickLiquidity[];
112
+ export interface EngineServerSubscriptionOrderUpdateEvent extends EngineServerSubscriptionBaseEvent<'order_update'> {
113
+ timestamp: string;
114
+ digest: string;
115
+ amount: string;
116
+ reason: OrderUpdateReason;
74
117
  }
118
+
119
+ /**
120
+ * Event from subscribing to a `liquidation` stream.
121
+ */
122
+ export interface EngineServerSubscriptionLiquidationEvent extends EngineServerSubscriptionBaseEvent<'liquidation'> {
123
+ timestamp: string;
124
+ /** Single element for regular liquidations, two elements for spread liquidations [spotId, perpId] */
125
+ product_ids: number[];
126
+ liquidator: string;
127
+ liquidatee: string;
128
+ /** Amount liquidated (positive for long, negative for short) */
129
+ amount: string;
130
+ /** Price at which liquidation occurred */
131
+ price: string;
132
+ }
133
+
134
+ /**
135
+ * Event from subscribing to a `latest_candlestick` stream.
136
+ */
137
+ export interface EngineServerSubscriptionLatestCandlestickEvent extends EngineServerSubscriptionBaseEvent<'latest_candlestick'> {
138
+ timestamp: string;
139
+ granularity: number;
140
+ open_x18: string;
141
+ high_x18: string;
142
+ low_x18: string;
143
+ close_x18: string;
144
+ volume: string;
145
+ }
146
+
147
+ /**
148
+ * Event from subscribing to a `funding_payment` stream.
149
+ */
150
+ export interface EngineServerSubscriptionFundingPaymentEvent extends EngineServerSubscriptionBaseEvent<'funding_payment'> {
151
+ timestamp: string;
152
+ /** Funding payment amount (positive = receive, negative = pay) */
153
+ payment_amount: string;
154
+ /** Open interest at time of funding */
155
+ open_interest: string;
156
+ /** Current cumulative funding values */
157
+ cumulative_funding_long_x18: string;
158
+ cumulative_funding_short_x18: string;
159
+ /** Time delta over which the funding payment was calculated */
160
+ dt: string;
161
+ }
162
+
163
+ /**
164
+ * Union type for all engine server subscription events.
165
+ */
166
+ export type EngineServerSubscriptionEvent =
167
+ | EngineServerSubscriptionTradeEvent
168
+ | EngineServerSubscriptionBestBidOfferEvent
169
+ | EngineServerSubscriptionBookDepthEvent
170
+ | EngineServerSubscriptionFillEvent
171
+ | EngineServerSubscriptionPositionChangeEvent
172
+ | EngineServerSubscriptionOrderUpdateEvent
173
+ | EngineServerSubscriptionLiquidationEvent
174
+ | EngineServerSubscriptionLatestCandlestickEvent
175
+ | EngineServerSubscriptionFundingPaymentEvent;
@@ -1,5 +1,6 @@
1
1
  export interface EngineServerOrderUpdateStreamParams {
2
- product_id: number;
2
+ /** when not provided, subscribes to all products */
3
+ product_id?: number;
3
4
  subaccount: string;
4
5
  }
5
6
 
@@ -12,12 +13,14 @@ export interface EngineServerBestBidOfferStreamParams {
12
13
  }
13
14
 
14
15
  export interface EngineServerFillStreamParams {
15
- product_id: number;
16
+ /** when not provided, subscribes to all products */
17
+ product_id?: number;
16
18
  subaccount: string;
17
19
  }
18
20
 
19
21
  export interface EngineServerPositionChangeStreamParams {
20
- product_id: number;
22
+ /** when not provided, subscribes to all products */
23
+ product_id?: number;
21
24
  subaccount: string;
22
25
  }
23
26
 
@@ -25,6 +28,20 @@ export interface EngineServerBookDepthStreamParams {
25
28
  product_id: number;
26
29
  }
27
30
 
31
+ export interface EngineServerLatestCandlestickStreamParams {
32
+ product_id: number;
33
+ granularity: number;
34
+ }
35
+
36
+ export interface EngineServerLiquidationStreamParams {
37
+ /** when not provided, subscribes to all products */
38
+ product_id?: number;
39
+ }
40
+
41
+ export interface EngineServerFundingPaymentStreamParams {
42
+ product_id: number;
43
+ }
44
+
28
45
  /**
29
46
  * Available subscription streams
30
47
  */
@@ -35,6 +52,9 @@ export interface EngineServerSubscriptionStreamParamsByType {
35
52
  fill: EngineServerFillStreamParams;
36
53
  position_change: EngineServerPositionChangeStreamParams;
37
54
  book_depth: EngineServerBookDepthStreamParams;
55
+ liquidation: EngineServerLiquidationStreamParams;
56
+ latest_candlestick: EngineServerLatestCandlestickStreamParams;
57
+ funding_payment: EngineServerFundingPaymentStreamParams;
38
58
  }
39
59
 
40
60
  export type EngineServerSubscriptionStreamParamsType =
@@ -13,21 +13,28 @@ import {
13
13
  } from '@nadohq/shared';
14
14
  import {
15
15
  EngineMarketPrice,
16
+ EngineNlpLockedBalance,
16
17
  EngineOrder,
17
18
  EnginePriceTickLiquidity,
18
19
  EngineServerIsolatedPositionsResponse,
19
20
  EngineServerMarketPrice,
21
+ EngineServerNlpLockedBalancesResponse,
22
+ EngineServerNlpPoolInfoResponse,
20
23
  EngineServerOrderResponse,
21
24
  EngineServerPerpProduct,
22
25
  EngineServerPriceTickLiquidity,
23
26
  EngineServerSpotProduct,
24
27
  EngineServerSubaccountInfoResponse,
28
+ EngineServerSubaccountInfoState,
25
29
  EngineServerSymbol,
26
30
  EngineServerSymbolsResponse,
27
31
  EngineSymbol,
28
32
  EngineSymbolsResponse,
29
33
  GetEngineIsolatedPositionsResponse,
34
+ GetEngineNlpLockedBalancesResponse,
35
+ GetEngineNlpPoolInfoResponse,
30
36
  GetEngineSubaccountSummaryResponse,
37
+ SubaccountSummaryState,
31
38
  } from '../types';
32
39
  import { mapEngineServerProductType } from './productEngineTypeMappers';
33
40
 
@@ -145,10 +152,32 @@ export function mapEngineServerBalanceHealthContributions(
145
152
  export function mapSubaccountSummary(
146
153
  baseResponse: EngineServerSubaccountInfoResponse,
147
154
  ): GetEngineSubaccountSummaryResponse {
148
- const balances: GetEngineSubaccountSummaryResponse['balances'] = [];
155
+ return {
156
+ exists: baseResponse.exists,
157
+ ...mapSubaccountSummaryState(
158
+ baseResponse,
159
+ baseResponse.spot_products,
160
+ baseResponse.perp_products,
161
+ ),
162
+ preState: baseResponse.pre_state
163
+ ? mapSubaccountSummaryState(
164
+ baseResponse.pre_state,
165
+ baseResponse.spot_products,
166
+ baseResponse.perp_products,
167
+ )
168
+ : undefined,
169
+ };
170
+ }
149
171
 
150
- baseResponse.spot_balances.forEach((spotBalance) => {
151
- const product = baseResponse.spot_products.find(
172
+ function mapSubaccountSummaryState(
173
+ state: EngineServerSubaccountInfoState,
174
+ spotProducts: EngineServerSubaccountInfoResponse['spot_products'],
175
+ perpProducts: EngineServerSubaccountInfoResponse['perp_products'],
176
+ ): SubaccountSummaryState {
177
+ const balances: SubaccountSummaryState['balances'] = [];
178
+
179
+ state.spot_balances.forEach((spotBalance) => {
180
+ const product = spotProducts.find(
152
181
  (product) => product.product_id === spotBalance.product_id,
153
182
  );
154
183
  if (!product) {
@@ -158,14 +187,14 @@ export function mapSubaccountSummary(
158
187
  balances.push({
159
188
  amount: toBigDecimal(spotBalance.balance.amount),
160
189
  healthContributions: mapEngineServerBalanceHealthContributions(
161
- baseResponse.health_contributions[spotBalance.product_id],
190
+ state.health_contributions[spotBalance.product_id],
162
191
  ),
163
192
  ...mapEngineServerSpotProduct(product).product,
164
193
  });
165
194
  });
166
195
 
167
- baseResponse.perp_balances.forEach((perpBalance) => {
168
- const product = baseResponse.perp_products.find(
196
+ state.perp_balances.forEach((perpBalance) => {
197
+ const product = perpProducts.find(
169
198
  (product) => product.product_id === perpBalance.product_id,
170
199
  );
171
200
  if (!product) {
@@ -176,30 +205,29 @@ export function mapSubaccountSummary(
176
205
  amount: toBigDecimal(perpBalance.balance.amount),
177
206
  vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),
178
207
  healthContributions: mapEngineServerBalanceHealthContributions(
179
- baseResponse.health_contributions[perpBalance.product_id],
208
+ state.health_contributions[perpBalance.product_id],
180
209
  ),
181
210
  ...mapEngineServerPerpProduct(product).product,
182
211
  });
183
212
  });
184
213
 
185
214
  return {
186
- balances: balances,
187
- exists: baseResponse.exists,
215
+ balances,
188
216
  health: {
189
217
  initial: {
190
- health: toBigDecimal(baseResponse.healths[0].health),
191
- assets: toBigDecimal(baseResponse.healths[0].assets),
192
- liabilities: toBigDecimal(baseResponse.healths[0].liabilities),
218
+ health: toBigDecimal(state.healths[0].health),
219
+ assets: toBigDecimal(state.healths[0].assets),
220
+ liabilities: toBigDecimal(state.healths[0].liabilities),
193
221
  },
194
222
  maintenance: {
195
- health: toBigDecimal(baseResponse.healths[1].health),
196
- assets: toBigDecimal(baseResponse.healths[1].assets),
197
- liabilities: toBigDecimal(baseResponse.healths[1].liabilities),
223
+ health: toBigDecimal(state.healths[1].health),
224
+ assets: toBigDecimal(state.healths[1].assets),
225
+ liabilities: toBigDecimal(state.healths[1].liabilities),
198
226
  },
199
227
  unweighted: {
200
- health: toBigDecimal(baseResponse.healths[2].health),
201
- assets: toBigDecimal(baseResponse.healths[2].assets),
202
- liabilities: toBigDecimal(baseResponse.healths[2].liabilities),
228
+ health: toBigDecimal(state.healths[2].health),
229
+ assets: toBigDecimal(state.healths[2].assets),
230
+ liabilities: toBigDecimal(state.healths[2].liabilities),
203
231
  },
204
232
  },
205
233
  };
@@ -266,8 +294,6 @@ export function mapEngineServerSymbol(
266
294
  priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),
267
295
  sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),
268
296
  minSize: toBigDecimal(engineServerSymbol.min_size),
269
- minDepth: removeDecimals(engineServerSymbol.min_depth_x18),
270
- maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),
271
297
  makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),
272
298
  takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),
273
299
  longWeightInitial: removeDecimals(
@@ -276,6 +302,7 @@ export function mapEngineServerSymbol(
276
302
  longWeightMaintenance: removeDecimals(
277
303
  engineServerSymbol.long_weight_maintenance_x18,
278
304
  ),
305
+ maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18),
279
306
  };
280
307
  }
281
308
 
@@ -288,3 +315,41 @@ export function mapEngineMarketPrice(
288
315
  productId: baseResponse.product_id,
289
316
  };
290
317
  }
318
+
319
+ export function mapEngineServerNlpLockedBalances(
320
+ baseResponse: EngineServerNlpLockedBalancesResponse,
321
+ ): GetEngineNlpLockedBalancesResponse {
322
+ const lockedBalances: EngineNlpLockedBalance[] =
323
+ baseResponse.locked_balances.map((lockedBalance) => ({
324
+ productId: lockedBalance.balance.product_id,
325
+ balance: toBigDecimal(lockedBalance.balance.balance.amount),
326
+ unlockedAt: lockedBalance.unlocked_at,
327
+ }));
328
+
329
+ return {
330
+ lockedBalances,
331
+ balanceLocked: {
332
+ productId: baseResponse.balance_locked.product_id,
333
+ balance: toBigDecimal(baseResponse.balance_locked.balance.amount),
334
+ },
335
+ balanceUnlocked: {
336
+ productId: baseResponse.balance_unlocked.product_id,
337
+ balance: toBigDecimal(baseResponse.balance_unlocked.balance.amount),
338
+ },
339
+ };
340
+ }
341
+
342
+ export function mapEngineServerNlpPoolInfo(
343
+ baseResponse: EngineServerNlpPoolInfoResponse,
344
+ ): GetEngineNlpPoolInfoResponse {
345
+ return {
346
+ nlpPools: baseResponse.nlp_pools.map((pool) => ({
347
+ poolId: pool.pool_id,
348
+ subaccountHex: pool.subaccount,
349
+ ownerAddress: pool.owner,
350
+ balanceWeight: removeDecimals(pool.balance_weight_x18),
351
+ subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
352
+ openOrders: pool.open_orders.map(mapEngineServerOrder),
353
+ })),
354
+ };
355
+ }