@nadohq/engine-client 0.1.0-alpha.4 → 0.1.0-alpha.40

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 (83) 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/EngineServerFailureError.cjs +1 -1
  30. package/dist/types/EngineServerFailureError.cjs.map +1 -1
  31. package/dist/types/EngineServerFailureError.js +1 -1
  32. package/dist/types/EngineServerFailureError.js.map +1 -1
  33. package/dist/types/clientExecuteTypes.cjs.map +1 -1
  34. package/dist/types/clientExecuteTypes.d.cts +8 -1
  35. package/dist/types/clientExecuteTypes.d.ts +8 -1
  36. package/dist/types/clientQueryTypes.cjs.map +1 -1
  37. package/dist/types/clientQueryTypes.d.cts +37 -5
  38. package/dist/types/clientQueryTypes.d.ts +37 -5
  39. package/dist/types/index.cjs +10 -10
  40. package/dist/types/index.cjs.map +1 -1
  41. package/dist/types/index.d.cts +6 -6
  42. package/dist/types/index.d.ts +6 -6
  43. package/dist/types/index.js +5 -5
  44. package/dist/types/index.js.map +1 -1
  45. package/dist/types/serverExecuteTypes.cjs.map +1 -1
  46. package/dist/types/serverExecuteTypes.d.cts +8 -1
  47. package/dist/types/serverExecuteTypes.d.ts +8 -1
  48. package/dist/types/serverQueryModelTypes.cjs.map +1 -1
  49. package/dist/types/serverQueryModelTypes.d.cts +24 -1
  50. package/dist/types/serverQueryModelTypes.d.ts +24 -1
  51. package/dist/types/serverQueryTypes.cjs.map +1 -1
  52. package/dist/types/serverQueryTypes.d.cts +47 -22
  53. package/dist/types/serverQueryTypes.d.ts +47 -22
  54. package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -1
  55. package/dist/types/serverSubscriptionEventTypes.d.cts +86 -22
  56. package/dist/types/serverSubscriptionEventTypes.d.ts +86 -22
  57. package/dist/types/serverSubscriptionTypes.cjs.map +1 -1
  58. package/dist/types/serverSubscriptionTypes.d.cts +21 -4
  59. package/dist/types/serverSubscriptionTypes.d.ts +21 -4
  60. package/dist/utils/index.d.cts +2 -2
  61. package/dist/utils/index.d.ts +2 -2
  62. package/dist/utils/queryDataMappers.cjs +66 -19
  63. package/dist/utils/queryDataMappers.cjs.map +1 -1
  64. package/dist/utils/queryDataMappers.d.cts +5 -3
  65. package/dist/utils/queryDataMappers.d.ts +5 -3
  66. package/dist/utils/queryDataMappers.js +64 -19
  67. package/dist/utils/queryDataMappers.js.map +1 -1
  68. package/package.json +7 -3
  69. package/src/EngineExecuteBuilder.ts +9 -6
  70. package/src/EngineExecuteClient.ts +7 -7
  71. package/src/EngineQueryClient.ts +63 -1
  72. package/src/endpoints.ts +6 -6
  73. package/src/index.ts +2 -2
  74. package/src/types/EngineServerFailureError.ts +1 -1
  75. package/src/types/clientExecuteTypes.ts +9 -2
  76. package/src/types/clientQueryTypes.ts +49 -4
  77. package/src/types/index.ts +5 -5
  78. package/src/types/serverExecuteTypes.ts +9 -2
  79. package/src/types/serverQueryModelTypes.ts +25 -0
  80. package/src/types/serverQueryTypes.ts +61 -21
  81. package/src/types/serverSubscriptionEventTypes.ts +131 -21
  82. package/src/types/serverSubscriptionTypes.ts +23 -3
  83. 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,20 @@ export interface EngineServerNoncesResponse {
156
176
  tx_nonce: string;
157
177
  }
158
178
 
