n8n-nodes-tk-modify-orders 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,769 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitgetTKModifyPosition = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const BitgetHelper_1 = require("./BitgetHelper");
6
+ class BitgetTKModifyPosition {
7
+ constructor() {
8
+ this.description = {
9
+ displayName: 'Bitget TK – Modify Open Position',
10
+ name: 'bitgetTKModifyPosition',
11
+ icon: 'file:bitget.svg',
12
+ group: ['transform'],
13
+ version: 1,
14
+ subtitle: 'Modify open position settings on Bitget',
15
+ description: 'Modify open position settings on Bitget: leverage, margin, margin mode, position mode, TP/SL, or flash close. All API v2 options included.',
16
+ defaults: {
17
+ name: 'Bitget TK – Modify Open Position',
18
+ },
19
+ inputs: ['main'],
20
+ outputs: ['main'],
21
+ credentials: [
22
+ {
23
+ name: 'bitgetTKApi',
24
+ required: true,
25
+ },
26
+ ],
27
+ properties: [
28
+ // ─── Operation Selector ──────────────────────────────────────────
29
+ {
30
+ displayName: 'Position Operation',
31
+ name: 'positionOperation',
32
+ type: 'options',
33
+ options: [
34
+ {
35
+ name: 'Change Leverage',
36
+ value: 'setLeverage',
37
+ description: 'Adjust leverage for a symbol (supports separate long/short leverage)',
38
+ },
39
+ {
40
+ name: 'Adjust Position Margin',
41
+ value: 'setMargin',
42
+ description: 'Add or reduce isolated position margin',
43
+ },
44
+ {
45
+ name: 'Change Margin Mode',
46
+ value: 'setMarginMode',
47
+ description: 'Switch between isolated and crossed margin for a symbol',
48
+ },
49
+ {
50
+ name: 'Change Position Mode',
51
+ value: 'setPositionMode',
52
+ description: 'Switch between one-way and hedge (dual) position mode',
53
+ },
54
+ {
55
+ name: 'Set Position TP/SL (Place Pos TPSL)',
56
+ value: 'placePosTpsl',
57
+ description: 'Set simultaneous take-profit and stop-loss on a whole position',
58
+ },
59
+ {
60
+ name: 'Place Single TP or SL Order',
61
+ value: 'placeTpslOrder',
62
+ description: 'Place a single take-profit or stop-loss plan order on a position',
63
+ },
64
+ {
65
+ name: 'Flash Close Position (Market Close All)',
66
+ value: 'flashClose',
67
+ description: 'Instantly close a position at market price',
68
+ },
69
+ ],
70
+ default: 'setLeverage',
71
+ description: 'Choose position action to perform',
72
+ },
73
+ // ════════════════════════════════════════════════════════════════
74
+ // ─── CHANGE LEVERAGE ─────────────────────────────────────────────
75
+ // ════════════════════════════════════════════════════════════════
76
+ {
77
+ displayName: '── Change Leverage ──',
78
+ name: 'leverageSection',
79
+ type: 'notice',
80
+ default: '',
81
+ displayOptions: { show: { positionOperation: ['setLeverage'] } },
82
+ description: 'Endpoint: POST /api/v2/mix/account/set-leverage. Rate limit: 10/s per UID. Supports setting long and short leverage independently in hedge mode.',
83
+ },
84
+ {
85
+ displayName: 'Symbol',
86
+ name: 'leverageSymbol',
87
+ type: 'string',
88
+ default: 'BTCUSDT',
89
+ required: true,
90
+ displayOptions: { show: { positionOperation: ['setLeverage'] } },
91
+ description: 'Trading pair symbol, e.g. BTCUSDT',
92
+ },
93
+ {
94
+ displayName: 'Product Type',
95
+ name: 'leverageProductType',
96
+ type: 'options',
97
+ options: [
98
+ { name: 'USDT-M Perpetual Futures', value: 'USDT-FUTURES' },
99
+ { name: 'Coin-M Perpetual Futures', value: 'COIN-FUTURES' },
100
+ { name: 'USDC-M Perpetual Futures', value: 'USDC-FUTURES' },
101
+ { name: 'Simulated USDT-M Futures', value: 'SUSDT-FUTURES' },
102
+ { name: 'Simulated Coin-M Futures', value: 'SCOIN-FUTURES' },
103
+ { name: 'Simulated USDC-M Futures', value: 'SUSDC-FUTURES' },
104
+ ],
105
+ default: 'USDT-FUTURES',
106
+ required: true,
107
+ displayOptions: { show: { positionOperation: ['setLeverage'] } },
108
+ description: 'Futures product type',
109
+ },
110
+ {
111
+ displayName: 'Margin Coin',
112
+ name: 'leverageMarginCoin',
113
+ type: 'string',
114
+ default: 'USDT',
115
+ required: true,
116
+ displayOptions: { show: { positionOperation: ['setLeverage'] } },
117
+ description: 'Margin currency, e.g. USDT',
118
+ },
119
+ {
120
+ displayName: 'Leverage',
121
+ name: 'leverage',
122
+ type: 'string',
123
+ default: '10',
124
+ required: true,
125
+ displayOptions: { show: { positionOperation: ['setLeverage'] } },
126
+ description: 'New leverage value (integer). Check symbol max leverage on Bitget.',
127
+ },
128
+ {
129
+ displayName: 'Hold Side (Hedge Mode Only)',
130
+ name: 'leverageHoldSide',
131
+ type: 'options',
132
+ options: [
133
+ { name: 'Long', value: 'long' },
134
+ { name: 'Short', value: 'short' },
135
+ { name: 'Both (One-way mode / cross margin)', value: '' },
136
+ ],
137
+ default: '',
138
+ displayOptions: { show: { positionOperation: ['setLeverage'] } },
139
+ description: 'In hedge mode, specify which side to adjust. In one-way mode or cross margin, leave blank to apply to both sides.',
140
+ },
141
+ // ════════════════════════════════════════════════════════════════
142
+ // ─── ADJUST POSITION MARGIN ──────────────────────────────────────
143
+ // ════════════════════════════════════════════════════════════════
144
+ {
145
+ displayName: '── Adjust Position Margin ──',
146
+ name: 'marginSection',
147
+ type: 'notice',
148
+ default: '',
149
+ displayOptions: { show: { positionOperation: ['setMargin'] } },
150
+ description: 'Endpoint: POST /api/v2/mix/account/set-margin. Rate limit: 10/s per UID. Only applies to isolated margin positions.',
151
+ },
152
+ {
153
+ displayName: 'Symbol',
154
+ name: 'marginSymbol',
155
+ type: 'string',
156
+ default: 'BTCUSDT',
157
+ required: true,
158
+ displayOptions: { show: { positionOperation: ['setMargin'] } },
159
+ description: 'Trading pair symbol',
160
+ },
161
+ {
162
+ displayName: 'Product Type',
163
+ name: 'marginProductType',
164
+ type: 'options',
165
+ options: [
166
+ { name: 'USDT-M Perpetual Futures', value: 'USDT-FUTURES' },
167
+ { name: 'Coin-M Perpetual Futures', value: 'COIN-FUTURES' },
168
+ { name: 'USDC-M Perpetual Futures', value: 'USDC-FUTURES' },
169
+ { name: 'Simulated USDT-M Futures', value: 'SUSDT-FUTURES' },
170
+ { name: 'Simulated Coin-M Futures', value: 'SCOIN-FUTURES' },
171
+ { name: 'Simulated USDC-M Futures', value: 'SUSDC-FUTURES' },
172
+ ],
173
+ default: 'USDT-FUTURES',
174
+ required: true,
175
+ displayOptions: { show: { positionOperation: ['setMargin'] } },
176
+ description: 'Futures product type',
177
+ },
178
+ {
179
+ displayName: 'Margin Coin',
180
+ name: 'marginCoin',
181
+ type: 'string',
182
+ default: 'USDT',
183
+ required: true,
184
+ displayOptions: { show: { positionOperation: ['setMargin'] } },
185
+ description: 'Margin currency',
186
+ },
187
+ {
188
+ displayName: 'Amount',
189
+ name: 'marginAmount',
190
+ type: 'string',
191
+ default: '',
192
+ required: true,
193
+ displayOptions: { show: { positionOperation: ['setMargin'] } },
194
+ description: 'Amount to add (positive) or reduce (negative, e.g. "-20") from the isolated margin.',
195
+ },
196
+ {
197
+ displayName: 'Hold Side',
198
+ name: 'marginHoldSide',
199
+ type: 'options',
200
+ options: [
201
+ { name: 'Long', value: 'long' },
202
+ { name: 'Short', value: 'short' },
203
+ ],
204
+ default: 'long',
205
+ required: true,
206
+ displayOptions: { show: { positionOperation: ['setMargin'] } },
207
+ description: 'Which side position to adjust margin for',
208
+ },
209
+ // ════════════════════════════════════════════════════════════════
210
+ // ─── CHANGE MARGIN MODE ──────────────────────────────────────────
211
+ // ════════════════════════════════════════════════════════════════
212
+ {
213
+ displayName: '── Change Margin Mode ──',
214
+ name: 'marginModeSection',
215
+ type: 'notice',
216
+ default: '',
217
+ displayOptions: { show: { positionOperation: ['setMarginMode'] } },
218
+ description: 'Endpoint: POST /api/v2/mix/account/set-margin-mode. Rate limit: 10/s per UID. Cannot switch while positions are open.',
219
+ },
220
+ {
221
+ displayName: 'Symbol',
222
+ name: 'marginModeSymbol',
223
+ type: 'string',
224
+ default: 'BTCUSDT',
225
+ required: true,
226
+ displayOptions: { show: { positionOperation: ['setMarginMode'] } },
227
+ description: 'Trading pair symbol',
228
+ },
229
+ {
230
+ displayName: 'Product Type',
231
+ name: 'marginModeProductType',
232
+ type: 'options',
233
+ options: [
234
+ { name: 'USDT-M Perpetual Futures', value: 'USDT-FUTURES' },
235
+ { name: 'Coin-M Perpetual Futures', value: 'COIN-FUTURES' },
236
+ { name: 'USDC-M Perpetual Futures', value: 'USDC-FUTURES' },
237
+ { name: 'Simulated USDT-M Futures', value: 'SUSDT-FUTURES' },
238
+ { name: 'Simulated Coin-M Futures', value: 'SCOIN-FUTURES' },
239
+ { name: 'Simulated USDC-M Futures', value: 'SUSDC-FUTURES' },
240
+ ],
241
+ default: 'USDT-FUTURES',
242
+ required: true,
243
+ displayOptions: { show: { positionOperation: ['setMarginMode'] } },
244
+ description: 'Futures product type',
245
+ },
246
+ {
247
+ displayName: 'Margin Coin',
248
+ name: 'marginModeMarginCoin',
249
+ type: 'string',
250
+ default: 'USDT',
251
+ required: true,
252
+ displayOptions: { show: { positionOperation: ['setMarginMode'] } },
253
+ description: 'Margin currency',
254
+ },
255
+ {
256
+ displayName: 'Margin Mode',
257
+ name: 'marginModeValue',
258
+ type: 'options',
259
+ options: [
260
+ { name: 'Isolated', value: 'isolated' },
261
+ { name: 'Crossed (Cross)', value: 'crossed' },
262
+ ],
263
+ default: 'isolated',
264
+ required: true,
265
+ displayOptions: { show: { positionOperation: ['setMarginMode'] } },
266
+ description: 'New margin mode to set',
267
+ },
268
+ // ════════════════════════════════════════════════════════════════
269
+ // ─── CHANGE POSITION MODE ────────────────────────────────────────
270
+ // ════════════════════════════════════════════════════════════════
271
+ {
272
+ displayName: '── Change Position Mode ──',
273
+ name: 'positionModeSection',
274
+ type: 'notice',
275
+ default: '',
276
+ displayOptions: { show: { positionOperation: ['setPositionMode'] } },
277
+ description: 'Endpoint: POST /api/v2/mix/account/set-position-mode. Rate limit: 10/s per UID. Cannot switch while positions or orders are open.',
278
+ },
279
+ {
280
+ displayName: 'Product Type',
281
+ name: 'positionModeProductType',
282
+ type: 'options',
283
+ options: [
284
+ { name: 'USDT-M Perpetual Futures', value: 'USDT-FUTURES' },
285
+ { name: 'Coin-M Perpetual Futures', value: 'COIN-FUTURES' },
286
+ { name: 'USDC-M Perpetual Futures', value: 'USDC-FUTURES' },
287
+ { name: 'Simulated USDT-M Futures', value: 'SUSDT-FUTURES' },
288
+ { name: 'Simulated Coin-M Futures', value: 'SCOIN-FUTURES' },
289
+ { name: 'Simulated USDC-M Futures', value: 'SUSDC-FUTURES' },
290
+ ],
291
+ default: 'USDT-FUTURES',
292
+ required: true,
293
+ displayOptions: { show: { positionOperation: ['setPositionMode'] } },
294
+ description: 'Futures product type (position mode is set product-wide, not per symbol)',
295
+ },
296
+ {
297
+ displayName: 'Position Mode',
298
+ name: 'posMode',
299
+ type: 'options',
300
+ options: [
301
+ { name: 'One-Way Mode (single direction)', value: 'one_way_mode' },
302
+ { name: 'Hedge Mode (dual/two-way)', value: 'hedge_mode' },
303
+ ],
304
+ default: 'one_way_mode',
305
+ required: true,
306
+ displayOptions: { show: { positionOperation: ['setPositionMode'] } },
307
+ description: 'New position mode to set for the product type',
308
+ },
309
+ // ════════════════════════════════════════════════════════════════
310
+ // ─── SET POSITION TP/SL (place-pos-tpsl) ─────────────────────────
311
+ // ════════════════════════════════════════════════════════════════
312
+ {
313
+ displayName: '── Set Position TP/SL (Simultaneous) ──',
314
+ name: 'posTpslSection',
315
+ type: 'notice',
316
+ default: '',
317
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
318
+ description: 'Endpoint: POST /api/v2/mix/order/place-pos-tpsl. Set a TP and/or SL on an entire open position at once. Rate limit: 10/s per UID.',
319
+ },
320
+ {
321
+ displayName: 'Symbol',
322
+ name: 'posTpslSymbol',
323
+ type: 'string',
324
+ default: 'BTCUSDT',
325
+ required: true,
326
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
327
+ description: 'Trading pair symbol',
328
+ },
329
+ {
330
+ displayName: 'Product Type',
331
+ name: 'posTpslProductType',
332
+ type: 'options',
333
+ options: [
334
+ { name: 'USDT-M Perpetual Futures', value: 'usdt-futures' },
335
+ { name: 'Coin-M Perpetual Futures', value: 'coin-futures' },
336
+ { name: 'USDC-M Perpetual Futures', value: 'usdc-futures' },
337
+ { name: 'Simulated USDT-M Futures', value: 'susdt-futures' },
338
+ { name: 'Simulated Coin-M Futures', value: 'scoin-futures' },
339
+ { name: 'Simulated USDC-M Futures', value: 'susdc-futures' },
340
+ ],
341
+ default: 'usdt-futures',
342
+ required: true,
343
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
344
+ description: 'Futures product type',
345
+ },
346
+ {
347
+ displayName: 'Margin Coin',
348
+ name: 'posTpslMarginCoin',
349
+ type: 'string',
350
+ default: 'USDT',
351
+ required: true,
352
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
353
+ description: 'Margin currency',
354
+ },
355
+ {
356
+ displayName: 'Hold Side',
357
+ name: 'posTpslHoldSide',
358
+ type: 'options',
359
+ options: [
360
+ { name: 'Long', value: 'long' },
361
+ { name: 'Short', value: 'short' },
362
+ ],
363
+ default: 'long',
364
+ required: true,
365
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
366
+ description: 'Which position side to set TP/SL on',
367
+ },
368
+ {
369
+ displayName: '── Take-Profit Settings ──',
370
+ name: 'posTpSection',
371
+ type: 'notice',
372
+ default: '',
373
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
374
+ },
375
+ {
376
+ displayName: 'Stop-Surplus (TP) Trigger Price',
377
+ name: 'posTpslStopSurplusTriggerPrice',
378
+ type: 'string',
379
+ default: '',
380
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
381
+ description: 'Take-profit trigger price. Leave blank to skip TP.',
382
+ },
383
+ {
384
+ displayName: 'Stop-Surplus Trigger Type',
385
+ name: 'posTpslStopSurplusTriggerType',
386
+ type: 'options',
387
+ options: [
388
+ { name: 'Fill Price (Last)', value: 'fill_price' },
389
+ { name: 'Mark Price', value: 'mark_price' },
390
+ { name: 'Index Price', value: 'index_price' },
391
+ { name: '(None)', value: '' },
392
+ ],
393
+ default: 'mark_price',
394
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
395
+ description: 'Price type for TP trigger evaluation',
396
+ },
397
+ {
398
+ displayName: 'Stop-Surplus Execute Price',
399
+ name: 'posTpslStopSurplusExecutePrice',
400
+ type: 'string',
401
+ default: '',
402
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
403
+ description: 'TP execution price. Use "0" or leave blank for market execution.',
404
+ },
405
+ {
406
+ displayName: '── Stop-Loss Settings ──',
407
+ name: 'posSlSection',
408
+ type: 'notice',
409
+ default: '',
410
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
411
+ },
412
+ {
413
+ displayName: 'Stop-Loss Trigger Price',
414
+ name: 'posTpslStopLossTriggerPrice',
415
+ type: 'string',
416
+ default: '',
417
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
418
+ description: 'Stop-loss trigger price. Leave blank to skip SL.',
419
+ },
420
+ {
421
+ displayName: 'Stop-Loss Trigger Type',
422
+ name: 'posTpslStopLossTriggerType',
423
+ type: 'options',
424
+ options: [
425
+ { name: 'Fill Price (Last)', value: 'fill_price' },
426
+ { name: 'Mark Price', value: 'mark_price' },
427
+ { name: 'Index Price', value: 'index_price' },
428
+ { name: '(None)', value: '' },
429
+ ],
430
+ default: 'mark_price',
431
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
432
+ description: 'Price type for SL trigger evaluation',
433
+ },
434
+ {
435
+ displayName: 'Stop-Loss Execute Price',
436
+ name: 'posTpslStopLossExecutePrice',
437
+ type: 'string',
438
+ default: '',
439
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
440
+ description: 'SL execution price. Use "0" or leave blank for market execution.',
441
+ },
442
+ {
443
+ displayName: 'Client TP Order ID',
444
+ name: 'posTpslStopSurplusClientOid',
445
+ type: 'string',
446
+ default: '',
447
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
448
+ description: 'Custom client ID for the take-profit order (optional)',
449
+ },
450
+ {
451
+ displayName: 'Client SL Order ID',
452
+ name: 'posTpslStopLossClientOid',
453
+ type: 'string',
454
+ default: '',
455
+ displayOptions: { show: { positionOperation: ['placePosTpsl'] } },
456
+ description: 'Custom client ID for the stop-loss order (optional)',
457
+ },
458
+ // ════════════════════════════════════════════════════════════════
459
+ // ─── PLACE SINGLE TP OR SL ───────────────────────────────────────
460
+ // ════════════════════════════════════════════════════════════════
461
+ {
462
+ displayName: '── Place Single TP or SL Order ──',
463
+ name: 'singleTpslSection',
464
+ type: 'notice',
465
+ default: '',
466
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
467
+ description: 'Endpoint: POST /api/v2/mix/order/place-tpsl-order. Place a single TP or SL plan order on a position. Rate limit: 10/s per UID.',
468
+ },
469
+ {
470
+ displayName: 'Plan Type',
471
+ name: 'singleTpslPlanType',
472
+ type: 'options',
473
+ options: [
474
+ { name: 'Profit Plan (Take-Profit)', value: 'profit_plan' },
475
+ { name: 'Loss Plan (Stop-Loss)', value: 'loss_plan' },
476
+ { name: 'Moving Plan (Trailing Stop)', value: 'moving_plan' },
477
+ { name: 'Position Profit Plan (position TP)', value: 'pos_profit' },
478
+ { name: 'Position Loss Plan (position SL)', value: 'pos_loss' },
479
+ ],
480
+ default: 'profit_plan',
481
+ required: true,
482
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
483
+ description: 'Type of TP/SL plan order',
484
+ },
485
+ {
486
+ displayName: 'Symbol',
487
+ name: 'singleTpslSymbol',
488
+ type: 'string',
489
+ default: 'BTCUSDT',
490
+ required: true,
491
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
492
+ description: 'Trading pair symbol',
493
+ },
494
+ {
495
+ displayName: 'Product Type',
496
+ name: 'singleTpslProductType',
497
+ type: 'options',
498
+ options: [
499
+ { name: 'USDT-M Perpetual Futures', value: 'usdt-futures' },
500
+ { name: 'Coin-M Perpetual Futures', value: 'coin-futures' },
501
+ { name: 'USDC-M Perpetual Futures', value: 'usdc-futures' },
502
+ { name: 'Simulated USDT-M Futures', value: 'susdt-futures' },
503
+ { name: 'Simulated Coin-M Futures', value: 'scoin-futures' },
504
+ { name: 'Simulated USDC-M Futures', value: 'susdc-futures' },
505
+ ],
506
+ default: 'usdt-futures',
507
+ required: true,
508
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
509
+ description: 'Futures product type',
510
+ },
511
+ {
512
+ displayName: 'Margin Coin',
513
+ name: 'singleTpslMarginCoin',
514
+ type: 'string',
515
+ default: 'USDT',
516
+ required: true,
517
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
518
+ description: 'Margin currency',
519
+ },
520
+ {
521
+ displayName: 'Hold Side',
522
+ name: 'singleTpslHoldSide',
523
+ type: 'options',
524
+ options: [
525
+ { name: 'Long', value: 'long' },
526
+ { name: 'Short', value: 'short' },
527
+ ],
528
+ default: 'long',
529
+ required: true,
530
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
531
+ description: 'Which position side this TP/SL applies to',
532
+ },
533
+ {
534
+ displayName: 'Trigger Price',
535
+ name: 'singleTpslTriggerPrice',
536
+ type: 'string',
537
+ default: '',
538
+ required: true,
539
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
540
+ description: 'Price that triggers this plan order',
541
+ },
542
+ {
543
+ displayName: 'Trigger Type',
544
+ name: 'singleTpslTriggerType',
545
+ type: 'options',
546
+ options: [
547
+ { name: 'Fill Price (Last)', value: 'fill_price' },
548
+ { name: 'Mark Price', value: 'mark_price' },
549
+ { name: 'Index Price', value: 'index_price' },
550
+ ],
551
+ default: 'mark_price',
552
+ required: true,
553
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
554
+ description: 'Price type for trigger evaluation',
555
+ },
556
+ {
557
+ displayName: 'Execute Price',
558
+ name: 'singleTpslExecutePrice',
559
+ type: 'string',
560
+ default: '0',
561
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
562
+ description: 'Execution price after trigger. Use "0" for market execution.',
563
+ },
564
+ {
565
+ displayName: 'Size',
566
+ name: 'singleTpslSize',
567
+ type: 'string',
568
+ default: '',
569
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
570
+ description: 'Quantity to close. Leave blank to close the entire position.',
571
+ },
572
+ {
573
+ displayName: 'Range Rate (Trailing %)',
574
+ name: 'singleTpslRangeRate',
575
+ type: 'string',
576
+ default: '',
577
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
578
+ description: 'For moving/trailing plans: callback percentage (e.g. "1" = 1%)',
579
+ },
580
+ {
581
+ displayName: 'Client Order ID',
582
+ name: 'singleTpslClientOid',
583
+ type: 'string',
584
+ default: '',
585
+ displayOptions: { show: { positionOperation: ['placeTpslOrder'] } },
586
+ description: 'Custom client ID for this order (optional)',
587
+ },
588
+ // ════════════════════════════════════════════════════════════════
589
+ // ─── FLASH CLOSE POSITION ────────────────────────────────────────
590
+ // ════════════════════════════════════════════════════════════════
591
+ {
592
+ displayName: '── Flash Close Position ──',
593
+ name: 'flashCloseSection',
594
+ type: 'notice',
595
+ default: '',
596
+ displayOptions: { show: { positionOperation: ['flashClose'] } },
597
+ description: 'Endpoint: POST /api/v2/mix/order/close-positions. Instantly close a position at market price. Rate limit: 10/s per UID.',
598
+ },
599
+ {
600
+ displayName: 'Symbol',
601
+ name: 'flashCloseSymbol',
602
+ type: 'string',
603
+ default: 'BTCUSDT',
604
+ required: true,
605
+ displayOptions: { show: { positionOperation: ['flashClose'] } },
606
+ description: 'Trading pair symbol to close',
607
+ },
608
+ {
609
+ displayName: 'Product Type',
610
+ name: 'flashCloseProductType',
611
+ type: 'options',
612
+ options: [
613
+ { name: 'USDT-M Perpetual Futures', value: 'USDT-FUTURES' },
614
+ { name: 'Coin-M Perpetual Futures', value: 'COIN-FUTURES' },
615
+ { name: 'USDC-M Perpetual Futures', value: 'USDC-FUTURES' },
616
+ { name: 'Simulated USDT-M Futures', value: 'SUSDT-FUTURES' },
617
+ { name: 'Simulated Coin-M Futures', value: 'SCOIN-FUTURES' },
618
+ { name: 'Simulated USDC-M Futures', value: 'SUSDC-FUTURES' },
619
+ ],
620
+ default: 'USDT-FUTURES',
621
+ required: true,
622
+ displayOptions: { show: { positionOperation: ['flashClose'] } },
623
+ description: 'Futures product type',
624
+ },
625
+ {
626
+ displayName: 'Hold Side',
627
+ name: 'flashCloseHoldSide',
628
+ type: 'options',
629
+ options: [
630
+ { name: 'Long', value: 'long' },
631
+ { name: 'Short', value: 'short' },
632
+ { name: 'Both (close all sides)', value: '' },
633
+ ],
634
+ default: '',
635
+ displayOptions: { show: { positionOperation: ['flashClose'] } },
636
+ description: 'Which position side to close. Leave blank to close both sides.',
637
+ },
638
+ {
639
+ displayName: 'Client Order ID',
640
+ name: 'flashCloseClientOid',
641
+ type: 'string',
642
+ default: '',
643
+ displayOptions: { show: { positionOperation: ['flashClose'] } },
644
+ description: 'Custom client ID for the close order (optional)',
645
+ },
646
+ ],
647
+ };
648
+ }
649
+ async execute() {
650
+ const items = this.getInputData();
651
+ const returnData = [];
652
+ const credentials = await this.getCredentials('bitgetTKApi');
653
+ const creds = {
654
+ apiKey: credentials.apiKey,
655
+ secretKey: credentials.secretKey,
656
+ passphrase: credentials.passphrase,
657
+ };
658
+ for (let i = 0; i < items.length; i++) {
659
+ try {
660
+ const positionOperation = this.getNodeParameter('positionOperation', i);
661
+ let result;
662
+ if (positionOperation === 'setLeverage') {
663
+ const holdSide = this.getNodeParameter('leverageHoldSide', i);
664
+ const body = (0, BitgetHelper_1.cleanBody)({
665
+ symbol: this.getNodeParameter('leverageSymbol', i),
666
+ productType: this.getNodeParameter('leverageProductType', i),
667
+ marginCoin: this.getNodeParameter('leverageMarginCoin', i),
668
+ leverage: this.getNodeParameter('leverage', i),
669
+ holdSide: holdSide || undefined,
670
+ });
671
+ result = await (0, BitgetHelper_1.bitgetRequest)(creds, 'POST', '/api/v2/mix/account/set-leverage', body);
672
+ }
673
+ else if (positionOperation === 'setMargin') {
674
+ const body = (0, BitgetHelper_1.cleanBody)({
675
+ symbol: this.getNodeParameter('marginSymbol', i),
676
+ productType: this.getNodeParameter('marginProductType', i),
677
+ marginCoin: this.getNodeParameter('marginCoin', i),
678
+ amount: this.getNodeParameter('marginAmount', i),
679
+ holdSide: this.getNodeParameter('marginHoldSide', i),
680
+ });
681
+ result = await (0, BitgetHelper_1.bitgetRequest)(creds, 'POST', '/api/v2/mix/account/set-margin', body);
682
+ }
683
+ else if (positionOperation === 'setMarginMode') {
684
+ const body = (0, BitgetHelper_1.cleanBody)({
685
+ symbol: this.getNodeParameter('marginModeSymbol', i),
686
+ productType: this.getNodeParameter('marginModeProductType', i),
687
+ marginCoin: this.getNodeParameter('marginModeMarginCoin', i),
688
+ marginMode: this.getNodeParameter('marginModeValue', i),
689
+ });
690
+ result = await (0, BitgetHelper_1.bitgetRequest)(creds, 'POST', '/api/v2/mix/account/set-margin-mode', body);
691
+ }
692
+ else if (positionOperation === 'setPositionMode') {
693
+ const body = (0, BitgetHelper_1.cleanBody)({
694
+ productType: this.getNodeParameter('positionModeProductType', i),
695
+ posMode: this.getNodeParameter('posMode', i),
696
+ });
697
+ result = await (0, BitgetHelper_1.bitgetRequest)(creds, 'POST', '/api/v2/mix/account/set-position-mode', body);
698
+ }
699
+ else if (positionOperation === 'placePosTpsl') {
700
+ const stopSurplusTriggerPrice = this.getNodeParameter('posTpslStopSurplusTriggerPrice', i);
701
+ const stopSurplusTriggerType = this.getNodeParameter('posTpslStopSurplusTriggerType', i);
702
+ const stopSurplusExecutePrice = this.getNodeParameter('posTpslStopSurplusExecutePrice', i);
703
+ const stopLossTriggerPrice = this.getNodeParameter('posTpslStopLossTriggerPrice', i);
704
+ const stopLossTriggerType = this.getNodeParameter('posTpslStopLossTriggerType', i);
705
+ const stopLossExecutePrice = this.getNodeParameter('posTpslStopLossExecutePrice', i);
706
+ const stopSurplusClientOid = this.getNodeParameter('posTpslStopSurplusClientOid', i);
707
+ const stopLossClientOid = this.getNodeParameter('posTpslStopLossClientOid', i);
708
+ const body = (0, BitgetHelper_1.cleanBody)({
709
+ symbol: this.getNodeParameter('posTpslSymbol', i),
710
+ productType: this.getNodeParameter('posTpslProductType', i),
711
+ marginCoin: this.getNodeParameter('posTpslMarginCoin', i),
712
+ holdSide: this.getNodeParameter('posTpslHoldSide', i),
713
+ stopSurplusTriggerPrice: stopSurplusTriggerPrice || undefined,
714
+ stopSurplusTriggerType: stopSurplusTriggerType || undefined,
715
+ stopSurplusExecutePrice: stopSurplusExecutePrice || undefined,
716
+ stopLossTriggerPrice: stopLossTriggerPrice || undefined,
717
+ stopLossTriggerType: stopLossTriggerType || undefined,
718
+ stopLossExecutePrice: stopLossExecutePrice || undefined,
719
+ stopSurplusClientOid: stopSurplusClientOid || undefined,
720
+ stopLossClientOid: stopLossClientOid || undefined,
721
+ });
722
+ result = await (0, BitgetHelper_1.bitgetRequest)(creds, 'POST', '/api/v2/mix/order/place-pos-tpsl', body);
723
+ }
724
+ else if (positionOperation === 'placeTpslOrder') {
725
+ const size = this.getNodeParameter('singleTpslSize', i);
726
+ const rangeRate = this.getNodeParameter('singleTpslRangeRate', i);
727
+ const clientOid = this.getNodeParameter('singleTpslClientOid', i);
728
+ const body = (0, BitgetHelper_1.cleanBody)({
729
+ planType: this.getNodeParameter('singleTpslPlanType', i),
730
+ symbol: this.getNodeParameter('singleTpslSymbol', i),
731
+ productType: this.getNodeParameter('singleTpslProductType', i),
732
+ marginCoin: this.getNodeParameter('singleTpslMarginCoin', i),
733
+ holdSide: this.getNodeParameter('singleTpslHoldSide', i),
734
+ triggerPrice: this.getNodeParameter('singleTpslTriggerPrice', i),
735
+ triggerType: this.getNodeParameter('singleTpslTriggerType', i),
736
+ executePrice: this.getNodeParameter('singleTpslExecutePrice', i),
737
+ size: size || undefined,
738
+ rangeRate: rangeRate || undefined,
739
+ clientOid: clientOid || undefined,
740
+ });
741
+ result = await (0, BitgetHelper_1.bitgetRequest)(creds, 'POST', '/api/v2/mix/order/place-tpsl-order', body);
742
+ }
743
+ else {
744
+ // flashClose
745
+ const holdSide = this.getNodeParameter('flashCloseHoldSide', i);
746
+ const clientOid = this.getNodeParameter('flashCloseClientOid', i);
747
+ const body = (0, BitgetHelper_1.cleanBody)({
748
+ symbol: this.getNodeParameter('flashCloseSymbol', i),
749
+ productType: this.getNodeParameter('flashCloseProductType', i),
750
+ holdSide: holdSide || undefined,
751
+ clientOid: clientOid || undefined,
752
+ });
753
+ result = await (0, BitgetHelper_1.bitgetRequest)(creds, 'POST', '/api/v2/mix/order/close-positions', body);
754
+ }
755
+ returnData.push({ json: result });
756
+ }
757
+ catch (error) {
758
+ if (this.continueOnFail()) {
759
+ returnData.push({ json: { error: error.message } });
760
+ continue;
761
+ }
762
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
763
+ }
764
+ }
765
+ return [returnData];
766
+ }
767
+ }
768
+ exports.BitgetTKModifyPosition = BitgetTKModifyPosition;
769
+ //# sourceMappingURL=BitgetTKModifyPosition.node.js.map