n8n-nodes-sunx-perps 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.
@@ -0,0 +1,855 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SunxPerps = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const SunxPerpsUtils_1 = require("./SunxPerpsUtils");
6
+ class SunxPerps {
7
+ constructor() {
8
+ this.description = {
9
+ displayName: 'SunX Perps',
10
+ name: 'sunxPerps',
11
+ icon: 'file:sunx.svg',
12
+ group: ['transform'],
13
+ version: 1,
14
+ subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
15
+ description: 'Interact with SunX Perpetual Futures API',
16
+ defaults: {
17
+ name: 'SunX Perps',
18
+ },
19
+ inputs: ['main'],
20
+ outputs: ['main'],
21
+ credentials: [
22
+ {
23
+ name: 'sunxPerpsApi',
24
+ required: true,
25
+ },
26
+ ],
27
+ requestDefaults: {
28
+ baseURL: '={{$credentials.baseUrl}}',
29
+ headers: {
30
+ Accept: 'application/json',
31
+ 'Content-Type': 'application/json',
32
+ },
33
+ },
34
+ properties: [
35
+ {
36
+ displayName: 'Resource',
37
+ name: 'resource',
38
+ type: 'options',
39
+ noDataExpression: true,
40
+ options: [
41
+ {
42
+ name: 'Account',
43
+ value: 'account',
44
+ },
45
+ {
46
+ name: 'Market Data',
47
+ value: 'marketData',
48
+ },
49
+ {
50
+ name: 'Order',
51
+ value: 'order',
52
+ },
53
+ {
54
+ name: 'Position',
55
+ value: 'position',
56
+ },
57
+ ],
58
+ default: 'account',
59
+ },
60
+ {
61
+ displayName: 'Operation',
62
+ name: 'operation',
63
+ type: 'options',
64
+ noDataExpression: true,
65
+ displayOptions: {
66
+ show: {
67
+ resource: ['account'],
68
+ },
69
+ },
70
+ options: [
71
+ {
72
+ name: 'Get Balance',
73
+ value: 'getBalance',
74
+ description: 'Get account balance',
75
+ action: 'Get account balance',
76
+ },
77
+ {
78
+ name: 'Get Trading Bills',
79
+ value: 'getTradingBills',
80
+ description: 'Get trading bills',
81
+ action: 'Get trading bills',
82
+ },
83
+ ],
84
+ default: 'getBalance',
85
+ },
86
+ {
87
+ displayName: 'Operation',
88
+ name: 'operation',
89
+ type: 'options',
90
+ noDataExpression: true,
91
+ displayOptions: {
92
+ show: {
93
+ resource: ['marketData'],
94
+ },
95
+ },
96
+ options: [
97
+ {
98
+ name: 'Get Contract Info',
99
+ value: 'getContractInfo',
100
+ description: 'Get contract information',
101
+ action: 'Get contract information',
102
+ },
103
+ {
104
+ name: 'Get Fee Info',
105
+ value: 'getFeeInfo',
106
+ description: 'Get fee information about pair',
107
+ action: 'Get fee information',
108
+ },
109
+ {
110
+ name: 'Get Funding Rate',
111
+ value: 'getFundingRate',
112
+ description: 'Get current funding rate',
113
+ action: 'Get funding rate',
114
+ },
115
+ {
116
+ name: 'Get Historical Funding Rate',
117
+ value: 'getHistoricalFundingRate',
118
+ description: 'Get historical funding rate',
119
+ action: 'Get historical funding rate',
120
+ },
121
+ {
122
+ name: 'Get Leverage Info',
123
+ value: 'getLeverageInfo',
124
+ description: 'Get futures risk limit',
125
+ action: 'Get leverage information',
126
+ },
127
+ {
128
+ name: 'Get Multi-Asset Collateral',
129
+ value: 'getMultiAssetCollateral',
130
+ description: 'Get assets available for multi-assets collateral mode',
131
+ action: 'Get multi-asset collateral info',
132
+ },
133
+ {
134
+ name: 'Get Swap Index Price',
135
+ value: 'getSwapIndexPrice',
136
+ description: 'Get swap index price information',
137
+ action: 'Get swap index price',
138
+ },
139
+ ],
140
+ default: 'getFundingRate',
141
+ },
142
+ {
143
+ displayName: 'Operation',
144
+ name: 'operation',
145
+ type: 'options',
146
+ noDataExpression: true,
147
+ displayOptions: {
148
+ show: {
149
+ resource: ['order'],
150
+ },
151
+ },
152
+ options: [
153
+ {
154
+ name: 'Cancel All Orders',
155
+ value: 'cancelAllOrders',
156
+ description: 'Cancel all orders',
157
+ action: 'Cancel all orders',
158
+ },
159
+ {
160
+ name: 'Cancel Multiple Orders',
161
+ value: 'cancelMultipleOrders',
162
+ description: 'Cancel multiple orders',
163
+ action: 'Cancel multiple orders',
164
+ },
165
+ {
166
+ name: 'Cancel Order',
167
+ value: 'cancelOrder',
168
+ description: 'Cancel a single order',
169
+ action: 'Cancel order',
170
+ },
171
+ {
172
+ name: 'Close All at Market Price',
173
+ value: 'closeAllAtMarket',
174
+ description: 'Close all positions at market price',
175
+ action: 'Close all at market price',
176
+ },
177
+ {
178
+ name: 'Close Symbol at Market Price',
179
+ value: 'closeSymbolAtMarket',
180
+ description: 'Close all of a symbol at market price',
181
+ action: 'Close symbol at market price',
182
+ },
183
+ {
184
+ name: 'Get Current Orders',
185
+ value: 'getCurrentOrders',
186
+ description: 'Get current orders',
187
+ action: 'Get current orders',
188
+ },
189
+ {
190
+ name: 'Get Order History',
191
+ value: 'getOrderHistory',
192
+ description: 'Get order history',
193
+ action: 'Get order history',
194
+ },
195
+ {
196
+ name: 'Get Order Info',
197
+ value: 'getOrderInfo',
198
+ description: 'Get order information',
199
+ action: 'Get order info',
200
+ },
201
+ {
202
+ name: 'Place Multiple Orders',
203
+ value: 'placeMultipleOrders',
204
+ description: 'Place multiple orders',
205
+ action: 'Place multiple orders',
206
+ },
207
+ {
208
+ name: 'Place Order',
209
+ value: 'placeOrder',
210
+ description: 'Place a single order',
211
+ action: 'Place order',
212
+ },
213
+ ],
214
+ default: 'placeOrder',
215
+ },
216
+ {
217
+ displayName: 'Operation',
218
+ name: 'operation',
219
+ type: 'options',
220
+ noDataExpression: true,
221
+ displayOptions: {
222
+ show: {
223
+ resource: ['position'],
224
+ },
225
+ },
226
+ options: [
227
+ {
228
+ name: 'Get Current Position',
229
+ value: 'getCurrentPosition',
230
+ description: 'Get current position',
231
+ action: 'Get current position',
232
+ },
233
+ {
234
+ name: 'Get Position Mode',
235
+ value: 'getPositionMode',
236
+ description: 'Get position mode',
237
+ action: 'Get position mode',
238
+ },
239
+ {
240
+ name: 'Set Leverage',
241
+ value: 'setLeverage',
242
+ description: 'Set leverage',
243
+ action: 'Set leverage',
244
+ },
245
+ {
246
+ name: 'Set Position Mode',
247
+ value: 'setPositionMode',
248
+ description: 'Set position mode',
249
+ action: 'Set position mode',
250
+ },
251
+ ],
252
+ default: 'getCurrentPosition',
253
+ },
254
+ {
255
+ displayName: 'Contract Code',
256
+ name: 'contractCode',
257
+ type: 'string',
258
+ required: true,
259
+ displayOptions: {
260
+ show: {
261
+ resource: ['marketData'],
262
+ operation: [
263
+ 'getFundingRate',
264
+ 'getHistoricalFundingRate',
265
+ 'getSwapIndexPrice',
266
+ 'getLeverageInfo',
267
+ 'getFeeInfo',
268
+ ],
269
+ },
270
+ },
271
+ default: 'BTC-USDT',
272
+ description: 'The contract code (e.g., BTC-USDT)',
273
+ },
274
+ {
275
+ displayName: 'Contract Code',
276
+ name: 'contractCode',
277
+ type: 'string',
278
+ required: true,
279
+ displayOptions: {
280
+ show: {
281
+ resource: ['order'],
282
+ operation: ['placeOrder'],
283
+ },
284
+ },
285
+ default: 'BTC-USDT',
286
+ description: 'The contract code (e.g., BTC-USDT)',
287
+ },
288
+ {
289
+ displayName: 'Direction',
290
+ name: 'direction',
291
+ type: 'options',
292
+ required: true,
293
+ displayOptions: {
294
+ show: {
295
+ resource: ['order'],
296
+ operation: ['placeOrder'],
297
+ },
298
+ },
299
+ options: [
300
+ {
301
+ name: 'Buy',
302
+ value: 'buy',
303
+ },
304
+ {
305
+ name: 'Sell',
306
+ value: 'sell',
307
+ },
308
+ ],
309
+ default: 'buy',
310
+ description: 'Order direction',
311
+ },
312
+ {
313
+ displayName: 'Offset',
314
+ name: 'offset',
315
+ type: 'options',
316
+ required: true,
317
+ displayOptions: {
318
+ show: {
319
+ resource: ['order'],
320
+ operation: ['placeOrder'],
321
+ },
322
+ },
323
+ options: [
324
+ {
325
+ name: 'Open',
326
+ value: 'open',
327
+ },
328
+ {
329
+ name: 'Close',
330
+ value: 'close',
331
+ },
332
+ ],
333
+ default: 'open',
334
+ description: 'Open or close position',
335
+ },
336
+ {
337
+ displayName: 'Order Price Type',
338
+ name: 'orderPriceType',
339
+ type: 'options',
340
+ required: true,
341
+ displayOptions: {
342
+ show: {
343
+ resource: ['order'],
344
+ operation: ['placeOrder'],
345
+ },
346
+ },
347
+ options: [
348
+ {
349
+ name: 'Limit',
350
+ value: 'limit',
351
+ },
352
+ {
353
+ name: 'Market',
354
+ value: 'market',
355
+ },
356
+ {
357
+ name: 'Post Only',
358
+ value: 'post_only',
359
+ },
360
+ {
361
+ name: 'FOK',
362
+ value: 'fok',
363
+ },
364
+ {
365
+ name: 'IOC',
366
+ value: 'ioc',
367
+ },
368
+ ],
369
+ default: 'limit',
370
+ description: 'Order price type',
371
+ },
372
+ {
373
+ displayName: 'Volume',
374
+ name: 'volume',
375
+ type: 'number',
376
+ required: true,
377
+ displayOptions: {
378
+ show: {
379
+ resource: ['order'],
380
+ operation: ['placeOrder'],
381
+ },
382
+ },
383
+ default: 1,
384
+ description: 'Order volume (number of contracts)',
385
+ },
386
+ {
387
+ displayName: 'Price',
388
+ name: 'price',
389
+ type: 'number',
390
+ displayOptions: {
391
+ show: {
392
+ resource: ['order'],
393
+ operation: ['placeOrder'],
394
+ orderPriceType: ['limit', 'post_only'],
395
+ },
396
+ },
397
+ default: 0,
398
+ description: 'Order price (required for limit orders)',
399
+ },
400
+ {
401
+ displayName: 'Leverage Rate',
402
+ name: 'leverageRate',
403
+ type: 'number',
404
+ displayOptions: {
405
+ show: {
406
+ resource: ['order'],
407
+ operation: ['placeOrder'],
408
+ },
409
+ },
410
+ default: 10,
411
+ description: 'Leverage rate (e.g., 10 for 10x)',
412
+ },
413
+ {
414
+ displayName: 'Client Order ID',
415
+ name: 'clientOrderId',
416
+ type: 'string',
417
+ displayOptions: {
418
+ show: {
419
+ resource: ['order'],
420
+ operation: ['placeOrder'],
421
+ },
422
+ },
423
+ default: '',
424
+ description: 'Client order ID (optional)',
425
+ },
426
+ {
427
+ displayName: 'Orders',
428
+ name: 'orders',
429
+ type: 'json',
430
+ required: true,
431
+ displayOptions: {
432
+ show: {
433
+ resource: ['order'],
434
+ operation: ['placeMultipleOrders'],
435
+ },
436
+ },
437
+ default: '[]',
438
+ description: 'Array of orders in JSON format',
439
+ placeholder: '[{"contract_code":"BTC-USDT","direction":"buy","offset":"open","order_price_type":"limit","volume":1,"price":50000}]',
440
+ },
441
+ {
442
+ displayName: 'Order ID',
443
+ name: 'orderId',
444
+ type: 'string',
445
+ required: true,
446
+ displayOptions: {
447
+ show: {
448
+ resource: ['order'],
449
+ operation: ['cancelOrder', 'getOrderInfo'],
450
+ },
451
+ },
452
+ default: '',
453
+ description: 'Order ID to cancel or get info',
454
+ },
455
+ {
456
+ displayName: 'Contract Code',
457
+ name: 'contractCode',
458
+ type: 'string',
459
+ displayOptions: {
460
+ show: {
461
+ resource: ['order'],
462
+ operation: ['cancelOrder', 'getOrderInfo'],
463
+ },
464
+ },
465
+ default: '',
466
+ description: 'Contract code (optional)',
467
+ },
468
+ {
469
+ displayName: 'Order IDs',
470
+ name: 'orderIds',
471
+ type: 'string',
472
+ required: true,
473
+ displayOptions: {
474
+ show: {
475
+ resource: ['order'],
476
+ operation: ['cancelMultipleOrders'],
477
+ },
478
+ },
479
+ default: '',
480
+ description: 'Comma-separated list of order IDs',
481
+ },
482
+ {
483
+ displayName: 'Contract Code',
484
+ name: 'contractCode',
485
+ type: 'string',
486
+ displayOptions: {
487
+ show: {
488
+ resource: ['order'],
489
+ operation: ['cancelAllOrders', 'closeSymbolAtMarket'],
490
+ },
491
+ },
492
+ default: '',
493
+ description: 'Contract code (optional for cancel all, required for close symbol)',
494
+ },
495
+ {
496
+ displayName: 'Direction',
497
+ name: 'direction',
498
+ type: 'options',
499
+ displayOptions: {
500
+ show: {
501
+ resource: ['order'],
502
+ operation: ['closeSymbolAtMarket', 'closeAllAtMarket'],
503
+ },
504
+ },
505
+ options: [
506
+ {
507
+ name: 'Buy',
508
+ value: 'buy',
509
+ },
510
+ {
511
+ name: 'Sell',
512
+ value: 'sell',
513
+ },
514
+ ],
515
+ default: 'buy',
516
+ description: 'Direction to close',
517
+ },
518
+ {
519
+ displayName: 'Contract Code',
520
+ name: 'contractCode',
521
+ type: 'string',
522
+ displayOptions: {
523
+ show: {
524
+ resource: ['order'],
525
+ operation: ['getCurrentOrders', 'getOrderHistory'],
526
+ },
527
+ },
528
+ default: '',
529
+ description: 'Contract code (optional)',
530
+ },
531
+ {
532
+ displayName: 'Page Index',
533
+ name: 'pageIndex',
534
+ type: 'number',
535
+ displayOptions: {
536
+ show: {
537
+ resource: ['order'],
538
+ operation: ['getOrderHistory'],
539
+ },
540
+ },
541
+ default: 1,
542
+ description: 'Page index',
543
+ },
544
+ {
545
+ displayName: 'Page Size',
546
+ name: 'pageSize',
547
+ type: 'number',
548
+ displayOptions: {
549
+ show: {
550
+ resource: ['order'],
551
+ operation: ['getOrderHistory'],
552
+ },
553
+ },
554
+ default: 20,
555
+ description: 'Page size',
556
+ },
557
+ {
558
+ displayName: 'Contract Code',
559
+ name: 'contractCode',
560
+ type: 'string',
561
+ displayOptions: {
562
+ show: {
563
+ resource: ['position'],
564
+ operation: ['getCurrentPosition', 'setLeverage'],
565
+ },
566
+ },
567
+ default: '',
568
+ description: 'Contract code (optional for get position, required for set leverage)',
569
+ },
570
+ {
571
+ displayName: 'Leverage Rate',
572
+ name: 'leverageRate',
573
+ type: 'number',
574
+ required: true,
575
+ displayOptions: {
576
+ show: {
577
+ resource: ['position'],
578
+ operation: ['setLeverage'],
579
+ },
580
+ },
581
+ default: 10,
582
+ description: 'Leverage rate to set',
583
+ },
584
+ {
585
+ displayName: 'Position Mode',
586
+ name: 'positionMode',
587
+ type: 'options',
588
+ required: true,
589
+ displayOptions: {
590
+ show: {
591
+ resource: ['position'],
592
+ operation: ['setPositionMode'],
593
+ },
594
+ },
595
+ options: [
596
+ {
597
+ name: 'Dual Side',
598
+ value: 'dual_side',
599
+ },
600
+ {
601
+ name: 'Single Side',
602
+ value: 'single_side',
603
+ },
604
+ ],
605
+ default: 'single_side',
606
+ description: 'Position mode to set',
607
+ },
608
+ {
609
+ displayName: 'Contract Code',
610
+ name: 'contractCode',
611
+ type: 'string',
612
+ displayOptions: {
613
+ show: {
614
+ resource: ['account'],
615
+ operation: ['getTradingBills'],
616
+ },
617
+ },
618
+ default: '',
619
+ description: 'Contract code (optional)',
620
+ },
621
+ {
622
+ displayName: 'Type',
623
+ name: 'type',
624
+ type: 'options',
625
+ displayOptions: {
626
+ show: {
627
+ resource: ['account'],
628
+ operation: ['getTradingBills'],
629
+ },
630
+ },
631
+ options: [
632
+ {
633
+ name: 'All',
634
+ value: '',
635
+ },
636
+ {
637
+ name: 'Open Long',
638
+ value: 'open_long',
639
+ },
640
+ {
641
+ name: 'Open Short',
642
+ value: 'open_short',
643
+ },
644
+ {
645
+ name: 'Close Long',
646
+ value: 'close_long',
647
+ },
648
+ {
649
+ name: 'Close Short',
650
+ value: 'close_short',
651
+ },
652
+ ],
653
+ default: '',
654
+ description: 'Bill type',
655
+ },
656
+ ],
657
+ };
658
+ }
659
+ async execute() {
660
+ const items = this.getInputData();
661
+ const returnData = [];
662
+ const resource = this.getNodeParameter('resource', 0);
663
+ const operation = this.getNodeParameter('operation', 0);
664
+ for (let i = 0; i < items.length; i++) {
665
+ try {
666
+ let responseData;
667
+ if (resource === 'account') {
668
+ if (operation === 'getBalance') {
669
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'GET', '/sapi/v1/account/balance');
670
+ }
671
+ else if (operation === 'getTradingBills') {
672
+ const qs = {};
673
+ const contractCode = this.getNodeParameter('contractCode', i, '');
674
+ const type = this.getNodeParameter('type', i, '');
675
+ if (contractCode)
676
+ qs.contract_code = contractCode;
677
+ if (type)
678
+ qs.type = type;
679
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'GET', '/sapi/v1/account/financial_record', undefined, qs);
680
+ }
681
+ }
682
+ else if (resource === 'marketData') {
683
+ if (operation === 'getContractInfo') {
684
+ responseData = await SunxPerpsUtils_1.sunxPublicApiRequest.call(this, 'GET', '/sapi/v1/public/contract_info');
685
+ }
686
+ else if (operation === 'getFeeInfo') {
687
+ const contractCode = this.getNodeParameter('contractCode', i);
688
+ responseData = await SunxPerpsUtils_1.sunxPublicApiRequest.call(this, 'GET', '/sapi/v1/public/swap_fee', { contract_code: contractCode });
689
+ }
690
+ else if (operation === 'getFundingRate') {
691
+ const contractCode = this.getNodeParameter('contractCode', i);
692
+ responseData = await SunxPerpsUtils_1.sunxPublicApiRequest.call(this, 'GET', '/sapi/v1/public/funding_rate', { contract_code: contractCode });
693
+ }
694
+ else if (operation === 'getHistoricalFundingRate') {
695
+ const contractCode = this.getNodeParameter('contractCode', i);
696
+ responseData = await SunxPerpsUtils_1.sunxPublicApiRequest.call(this, 'GET', '/sapi/v1/public/historical_funding_rate', { contract_code: contractCode });
697
+ }
698
+ else if (operation === 'getLeverageInfo') {
699
+ const contractCode = this.getNodeParameter('contractCode', i);
700
+ responseData = await SunxPerpsUtils_1.sunxPublicApiRequest.call(this, 'GET', '/sapi/v1/public/swap_adjustfactor', { contract_code: contractCode });
701
+ }
702
+ else if (operation === 'getMultiAssetCollateral') {
703
+ responseData = await SunxPerpsUtils_1.sunxPublicApiRequest.call(this, 'GET', '/sapi/v1/public/cross_transfer_info');
704
+ }
705
+ else if (operation === 'getSwapIndexPrice') {
706
+ const contractCode = this.getNodeParameter('contractCode', i);
707
+ responseData = await SunxPerpsUtils_1.sunxPublicApiRequest.call(this, 'GET', '/sapi/v1/public/swap_index', { contract_code: contractCode });
708
+ }
709
+ }
710
+ else if (resource === 'order') {
711
+ if (operation === 'placeOrder') {
712
+ const contractCode = this.getNodeParameter('contractCode', i);
713
+ const direction = this.getNodeParameter('direction', i);
714
+ const offset = this.getNodeParameter('offset', i);
715
+ const orderPriceType = this.getNodeParameter('orderPriceType', i);
716
+ const volume = this.getNodeParameter('volume', i);
717
+ const price = this.getNodeParameter('price', i, 0);
718
+ const leverageRate = this.getNodeParameter('leverageRate', i, 10);
719
+ const clientOrderId = this.getNodeParameter('clientOrderId', i, '');
720
+ const body = {
721
+ contract_code: contractCode,
722
+ direction,
723
+ offset,
724
+ order_price_type: orderPriceType,
725
+ volume,
726
+ lever_rate: leverageRate,
727
+ };
728
+ if (price && (orderPriceType === 'limit' || orderPriceType === 'post_only')) {
729
+ body.price = price;
730
+ }
731
+ if (clientOrderId) {
732
+ body.client_order_id = clientOrderId;
733
+ }
734
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'POST', '/sapi/v1/order', body);
735
+ }
736
+ else if (operation === 'placeMultipleOrders') {
737
+ const ordersJson = this.getNodeParameter('orders', i);
738
+ let orders;
739
+ try {
740
+ orders = JSON.parse(ordersJson);
741
+ }
742
+ catch (error) {
743
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Invalid JSON format for orders', { itemIndex: i });
744
+ }
745
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'POST', '/sapi/v1/order/batch', { orders_data: orders });
746
+ }
747
+ else if (operation === 'cancelOrder') {
748
+ const orderId = this.getNodeParameter('orderId', i);
749
+ const contractCode = this.getNodeParameter('contractCode', i, '');
750
+ const body = {
751
+ order_id: orderId,
752
+ };
753
+ if (contractCode) {
754
+ body.contract_code = contractCode;
755
+ }
756
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'POST', '/sapi/v1/order/cancel', body);
757
+ }
758
+ else if (operation === 'cancelMultipleOrders') {
759
+ const orderIdsString = this.getNodeParameter('orderIds', i);
760
+ const orderIds = orderIdsString.split(',').map((id) => id.trim());
761
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'POST', '/sapi/v1/order/cancel', { order_id: orderIds.join(',') });
762
+ }
763
+ else if (operation === 'cancelAllOrders') {
764
+ const contractCode = this.getNodeParameter('contractCode', i, '');
765
+ const body = {};
766
+ if (contractCode) {
767
+ body.contract_code = contractCode;
768
+ }
769
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'POST', '/sapi/v1/order/cancelall', body);
770
+ }
771
+ else if (operation === 'closeSymbolAtMarket') {
772
+ const contractCode = this.getNodeParameter('contractCode', i);
773
+ const direction = this.getNodeParameter('direction', i, 'buy');
774
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'POST', '/sapi/v1/order/close_position', {
775
+ contract_code: contractCode,
776
+ direction,
777
+ });
778
+ }
779
+ else if (operation === 'closeAllAtMarket') {
780
+ const direction = this.getNodeParameter('direction', i, 'buy');
781
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'POST', '/sapi/v1/order/close_all_position', { direction });
782
+ }
783
+ else if (operation === 'getCurrentOrders') {
784
+ const qs = {};
785
+ const contractCode = this.getNodeParameter('contractCode', i, '');
786
+ if (contractCode)
787
+ qs.contract_code = contractCode;
788
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'GET', '/sapi/v1/order/openorders', undefined, qs);
789
+ }
790
+ else if (operation === 'getOrderHistory') {
791
+ const qs = {};
792
+ const contractCode = this.getNodeParameter('contractCode', i, '');
793
+ const pageIndex = this.getNodeParameter('pageIndex', i, 1);
794
+ const pageSize = this.getNodeParameter('pageSize', i, 20);
795
+ if (contractCode)
796
+ qs.contract_code = contractCode;
797
+ qs.page_index = pageIndex;
798
+ qs.page_size = pageSize;
799
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'GET', '/sapi/v1/order/hisorders', undefined, qs);
800
+ }
801
+ else if (operation === 'getOrderInfo') {
802
+ const orderId = this.getNodeParameter('orderId', i);
803
+ const contractCode = this.getNodeParameter('contractCode', i, '');
804
+ const qs = {
805
+ order_id: orderId,
806
+ };
807
+ if (contractCode)
808
+ qs.contract_code = contractCode;
809
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'GET', '/sapi/v1/order/info', undefined, qs);
810
+ }
811
+ }
812
+ else if (resource === 'position') {
813
+ if (operation === 'getCurrentPosition') {
814
+ const qs = {};
815
+ const contractCode = this.getNodeParameter('contractCode', i, '');
816
+ if (contractCode)
817
+ qs.contract_code = contractCode;
818
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'GET', '/sapi/v1/position/info', undefined, qs);
819
+ }
820
+ else if (operation === 'setLeverage') {
821
+ const contractCode = this.getNodeParameter('contractCode', i);
822
+ const leverageRate = this.getNodeParameter('leverageRate', i);
823
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'POST', '/sapi/v1/position/switch_lever_rate', {
824
+ contract_code: contractCode,
825
+ lever_rate: leverageRate,
826
+ });
827
+ }
828
+ else if (operation === 'getPositionMode') {
829
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'GET', '/sapi/v1/position/position_mode');
830
+ }
831
+ else if (operation === 'setPositionMode') {
832
+ const positionMode = this.getNodeParameter('positionMode', i);
833
+ responseData = await SunxPerpsUtils_1.sunxApiRequest.call(this, 'POST', '/sapi/v1/position/switch_position_mode', {
834
+ position_mode: positionMode,
835
+ });
836
+ }
837
+ }
838
+ const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
839
+ returnData.push(...executionData);
840
+ }
841
+ catch (error) {
842
+ if (this.continueOnFail()) {
843
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
844
+ const executionErrorData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: errorMessage }), { itemData: { item: i } });
845
+ returnData.push(...executionErrorData);
846
+ continue;
847
+ }
848
+ throw error;
849
+ }
850
+ }
851
+ return [returnData];
852
+ }
853
+ }
854
+ exports.SunxPerps = SunxPerps;
855
+ //# sourceMappingURL=SunxPerps.node.js.map