159
- export interface EngineServerSubaccountInfoResponse {
179
+ export interface EngineServerSubaccountInfoResponse
180
+ extends EngineServerSubaccountInfoState {
160
181
  exists: boolean;
161
182
  subaccount: string;
183
+ spot_count: number;
184
+ perp_count: number;
185
+ spot_products: EngineServerSpotProduct[];
186
+ perp_products: EngineServerPerpProduct[];
187
+
188
+ /** This is set if request has `pre_state` flag set to 'true' */
189
+ pre_state: EngineServerSubaccountInfoState | undefined;
190
+ }
191
+
192
+ export interface EngineServerSubaccountInfoState {
162
193
  healths: [
163
194
  initial: EngineServerHealthBreakdown,
164
195
  maintenance: EngineServerHealthBreakdown,
@@ -166,12 +197,8 @@ export interface EngineServerSubaccountInfoResponse {
166
197
  ];
167
198
  // First index is product ID, each subarray is of length 3 [initial, maintenance, unweighted]
168
199
  health_contributions: string[][];
169
- spot_count: number;
170
- perp_count: number;
171
200
  spot_balances: EngineServerSpotBalance[];
172
201
  perp_balances: EngineServerPerpBalance[];
173
- spot_products: EngineServerSpotProduct[];
174
- perp_products: EngineServerPerpProduct[];
175
202
  }
176
203
 
177
204
  export interface EngineServerIsolatedPosition {
@@ -200,12 +227,12 @@ export interface EngineServerSymbol {
200
227
  price_increment_x18: string;
201
228
  size_increment: string;
202
229
  min_size: string;
203
- min_depth_x18: string;
204
- max_spread_rate_x18: string;
205
230
  maker_fee_rate_x18: string;
206
231
  taker_fee_rate_x18: string;
207
232
  long_weight_initial_x18: string;
208
233
  long_weight_maintenance_x18: string;
234
+ // undefined when there is no max open interest limit (always undefined for spot products)
235
+ max_open_interest_x18: string | undefined;
209
236
  }
210
237
 
211
238
  export interface EngineServerSymbolsResponse {
@@ -253,6 +280,7 @@ export interface EngineServerFeeRatesResponse {
253
280
  withdraw_sequencer_fees: string[];
254
281
  taker_fee_rates_x18: string[];
255
282
  maker_fee_rates_x18: string[];
283
+ fee_tier: number;
256
284
  }
257
285
 
258
286
  export interface EngineServerMarketPrice {
@@ -267,20 +295,6 @@ export interface EngineServerMarketPricesResponse {
267
295
  market_prices: EngineServerMarketPrice[];
268
296
  }
269
297
 
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
298
  export type EngineServerOrderResponse = EngineServerOrder;
285
299
 
286
300
  export interface EngineServerValidateOrderResponse {
@@ -317,10 +331,33 @@ export interface EngineServerEdgeAllProductsResponse {
317
331
  edge_all_products: Record<number, EngineServerAllProductsResponse>;
318
332
  }
319
333
 
334
+ export interface EngineServerMaxBurnNlpResponse {
335
+ max_nlp_amount: string;
336
+ }
337
+
320
338
  export interface EngineServerMaxMintNlpResponse {
321
339
  max_quote_amount: string;
322
340
  }
323
341
 
342
+ export interface EngineServerNlpLockedBalancesResponse {
343
+ balance_locked: EngineServerNlpBalance;
344
+ balance_unlocked: EngineServerNlpBalance;
345
+ locked_balances: EngineServerNlpLockedBalance[];
346
+ }
347
+
348
+ export interface EngineServerNlpPool {
349
+ pool_id: number;
350
+ subaccount: string;
351
+ owner: string;
352
+ balance_weight_x18: string;
353
+ subaccount_info: EngineServerSubaccountInfoResponse;
354
+ open_orders: EngineServerOrder[];
355
+ }
356
+
357
+ export interface EngineServerNlpPoolInfoResponse {
358
+ nlp_pools: EngineServerNlpPool[];
359
+ }
360
+
324
361
  export interface EngineServerQueryResponseByType {
325
362
  all_products: EngineServerAllProductsResponse;
326
363
  contracts: EngineServerContractsResponse;
@@ -333,8 +370,11 @@ export interface EngineServerQueryResponseByType {
333
370
  market_liquidity: EngineServerMarketLiquidityResponse;
334
371
  market_price: EngineServerMarketPriceResponse;
335
372
  market_prices: EngineServerMarketPricesResponse;
373
+ max_nlp_burnable: EngineServerMaxBurnNlpResponse;
336
374
  max_nlp_mintable: EngineServerMaxMintNlpResponse;
337
375
  max_order_size: EngineServerMaxOrderSizeResponse;
376
+ nlp_locked_balances: EngineServerNlpLockedBalancesResponse;
377
+ nlp_pool_info: EngineServerNlpPoolInfoResponse;
338
378
  max_withdrawable: EngineServerMaxWithdrawableResponse;
339
379
  nonces: EngineServerNoncesResponse;
340
380
  order: EngineServerOrderResponse;
@@ -1,22 +1,48 @@
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
34
+ EngineServerSubscriptionEventType = 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
44
+ extends EngineServerSubscriptionBaseEvent<'trade'> {
18
45
  timestamp: string;
19
- product_id: number;
20
46
  price: string;
21
47
  taker_qty: string;
22
48
  maker_qty: string;
@@ -26,49 +52,133 @@ export interface EngineServerSubscriptionTradeEvent {
26
52
  /**
27
53
  * Event from subscribing to a `best_bid_offer` stream.
28
54
  */
29
- export interface EngineServerSubscriptionBestBidOfferEvent {
55
+ export interface EngineServerSubscriptionBestBidOfferEvent
56
+ extends EngineServerSubscriptionBaseEvent<'best_bid_offer'> {
30
57
  timestamp: string;
31
- product_id: number;
32
58
  bid_price: string;
33
59
  bid_qty: string;
34
60
  ask_price: string;
35
61
  ask_qty: string;
36
62
  }
37
63
 
64
+ /**
65
+ * Event from subscribing to a `book_depth` stream.
66
+ */
67
+ export interface EngineServerSubscriptionBookDepthEvent
68
+ extends EngineServerSubscriptionBaseEvent<'book_depth'> {
69
+ last_max_timestamp: string;
70
+ min_timestamp: string;
71
+ max_timestamp: string;
72
+ bids: EngineServerPriceTickLiquidity[];
73
+ asks: EngineServerPriceTickLiquidity[];
74
+ }
75
+
38
76
  /**
39
77
  * Event from subscribing to a `fill` stream.
40
78
  */
41
- export interface EngineServerSubscriptionFillEvent {
79
+ export interface EngineServerSubscriptionFillEvent
80
+ extends EngineServerSubscriptionBaseEvent<'fill'> {
42
81
  // NOTE: `id` is excluded from the response to avoid parsing issues.
43
82
  // type of `id` on the backend is `u64` which can overflow until we introduce proper parsing on the SDK.
44
83
  timestamp: string;
45
- product_id: number;
46
84
  subaccount: string;
47
85
  order_digest: string;
48
86
  filled_qty: string;
49
87
  remaining_qty: string;
88
+ original_qty: string;
50
89
  price: string;
51
90
  is_taker: boolean;
91
+ is_bid: boolean;
92
+ fee: string;
93
+ submission_idx: string;
94
+ appendix: string;
52
95
  }
53
96
 
54
97
  /**
55
98
  * Event from subscribing to a `position_change` stream.
56
99
  */
57
- export interface EngineServerSubscriptionPositionChangeEvent {
100
+ export interface EngineServerSubscriptionPositionChangeEvent
101
+ extends EngineServerSubscriptionBaseEvent<'position_change'> {
58
102
  timestamp: string;
59
- product_id: number;
60
103
  subaccount: string;
61
104
  amount: string;
105
+ /** Zero for everything except perps */
62
106
  v_quote_amount: string;
107
+ reason: PositionChangeReason;
108
+ /**
109
+ * True if the position change was for an isolated position
110
+ */
111
+ isolated: boolean;
63
112
  }
64
113
 
65
114
  /**
66
- * Event from subscribing to a `book_depth` stream.
115
+ * Event from subscribing to an `order_update` stream.
67
116
  */
68
- export interface EngineServerSubscriptionBookDepthEvent {
69
- min_timestamp: string;
70
- max_timestamp: string;
71
- product_id: number;
72
- bids: EngineServerPriceTickLiquidity[];
73
- asks: EngineServerPriceTickLiquidity[];
117
+ export interface EngineServerSubscriptionOrderUpdateEvent
118
+ extends EngineServerSubscriptionBaseEvent<'order_update'> {
119
+ timestamp: string;
120
+ digest: string;
121
+ amount: string;
122
+ reason: OrderUpdateReason;
74
123
  }
124
+
125
+ /**
126
+ * Event from subscribing to a `liquidation` stream.
127
+ */
128
+ export interface EngineServerSubscriptionLiquidationEvent
129
+ extends EngineServerSubscriptionBaseEvent<'liquidation'> {
130
+ timestamp: string;
131
+ /** Single element for regular liquidations, two elements for spread liquidations [spotId, perpId] */
132
+ product_ids: number[];
133
+ liquidator: string;
134
+ liquidatee: string;
135
+ /** Amount liquidated (positive for long, negative for short) */
136
+ amount: string;
137
+ /** Price at which liquidation occurred */
138
+ price: string;
139
+ }
140
+
141
+ /**
142
+ * Event from subscribing to a `latest_candlestick` stream.
143
+ */
144
+ export interface EngineServerSubscriptionLatestCandlestickEvent
145
+ extends EngineServerSubscriptionBaseEvent<'latest_candlestick'> {
146
+ timestamp: string;
147
+ granularity: number;
148
+ open_x18: string;
149
+ high_x18: string;
150
+ low_x18: string;
151
+ close_x18: string;
152
+ volume: string;
153
+ }
154
+
155
+ /**
156
+ * Event from subscribing to a `funding_payment` stream.
157
+ */
158
+ export interface EngineServerSubscriptionFundingPaymentEvent
159
+ extends EngineServerSubscriptionBaseEvent<'funding_payment'> {
160
+ timestamp: string;
161
+ /** Funding payment amount (positive = receive, negative = pay) */
162
+ payment_amount: string;
163
+ /** Open interest at time of funding */
164
+ open_interest: string;
165
+ /** Current cumulative funding values */
166
+ cumulative_funding_long_x18: string;
167
+ cumulative_funding_short_x18: string;
168
+ /** Time delta over which the funding payment was calculated */
169
+ dt: string;
170
+ }
171
+
172
+ /**
173
+ * Union type for all engine server subscription events.
174
+ */
175
+ export type EngineServerSubscriptionEvent =
176
+ | EngineServerSubscriptionTradeEvent
177
+ | EngineServerSubscriptionBestBidOfferEvent
178
+ | EngineServerSubscriptionBookDepthEvent
179
+ | EngineServerSubscriptionFillEvent
180
+ | EngineServerSubscriptionPositionChangeEvent
181
+ | EngineServerSubscriptionOrderUpdateEvent
182
+ | EngineServerSubscriptionLiquidationEvent
183
+ | EngineServerSubscriptionLatestCandlestickEvent
184
+ | 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
+ }