n8n-nodes-bitget 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.
Files changed (66) hide show
  1. package/COMMERCIAL_LICENSE.md +31 -0
  2. package/LICENSE +46 -0
  3. package/LICENSING_FAQ.md +18 -0
  4. package/README.md +356 -0
  5. package/dist/credentials/BitgetApi.credentials.d.ts +8 -0
  6. package/dist/credentials/BitgetApi.credentials.d.ts.map +1 -0
  7. package/dist/credentials/BitgetApi.credentials.js +67 -0
  8. package/dist/credentials/BitgetApi.credentials.js.map +1 -0
  9. package/dist/index.d.ts +4 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +26 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/nodes/Bitget/Bitget.node.d.ts +6 -0
  14. package/dist/nodes/Bitget/Bitget.node.d.ts.map +1 -0
  15. package/dist/nodes/Bitget/Bitget.node.js +994 -0
  16. package/dist/nodes/Bitget/Bitget.node.js.map +1 -0
  17. package/dist/nodes/Bitget/BitgetTrigger.node.d.ts +6 -0
  18. package/dist/nodes/Bitget/BitgetTrigger.node.d.ts.map +1 -0
  19. package/dist/nodes/Bitget/BitgetTrigger.node.js +576 -0
  20. package/dist/nodes/Bitget/BitgetTrigger.node.js.map +1 -0
  21. package/dist/nodes/Bitget/actions/copyTrading/index.d.ts +4 -0
  22. package/dist/nodes/Bitget/actions/copyTrading/index.d.ts.map +1 -0
  23. package/dist/nodes/Bitget/actions/copyTrading/index.js +519 -0
  24. package/dist/nodes/Bitget/actions/copyTrading/index.js.map +1 -0
  25. package/dist/nodes/Bitget/actions/earn/index.d.ts +4 -0
  26. package/dist/nodes/Bitget/actions/earn/index.d.ts.map +1 -0
  27. package/dist/nodes/Bitget/actions/earn/index.js +326 -0
  28. package/dist/nodes/Bitget/actions/earn/index.js.map +1 -0
  29. package/dist/nodes/Bitget/actions/futuresAccount/index.d.ts +4 -0
  30. package/dist/nodes/Bitget/actions/futuresAccount/index.d.ts.map +1 -0
  31. package/dist/nodes/Bitget/actions/futuresAccount/index.js +335 -0
  32. package/dist/nodes/Bitget/actions/futuresAccount/index.js.map +1 -0
  33. package/dist/nodes/Bitget/actions/futuresTrading/index.d.ts +4 -0
  34. package/dist/nodes/Bitget/actions/futuresTrading/index.d.ts.map +1 -0
  35. package/dist/nodes/Bitget/actions/futuresTrading/index.js +933 -0
  36. package/dist/nodes/Bitget/actions/futuresTrading/index.js.map +1 -0
  37. package/dist/nodes/Bitget/actions/marketData/index.d.ts +4 -0
  38. package/dist/nodes/Bitget/actions/marketData/index.d.ts.map +1 -0
  39. package/dist/nodes/Bitget/actions/marketData/index.js +303 -0
  40. package/dist/nodes/Bitget/actions/marketData/index.js.map +1 -0
  41. package/dist/nodes/Bitget/actions/spotAccount/index.d.ts +4 -0
  42. package/dist/nodes/Bitget/actions/spotAccount/index.d.ts.map +1 -0
  43. package/dist/nodes/Bitget/actions/spotAccount/index.js +314 -0
  44. package/dist/nodes/Bitget/actions/spotAccount/index.js.map +1 -0
  45. package/dist/nodes/Bitget/actions/spotTrading/index.d.ts +4 -0
  46. package/dist/nodes/Bitget/actions/spotTrading/index.d.ts.map +1 -0
  47. package/dist/nodes/Bitget/actions/spotTrading/index.js +575 -0
  48. package/dist/nodes/Bitget/actions/spotTrading/index.js.map +1 -0
  49. package/dist/nodes/Bitget/bitget.svg +11 -0
  50. package/dist/nodes/Bitget/constants/index.d.ts +90 -0
  51. package/dist/nodes/Bitget/constants/index.d.ts.map +1 -0
  52. package/dist/nodes/Bitget/constants/index.js +127 -0
  53. package/dist/nodes/Bitget/constants/index.js.map +1 -0
  54. package/dist/nodes/Bitget/transport/index.d.ts +22 -0
  55. package/dist/nodes/Bitget/transport/index.d.ts.map +1 -0
  56. package/dist/nodes/Bitget/transport/index.js +267 -0
  57. package/dist/nodes/Bitget/transport/index.js.map +1 -0
  58. package/dist/nodes/Bitget/types/BitgetTypes.d.ts +396 -0
  59. package/dist/nodes/Bitget/types/BitgetTypes.d.ts.map +1 -0
  60. package/dist/nodes/Bitget/types/BitgetTypes.js +74 -0
  61. package/dist/nodes/Bitget/types/BitgetTypes.js.map +1 -0
  62. package/dist/nodes/Bitget/utils/index.d.ts +76 -0
  63. package/dist/nodes/Bitget/utils/index.d.ts.map +1 -0
  64. package/dist/nodes/Bitget/utils/index.js +210 -0
  65. package/dist/nodes/Bitget/utils/index.js.map +1 -0
  66. package/package.json +92 -0
@@ -0,0 +1,994 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Velocity BPA, LLC
4
+ * Licensed under the Business Source License 1.1
5
+ * Commercial use requires a separate commercial license.
6
+ * See LICENSE file for details.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Bitget = void 0;
10
+ const n8n_workflow_1 = require("n8n-workflow");
11
+ const constants_1 = require("./constants");
12
+ const transport_1 = require("./transport");
13
+ const utils_1 = require("./utils");
14
+ // Import action definitions
15
+ const spotAccount_1 = require("./actions/spotAccount");
16
+ const spotTrading_1 = require("./actions/spotTrading");
17
+ const futuresAccount_1 = require("./actions/futuresAccount");
18
+ const futuresTrading_1 = require("./actions/futuresTrading");
19
+ const copyTrading_1 = require("./actions/copyTrading");
20
+ const marketData_1 = require("./actions/marketData");
21
+ const earn_1 = require("./actions/earn");
22
+ class Bitget {
23
+ constructor() {
24
+ this.description = {
25
+ displayName: 'Bitget',
26
+ name: 'bitget',
27
+ icon: 'file:bitget.svg',
28
+ group: ['transform'],
29
+ version: 1,
30
+ subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
31
+ description: 'Interact with Bitget cryptocurrency exchange API',
32
+ defaults: {
33
+ name: 'Bitget',
34
+ },
35
+ inputs: ['main'],
36
+ outputs: ['main'],
37
+ credentials: [
38
+ {
39
+ name: 'bitgetApi',
40
+ required: true,
41
+ },
42
+ ],
43
+ properties: [
44
+ {
45
+ displayName: 'Resource',
46
+ name: 'resource',
47
+ type: 'options',
48
+ noDataExpression: true,
49
+ options: [
50
+ {
51
+ name: 'Copy Trading',
52
+ value: 'copyTrading',
53
+ description: 'Copy trading operations',
54
+ },
55
+ {
56
+ name: 'Earn',
57
+ value: 'earn',
58
+ description: 'Earn products operations',
59
+ },
60
+ {
61
+ name: 'Futures Account',
62
+ value: 'futuresAccount',
63
+ description: 'Futures account operations',
64
+ },
65
+ {
66
+ name: 'Futures Trading',
67
+ value: 'futuresTrading',
68
+ description: 'Futures trading operations',
69
+ },
70
+ {
71
+ name: 'Market Data',
72
+ value: 'marketData',
73
+ description: 'Market data operations',
74
+ },
75
+ {
76
+ name: 'Spot Account',
77
+ value: 'spotAccount',
78
+ description: 'Spot account operations',
79
+ },
80
+ {
81
+ name: 'Spot Trading',
82
+ value: 'spotTrading',
83
+ description: 'Spot trading operations',
84
+ },
85
+ ],
86
+ default: 'spotTrading',
87
+ },
88
+ // Operations
89
+ ...spotAccount_1.spotAccountOperations,
90
+ ...spotTrading_1.spotTradingOperations,
91
+ ...futuresAccount_1.futuresAccountOperations,
92
+ ...futuresTrading_1.futuresTradingOperations,
93
+ ...copyTrading_1.copyTradingOperations,
94
+ ...marketData_1.marketDataOperations,
95
+ ...earn_1.earnOperations,
96
+ // Fields
97
+ ...spotAccount_1.spotAccountFields,
98
+ ...spotTrading_1.spotTradingFields,
99
+ ...futuresAccount_1.futuresAccountFields,
100
+ ...futuresTrading_1.futuresTradingFields,
101
+ ...copyTrading_1.copyTradingFields,
102
+ ...marketData_1.marketDataFields,
103
+ ...earn_1.earnFields,
104
+ ],
105
+ };
106
+ }
107
+ async execute() {
108
+ const items = this.getInputData();
109
+ const returnData = [];
110
+ const resource = this.getNodeParameter('resource', 0);
111
+ const operation = this.getNodeParameter('operation', 0);
112
+ for (let i = 0; i < items.length; i++) {
113
+ try {
114
+ let responseData;
115
+ // Route to appropriate handler based on resource
116
+ switch (resource) {
117
+ case 'spotAccount':
118
+ responseData = await executeSpotAccount.call(this, operation, i);
119
+ break;
120
+ case 'spotTrading':
121
+ responseData = await executeSpotTrading.call(this, operation, i);
122
+ break;
123
+ case 'futuresAccount':
124
+ responseData = await executeFuturesAccount.call(this, operation, i);
125
+ break;
126
+ case 'futuresTrading':
127
+ responseData = await executeFuturesTrading.call(this, operation, i);
128
+ break;
129
+ case 'copyTrading':
130
+ responseData = await executeCopyTrading.call(this, operation, i);
131
+ break;
132
+ case 'marketData':
133
+ responseData = await executeMarketData.call(this, operation, i);
134
+ break;
135
+ case 'earn':
136
+ responseData = await executeEarn.call(this, operation, i);
137
+ break;
138
+ default:
139
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown resource: ${resource}`);
140
+ }
141
+ // Handle response
142
+ if (Array.isArray(responseData)) {
143
+ returnData.push(...responseData.map((item) => ({ json: item })));
144
+ }
145
+ else if (responseData !== null && responseData !== undefined) {
146
+ returnData.push({ json: responseData });
147
+ }
148
+ }
149
+ catch (error) {
150
+ if (this.continueOnFail()) {
151
+ returnData.push({
152
+ json: {
153
+ error: error.message,
154
+ },
155
+ pairedItem: { item: i },
156
+ });
157
+ continue;
158
+ }
159
+ throw error;
160
+ }
161
+ }
162
+ return [returnData];
163
+ }
164
+ }
165
+ exports.Bitget = Bitget;
166
+ // ============================================================================
167
+ // SPOT ACCOUNT OPERATIONS
168
+ // ============================================================================
169
+ async function executeSpotAccount(operation, itemIndex) {
170
+ switch (operation) {
171
+ case 'getBalance': {
172
+ const coin = this.getNodeParameter('coin', itemIndex, '');
173
+ const query = {};
174
+ if (coin)
175
+ query.coin = coin.toUpperCase();
176
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.SPOT_ACCOUNT_ASSETS, {}, query);
177
+ }
178
+ case 'getBills': {
179
+ const coin = this.getNodeParameter('coin', itemIndex, '');
180
+ const groupType = this.getNodeParameter('groupType', itemIndex, '');
181
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
182
+ const query = {};
183
+ if (coin)
184
+ query.coin = coin.toUpperCase();
185
+ if (groupType)
186
+ query.groupType = groupType;
187
+ if (additionalOptions.startTime)
188
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
189
+ if (additionalOptions.endTime)
190
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
191
+ if (additionalOptions.limit)
192
+ query.limit = additionalOptions.limit;
193
+ if (additionalOptions.idLessThan)
194
+ query.idLessThan = additionalOptions.idLessThan;
195
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.SPOT_ACCOUNT_BILLS, {}, query);
196
+ }
197
+ case 'transfer': {
198
+ const fromType = this.getNodeParameter('fromType', itemIndex);
199
+ const toType = this.getNodeParameter('toType', itemIndex);
200
+ const coin = this.getNodeParameter('coin', itemIndex);
201
+ const amount = this.getNodeParameter('size', itemIndex);
202
+ const clientOid = this.getNodeParameter('clientOid', itemIndex, '');
203
+ const body = {
204
+ fromType,
205
+ toType,
206
+ coin: coin.toUpperCase(),
207
+ amount,
208
+ };
209
+ if (clientOid)
210
+ body.clientOid = clientOid;
211
+ return await transport_1.bitgetApiRequestWithRetry.call(this, 'POST', constants_1.ENDPOINTS.SPOT_WALLET_TRANSFER, body);
212
+ }
213
+ case 'getTransferHistory': {
214
+ const coin = this.getNodeParameter('coin', itemIndex, '');
215
+ const fromType = this.getNodeParameter('fromType', itemIndex, '');
216
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
217
+ const query = {};
218
+ if (coin)
219
+ query.coin = coin.toUpperCase();
220
+ if (fromType)
221
+ query.fromType = fromType;
222
+ if (additionalOptions.startTime)
223
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
224
+ if (additionalOptions.endTime)
225
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
226
+ if (additionalOptions.limit)
227
+ query.limit = additionalOptions.limit;
228
+ if (additionalOptions.clientOid)
229
+ query.clientOid = additionalOptions.clientOid;
230
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.SPOT_WALLET_TRANSFER_RECORDS, {}, query);
231
+ }
232
+ default:
233
+ throw new Error(`Unknown operation: ${operation}`);
234
+ }
235
+ }
236
+ // ============================================================================
237
+ // SPOT TRADING OPERATIONS
238
+ // ============================================================================
239
+ async function executeSpotTrading(operation, itemIndex) {
240
+ switch (operation) {
241
+ case 'placeOrder': {
242
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
243
+ const side = this.getNodeParameter('side', itemIndex);
244
+ const orderType = this.getNodeParameter('orderType', itemIndex);
245
+ const size = this.getNodeParameter('size', itemIndex);
246
+ const force = this.getNodeParameter('force', itemIndex, 'GTC');
247
+ const clientOid = this.getNodeParameter('clientOid', itemIndex, '');
248
+ const body = {
249
+ symbol,
250
+ side,
251
+ orderType,
252
+ size,
253
+ force,
254
+ clientOid: clientOid || (0, utils_1.generateClientOrderId)(),
255
+ };
256
+ if (orderType === 'limit') {
257
+ const price = this.getNodeParameter('price', itemIndex);
258
+ body.price = price;
259
+ }
260
+ return await transport_1.bitgetApiRequestWithRetry.call(this, 'POST', constants_1.ENDPOINTS.SPOT_TRADE_PLACE_ORDER, body);
261
+ }
262
+ case 'batchPlaceOrders': {
263
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
264
+ const ordersCollection = this.getNodeParameter('orders', itemIndex, {});
265
+ const orders = ordersCollection.order || [];
266
+ if (orders.length === 0) {
267
+ throw new Error('At least one order is required');
268
+ }
269
+ if (orders.length > 50) {
270
+ throw new Error('Maximum 50 orders per batch');
271
+ }
272
+ const orderList = orders.map((order, index) => ({
273
+ side: order.side,
274
+ orderType: order.orderType,
275
+ size: order.size,
276
+ price: order.price,
277
+ force: order.force || 'GTC',
278
+ clientOid: order.clientOid || (0, utils_1.generateClientOrderId)(`batch${index}`),
279
+ }));
280
+ const body = {
281
+ symbol,
282
+ orderList,
283
+ };
284
+ return await transport_1.bitgetApiRequestWithRetry.call(this, 'POST', constants_1.ENDPOINTS.SPOT_TRADE_BATCH_ORDERS, body);
285
+ }
286
+ case 'cancelOrder': {
287
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
288
+ const orderId = this.getNodeParameter('orderId', itemIndex, '');
289
+ const clientOid = this.getNodeParameter('clientOid', itemIndex, '');
290
+ if (!orderId && !clientOid) {
291
+ throw new Error('Either Order ID or Client Order ID is required');
292
+ }
293
+ const body = { symbol };
294
+ if (orderId)
295
+ body.orderId = orderId;
296
+ if (clientOid)
297
+ body.clientOid = clientOid;
298
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.SPOT_TRADE_CANCEL_ORDER, body);
299
+ }
300
+ case 'batchCancelOrders': {
301
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
302
+ const orderIds = this.getNodeParameter('orderIds', itemIndex, '');
303
+ const body = { symbol };
304
+ if (orderIds) {
305
+ body.orderIds = orderIds.split(',').map((id) => id.trim());
306
+ }
307
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.SPOT_TRADE_BATCH_CANCEL, body);
308
+ }
309
+ case 'getOpenOrders': {
310
+ const symbol = this.getNodeParameter('symbol', itemIndex, '');
311
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
312
+ const query = {};
313
+ if (symbol)
314
+ query.symbol = (0, utils_1.formatSymbol)(symbol);
315
+ if (additionalOptions.startTime)
316
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
317
+ if (additionalOptions.endTime)
318
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
319
+ if (additionalOptions.limit)
320
+ query.limit = additionalOptions.limit;
321
+ if (additionalOptions.orderType)
322
+ query.orderType = additionalOptions.orderType;
323
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.SPOT_TRADE_OPEN_ORDERS, {}, query);
324
+ }
325
+ case 'getOrderHistory': {
326
+ const symbol = this.getNodeParameter('symbol', itemIndex, '');
327
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
328
+ const query = {};
329
+ if (symbol)
330
+ query.symbol = (0, utils_1.formatSymbol)(symbol);
331
+ if (additionalOptions.startTime)
332
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
333
+ if (additionalOptions.endTime)
334
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
335
+ if (additionalOptions.limit)
336
+ query.limit = additionalOptions.limit;
337
+ if (additionalOptions.idLessThan)
338
+ query.idLessThan = additionalOptions.idLessThan;
339
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.SPOT_TRADE_HISTORY_ORDERS, {}, query);
340
+ }
341
+ case 'getOrderDetail': {
342
+ const orderId = this.getNodeParameter('orderId', itemIndex, '');
343
+ const clientOid = this.getNodeParameter('clientOid', itemIndex, '');
344
+ if (!orderId && !clientOid) {
345
+ throw new Error('Either Order ID or Client Order ID is required');
346
+ }
347
+ const query = {};
348
+ if (orderId)
349
+ query.orderId = orderId;
350
+ if (clientOid)
351
+ query.clientOid = clientOid;
352
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.SPOT_TRADE_ORDER_INFO, {}, query);
353
+ }
354
+ case 'getFills': {
355
+ const symbol = this.getNodeParameter('symbol', itemIndex, '');
356
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
357
+ const query = {};
358
+ if (symbol)
359
+ query.symbol = (0, utils_1.formatSymbol)(symbol);
360
+ if (additionalOptions.orderId)
361
+ query.orderId = additionalOptions.orderId;
362
+ if (additionalOptions.startTime)
363
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
364
+ if (additionalOptions.endTime)
365
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
366
+ if (additionalOptions.limit)
367
+ query.limit = additionalOptions.limit;
368
+ if (additionalOptions.idLessThan)
369
+ query.idLessThan = additionalOptions.idLessThan;
370
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.SPOT_TRADE_FILLS, {}, query);
371
+ }
372
+ default:
373
+ throw new Error(`Unknown operation: ${operation}`);
374
+ }
375
+ }
376
+ // ============================================================================
377
+ // FUTURES ACCOUNT OPERATIONS
378
+ // ============================================================================
379
+ async function executeFuturesAccount(operation, itemIndex) {
380
+ switch (operation) {
381
+ case 'getAccount': {
382
+ const productType = this.getNodeParameter('productType', itemIndex);
383
+ const marginCoin = this.getNodeParameter('marginCoin', itemIndex, '');
384
+ const query = { productType };
385
+ if (marginCoin)
386
+ query.marginCoin = marginCoin.toUpperCase();
387
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.FUTURES_ACCOUNT, {}, query);
388
+ }
389
+ case 'getPositions': {
390
+ const productType = this.getNodeParameter('productType', itemIndex);
391
+ const marginCoin = this.getNodeParameter('marginCoin', itemIndex, '');
392
+ const query = { productType };
393
+ if (marginCoin)
394
+ query.marginCoin = marginCoin.toUpperCase();
395
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.FUTURES_POSITIONS, {}, query);
396
+ }
397
+ case 'getSinglePosition': {
398
+ const productType = this.getNodeParameter('productType', itemIndex);
399
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
400
+ const marginCoin = this.getNodeParameter('marginCoin', itemIndex);
401
+ const query = {
402
+ productType,
403
+ symbol,
404
+ marginCoin: marginCoin.toUpperCase(),
405
+ };
406
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.FUTURES_SINGLE_POSITION, {}, query);
407
+ }
408
+ case 'setLeverage': {
409
+ const productType = this.getNodeParameter('productType', itemIndex);
410
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
411
+ const marginCoin = this.getNodeParameter('marginCoin', itemIndex);
412
+ const leverage = this.getNodeParameter('leverage', itemIndex);
413
+ const holdSide = this.getNodeParameter('holdSide', itemIndex, '');
414
+ const body = {
415
+ productType,
416
+ symbol,
417
+ marginCoin: marginCoin.toUpperCase(),
418
+ leverage: leverage.toString(),
419
+ };
420
+ if (holdSide)
421
+ body.holdSide = holdSide;
422
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.FUTURES_SET_LEVERAGE, body);
423
+ }
424
+ case 'setMarginMode': {
425
+ const productType = this.getNodeParameter('productType', itemIndex);
426
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
427
+ const marginCoin = this.getNodeParameter('marginCoin', itemIndex);
428
+ const marginMode = this.getNodeParameter('marginMode', itemIndex);
429
+ const body = {
430
+ productType,
431
+ symbol,
432
+ marginCoin: marginCoin.toUpperCase(),
433
+ marginMode,
434
+ };
435
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.FUTURES_SET_MARGIN_MODE, body);
436
+ }
437
+ case 'getBills': {
438
+ const productType = this.getNodeParameter('productType', itemIndex);
439
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
440
+ const query = { productType };
441
+ if (additionalOptions.coin)
442
+ query.coin = additionalOptions.coin.toUpperCase();
443
+ if (additionalOptions.businessType)
444
+ query.businessType = additionalOptions.businessType;
445
+ if (additionalOptions.startTime)
446
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
447
+ if (additionalOptions.endTime)
448
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
449
+ if (additionalOptions.limit)
450
+ query.limit = additionalOptions.limit;
451
+ if (additionalOptions.idLessThan)
452
+ query.idLessThan = additionalOptions.idLessThan;
453
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.FUTURES_BILLS, {}, query);
454
+ }
455
+ default:
456
+ throw new Error(`Unknown operation: ${operation}`);
457
+ }
458
+ }
459
+ // ============================================================================
460
+ // FUTURES TRADING OPERATIONS
461
+ // ============================================================================
462
+ async function executeFuturesTrading(operation, itemIndex) {
463
+ switch (operation) {
464
+ case 'placeOrder': {
465
+ const productType = this.getNodeParameter('productType', itemIndex);
466
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
467
+ const marginCoin = this.getNodeParameter('marginCoin', itemIndex);
468
+ const side = this.getNodeParameter('side', itemIndex);
469
+ const orderType = this.getNodeParameter('orderType', itemIndex);
470
+ const size = this.getNodeParameter('size', itemIndex);
471
+ const tradeSide = this.getNodeParameter('tradeSide', itemIndex, '');
472
+ const clientOid = this.getNodeParameter('clientOid', itemIndex, '');
473
+ const body = {
474
+ productType,
475
+ symbol,
476
+ marginCoin: marginCoin.toUpperCase(),
477
+ side,
478
+ orderType,
479
+ size,
480
+ clientOid: clientOid || (0, utils_1.generateClientOrderId)('futures'),
481
+ };
482
+ if (tradeSide)
483
+ body.tradeSide = tradeSide;
484
+ if (orderType === 'limit') {
485
+ const price = this.getNodeParameter('price', itemIndex);
486
+ const force = this.getNodeParameter('force', itemIndex, 'GTC');
487
+ body.price = price;
488
+ body.force = force;
489
+ }
490
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
491
+ if (additionalOptions.reduceOnly)
492
+ body.reduceOnly = additionalOptions.reduceOnly;
493
+ if (additionalOptions.presetStopSurplusPrice)
494
+ body.presetStopSurplusPrice = additionalOptions.presetStopSurplusPrice;
495
+ if (additionalOptions.presetStopLossPrice)
496
+ body.presetStopLossPrice = additionalOptions.presetStopLossPrice;
497
+ return await transport_1.bitgetApiRequestWithRetry.call(this, 'POST', constants_1.ENDPOINTS.FUTURES_PLACE_ORDER, body);
498
+ }
499
+ case 'batchPlaceOrders': {
500
+ const productType = this.getNodeParameter('productType', itemIndex);
501
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
502
+ const marginCoin = this.getNodeParameter('marginCoin', itemIndex);
503
+ const ordersCollection = this.getNodeParameter('orders', itemIndex, {});
504
+ const orders = ordersCollection.order || [];
505
+ if (orders.length === 0) {
506
+ throw new Error('At least one order is required');
507
+ }
508
+ if (orders.length > 50) {
509
+ throw new Error('Maximum 50 orders per batch');
510
+ }
511
+ const orderList = orders.map((order, index) => ({
512
+ side: order.side,
513
+ orderType: order.orderType,
514
+ size: order.size,
515
+ price: order.price,
516
+ tradeSide: order.tradeSide,
517
+ clientOid: order.clientOid || (0, utils_1.generateClientOrderId)(`fbatch${index}`),
518
+ }));
519
+ const body = {
520
+ productType,
521
+ symbol,
522
+ marginCoin: marginCoin.toUpperCase(),
523
+ orderList,
524
+ };
525
+ return await transport_1.bitgetApiRequestWithRetry.call(this, 'POST', constants_1.ENDPOINTS.FUTURES_BATCH_ORDERS, body);
526
+ }
527
+ case 'modifyOrder': {
528
+ const productType = this.getNodeParameter('productType', itemIndex);
529
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
530
+ const orderId = this.getNodeParameter('orderId', itemIndex, '');
531
+ const clientOid = this.getNodeParameter('clientOid', itemIndex, '');
532
+ if (!orderId && !clientOid) {
533
+ throw new Error('Either Order ID or Client Order ID is required');
534
+ }
535
+ const body = {
536
+ productType,
537
+ symbol,
538
+ };
539
+ if (orderId)
540
+ body.orderId = orderId;
541
+ if (clientOid)
542
+ body.clientOid = clientOid;
543
+ const newPrice = this.getNodeParameter('newPrice', itemIndex, '');
544
+ const newSize = this.getNodeParameter('newSize', itemIndex, '');
545
+ if (newPrice)
546
+ body.newPrice = newPrice;
547
+ if (newSize)
548
+ body.newSize = newSize;
549
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.FUTURES_MODIFY_ORDER, body);
550
+ }
551
+ case 'cancelOrder': {
552
+ const productType = this.getNodeParameter('productType', itemIndex);
553
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
554
+ const orderId = this.getNodeParameter('orderId', itemIndex, '');
555
+ const clientOid = this.getNodeParameter('clientOid', itemIndex, '');
556
+ if (!orderId && !clientOid) {
557
+ throw new Error('Either Order ID or Client Order ID is required');
558
+ }
559
+ const body = {
560
+ productType,
561
+ symbol,
562
+ };
563
+ if (orderId)
564
+ body.orderId = orderId;
565
+ if (clientOid)
566
+ body.clientOid = clientOid;
567
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.FUTURES_CANCEL_ORDER, body);
568
+ }
569
+ case 'cancelAllOrders': {
570
+ const productType = this.getNodeParameter('productType', itemIndex);
571
+ const symbol = this.getNodeParameter('symbol', itemIndex, '');
572
+ const marginCoin = this.getNodeParameter('marginCoin', itemIndex, '');
573
+ const body = { productType };
574
+ if (symbol)
575
+ body.symbol = (0, utils_1.formatSymbol)(symbol);
576
+ if (marginCoin)
577
+ body.marginCoin = marginCoin.toUpperCase();
578
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.FUTURES_CANCEL_ALL_ORDERS, body);
579
+ }
580
+ case 'getOpenOrders': {
581
+ const productType = this.getNodeParameter('productType', itemIndex);
582
+ const symbol = this.getNodeParameter('symbol', itemIndex, '');
583
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
584
+ const query = { productType };
585
+ if (symbol)
586
+ query.symbol = (0, utils_1.formatSymbol)(symbol);
587
+ if (additionalOptions.orderId)
588
+ query.orderId = additionalOptions.orderId;
589
+ if (additionalOptions.clientOid)
590
+ query.clientOid = additionalOptions.clientOid;
591
+ if (additionalOptions.limit)
592
+ query.limit = additionalOptions.limit;
593
+ if (additionalOptions.idLessThan)
594
+ query.idLessThan = additionalOptions.idLessThan;
595
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.FUTURES_OPEN_ORDERS, {}, query);
596
+ }
597
+ case 'getOrderHistory': {
598
+ const productType = this.getNodeParameter('productType', itemIndex);
599
+ const symbol = this.getNodeParameter('symbol', itemIndex, '');
600
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
601
+ const query = { productType };
602
+ if (symbol)
603
+ query.symbol = (0, utils_1.formatSymbol)(symbol);
604
+ if (additionalOptions.startTime)
605
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
606
+ if (additionalOptions.endTime)
607
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
608
+ if (additionalOptions.limit)
609
+ query.limit = additionalOptions.limit;
610
+ if (additionalOptions.idLessThan)
611
+ query.idLessThan = additionalOptions.idLessThan;
612
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.FUTURES_HISTORY_ORDERS, {}, query);
613
+ }
614
+ case 'getFills': {
615
+ const productType = this.getNodeParameter('productType', itemIndex);
616
+ const symbol = this.getNodeParameter('symbol', itemIndex, '');
617
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
618
+ const query = { productType };
619
+ if (symbol)
620
+ query.symbol = (0, utils_1.formatSymbol)(symbol);
621
+ if (additionalOptions.orderId)
622
+ query.orderId = additionalOptions.orderId;
623
+ if (additionalOptions.startTime)
624
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
625
+ if (additionalOptions.endTime)
626
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
627
+ if (additionalOptions.limit)
628
+ query.limit = additionalOptions.limit;
629
+ if (additionalOptions.idLessThan)
630
+ query.idLessThan = additionalOptions.idLessThan;
631
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.FUTURES_FILLS, {}, query);
632
+ }
633
+ case 'placePlanOrder': {
634
+ const productType = this.getNodeParameter('productType', itemIndex);
635
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
636
+ const marginCoin = this.getNodeParameter('marginCoin', itemIndex);
637
+ const side = this.getNodeParameter('side', itemIndex);
638
+ const size = this.getNodeParameter('size', itemIndex);
639
+ const triggerPrice = this.getNodeParameter('triggerPrice', itemIndex);
640
+ const triggerType = this.getNodeParameter('triggerType', itemIndex);
641
+ const orderType = this.getNodeParameter('orderType', itemIndex);
642
+ const clientOid = this.getNodeParameter('clientOid', itemIndex, '');
643
+ const body = {
644
+ productType,
645
+ symbol,
646
+ marginCoin: marginCoin.toUpperCase(),
647
+ side,
648
+ size,
649
+ triggerPrice,
650
+ triggerType,
651
+ orderType,
652
+ clientOid: clientOid || (0, utils_1.generateClientOrderId)('plan'),
653
+ };
654
+ if (orderType === 'limit') {
655
+ const executePrice = this.getNodeParameter('executePrice', itemIndex);
656
+ body.executePrice = executePrice;
657
+ }
658
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
659
+ if (additionalOptions.tradeSide)
660
+ body.tradeSide = additionalOptions.tradeSide;
661
+ if (additionalOptions.reduceOnly)
662
+ body.reduceOnly = additionalOptions.reduceOnly;
663
+ return await transport_1.bitgetApiRequestWithRetry.call(this, 'POST', constants_1.ENDPOINTS.FUTURES_PLACE_PLAN_ORDER, body);
664
+ }
665
+ case 'cancelPlanOrder': {
666
+ const productType = this.getNodeParameter('productType', itemIndex);
667
+ const orderId = this.getNodeParameter('orderId', itemIndex, '');
668
+ const clientOid = this.getNodeParameter('clientOid', itemIndex, '');
669
+ if (!orderId && !clientOid) {
670
+ throw new Error('Either Order ID or Client Order ID is required');
671
+ }
672
+ const body = { productType };
673
+ if (orderId)
674
+ body.orderId = orderId;
675
+ if (clientOid)
676
+ body.clientOid = clientOid;
677
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.FUTURES_CANCEL_PLAN_ORDER, body);
678
+ }
679
+ case 'getPlanOrders': {
680
+ const productType = this.getNodeParameter('productType', itemIndex);
681
+ const symbol = this.getNodeParameter('symbol', itemIndex, '');
682
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
683
+ const query = { productType };
684
+ if (symbol)
685
+ query.symbol = (0, utils_1.formatSymbol)(symbol);
686
+ if (additionalOptions.planType)
687
+ query.planType = additionalOptions.planType;
688
+ if (additionalOptions.limit)
689
+ query.limit = additionalOptions.limit;
690
+ if (additionalOptions.idLessThan)
691
+ query.idLessThan = additionalOptions.idLessThan;
692
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.FUTURES_PLAN_ORDERS, {}, query);
693
+ }
694
+ default:
695
+ throw new Error(`Unknown operation: ${operation}`);
696
+ }
697
+ }
698
+ // ============================================================================
699
+ // COPY TRADING OPERATIONS
700
+ // ============================================================================
701
+ async function executeCopyTrading(operation, itemIndex) {
702
+ switch (operation) {
703
+ case 'getTraders': {
704
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
705
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
706
+ const query = { productType };
707
+ if (additionalOptions.pageNo)
708
+ query.pageNo = additionalOptions.pageNo;
709
+ if (additionalOptions.pageSize)
710
+ query.pageSize = additionalOptions.pageSize;
711
+ if (additionalOptions.sortBy)
712
+ query.sortBy = additionalOptions.sortBy;
713
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.COPY_TRADERS, {}, query);
714
+ }
715
+ case 'getTraderPositions': {
716
+ const traderId = this.getNodeParameter('traderId', itemIndex);
717
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
718
+ const query = {
719
+ traderId,
720
+ productType,
721
+ };
722
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.COPY_TRADER_POSITIONS, {}, query);
723
+ }
724
+ case 'followTrader': {
725
+ const traderId = this.getNodeParameter('traderId', itemIndex);
726
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
727
+ const copyMode = this.getNodeParameter('copyMode', itemIndex);
728
+ const copyTradeCoin = this.getNodeParameter('copyTradeCoin', itemIndex);
729
+ const body = {
730
+ traderId,
731
+ productType,
732
+ copyTradeCoin: copyTradeCoin.toUpperCase(),
733
+ };
734
+ if (copyMode === 'fixedAmount') {
735
+ const fixedAmount = this.getNodeParameter('fixedAmount', itemIndex);
736
+ body.fixedAmount = fixedAmount;
737
+ }
738
+ else {
739
+ const copyRatio = this.getNodeParameter('copyRatio', itemIndex);
740
+ body.copyRatio = copyRatio.toString();
741
+ }
742
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
743
+ if (additionalOptions.maxFollowAmount)
744
+ body.maxFollowAmount = additionalOptions.maxFollowAmount;
745
+ if (additionalOptions.totalLimit)
746
+ body.totalLimit = additionalOptions.totalLimit;
747
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.COPY_FOLLOW_TRADER, body);
748
+ }
749
+ case 'unfollowTrader': {
750
+ const traderId = this.getNodeParameter('traderId', itemIndex);
751
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
752
+ const body = {
753
+ traderId,
754
+ productType,
755
+ };
756
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.COPY_UNFOLLOW_TRADER, body);
757
+ }
758
+ case 'getFollowSettings': {
759
+ const traderId = this.getNodeParameter('traderId', itemIndex);
760
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
761
+ const query = {
762
+ traderId,
763
+ productType,
764
+ };
765
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.COPY_FOLLOW_SETTINGS, {}, query);
766
+ }
767
+ case 'updateFollowSettings': {
768
+ const traderId = this.getNodeParameter('traderId', itemIndex);
769
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
770
+ const settings = this.getNodeParameter('settings', itemIndex, {});
771
+ const body = {
772
+ traderId,
773
+ productType,
774
+ };
775
+ if (settings.fixedAmount)
776
+ body.fixedAmount = settings.fixedAmount;
777
+ if (settings.copyRatio)
778
+ body.copyRatio = settings.copyRatio;
779
+ if (settings.maxFollowAmount)
780
+ body.maxFollowAmount = settings.maxFollowAmount;
781
+ if (settings.totalLimit)
782
+ body.totalLimit = settings.totalLimit;
783
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.COPY_UPDATE_SETTINGS, body);
784
+ }
785
+ case 'getFollowerHistory': {
786
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
787
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
788
+ const query = { productType };
789
+ if (additionalOptions.traderId)
790
+ query.traderId = additionalOptions.traderId;
791
+ if (additionalOptions.symbol)
792
+ query.symbol = (0, utils_1.formatSymbol)(additionalOptions.symbol);
793
+ if (additionalOptions.startTime)
794
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
795
+ if (additionalOptions.endTime)
796
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
797
+ if (additionalOptions.limit)
798
+ query.limit = additionalOptions.limit;
799
+ if (additionalOptions.idLessThan)
800
+ query.idLessThan = additionalOptions.idLessThan;
801
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.COPY_FOLLOWER_HISTORY, {}, query);
802
+ }
803
+ case 'closeFollowerPosition': {
804
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
805
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
806
+ const traderId = this.getNodeParameter('traderId', itemIndex);
807
+ const holdSide = this.getNodeParameter('holdSide', itemIndex);
808
+ const body = {
809
+ productType,
810
+ symbol,
811
+ traderId,
812
+ holdSide,
813
+ };
814
+ return await transport_1.bitgetApiRequest.call(this, 'POST', constants_1.ENDPOINTS.COPY_CLOSE_POSITION, body);
815
+ }
816
+ default:
817
+ throw new Error(`Unknown operation: ${operation}`);
818
+ }
819
+ }
820
+ // ============================================================================
821
+ // MARKET DATA OPERATIONS
822
+ // ============================================================================
823
+ async function executeMarketData(operation, itemIndex) {
824
+ switch (operation) {
825
+ case 'getTickers': {
826
+ const marketType = this.getNodeParameter('marketType', itemIndex, 'spot');
827
+ const endpoint = marketType === 'spot'
828
+ ? constants_1.ENDPOINTS.MARKET_TICKERS
829
+ : constants_1.ENDPOINTS.FUTURES_MARKET_TICKERS;
830
+ const query = {};
831
+ if (marketType !== 'spot') {
832
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
833
+ query.productType = productType;
834
+ }
835
+ return await transport_1.bitgetPublicApiRequest.call(this, 'GET', endpoint, query);
836
+ }
837
+ case 'getTicker': {
838
+ const marketType = this.getNodeParameter('marketType', itemIndex, 'spot');
839
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
840
+ const endpoint = marketType === 'spot'
841
+ ? constants_1.ENDPOINTS.MARKET_TICKER
842
+ : constants_1.ENDPOINTS.FUTURES_MARKET_TICKER;
843
+ const query = { symbol };
844
+ if (marketType !== 'spot') {
845
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
846
+ query.productType = productType;
847
+ }
848
+ return await transport_1.bitgetPublicApiRequest.call(this, 'GET', endpoint, query);
849
+ }
850
+ case 'getOrderBook': {
851
+ const marketType = this.getNodeParameter('marketType', itemIndex, 'spot');
852
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
853
+ const limit = this.getNodeParameter('limit', itemIndex, 15);
854
+ const endpoint = marketType === 'spot'
855
+ ? constants_1.ENDPOINTS.MARKET_ORDERBOOK
856
+ : constants_1.ENDPOINTS.FUTURES_MARKET_ORDERBOOK;
857
+ const query = {
858
+ symbol,
859
+ limit: limit.toString(),
860
+ };
861
+ if (marketType !== 'spot') {
862
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
863
+ query.productType = productType;
864
+ }
865
+ return await transport_1.bitgetPublicApiRequest.call(this, 'GET', endpoint, query);
866
+ }
867
+ case 'getCandles': {
868
+ const marketType = this.getNodeParameter('marketType', itemIndex, 'spot');
869
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
870
+ const granularity = this.getNodeParameter('granularity', itemIndex);
871
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
872
+ const endpoint = marketType === 'spot'
873
+ ? constants_1.ENDPOINTS.MARKET_CANDLES
874
+ : constants_1.ENDPOINTS.FUTURES_MARKET_CANDLES;
875
+ const query = {
876
+ symbol,
877
+ granularity,
878
+ };
879
+ if (marketType !== 'spot') {
880
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
881
+ query.productType = productType;
882
+ }
883
+ if (additionalOptions.startTime)
884
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
885
+ if (additionalOptions.endTime)
886
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
887
+ if (additionalOptions.limit)
888
+ query.limit = additionalOptions.limit;
889
+ return await transport_1.bitgetPublicApiRequest.call(this, 'GET', endpoint, query);
890
+ }
891
+ case 'getTrades': {
892
+ const marketType = this.getNodeParameter('marketType', itemIndex, 'spot');
893
+ const symbol = (0, utils_1.formatSymbol)(this.getNodeParameter('symbol', itemIndex));
894
+ const limit = this.getNodeParameter('limit', itemIndex, 100);
895
+ const endpoint = marketType === 'spot'
896
+ ? constants_1.ENDPOINTS.MARKET_TRADES
897
+ : constants_1.ENDPOINTS.FUTURES_MARKET_TRADES;
898
+ const query = {
899
+ symbol,
900
+ limit: limit.toString(),
901
+ };
902
+ if (marketType !== 'spot') {
903
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
904
+ query.productType = productType;
905
+ }
906
+ return await transport_1.bitgetPublicApiRequest.call(this, 'GET', endpoint, query);
907
+ }
908
+ case 'getSymbols': {
909
+ const marketType = this.getNodeParameter('marketType', itemIndex, 'spot');
910
+ const endpoint = marketType === 'spot'
911
+ ? constants_1.ENDPOINTS.MARKET_SYMBOLS
912
+ : constants_1.ENDPOINTS.FUTURES_MARKET_SYMBOLS;
913
+ const query = {};
914
+ if (marketType !== 'spot') {
915
+ const productType = this.getNodeParameter('productType', itemIndex, 'USDT-FUTURES');
916
+ query.productType = productType;
917
+ }
918
+ return await transport_1.bitgetPublicApiRequest.call(this, 'GET', endpoint, query);
919
+ }
920
+ case 'getServerTime': {
921
+ return await transport_1.bitgetPublicApiRequest.call(this, 'GET', constants_1.ENDPOINTS.MARKET_SERVER_TIME);
922
+ }
923
+ default:
924
+ throw new Error(`Unknown operation: ${operation}`);
925
+ }
926
+ }
927
+ // ============================================================================
928
+ // EARN OPERATIONS
929
+ // ============================================================================
930
+ async function executeEarn(operation, itemIndex) {
931
+ switch (operation) {
932
+ case 'getProducts': {
933
+ const coin = this.getNodeParameter('coin', itemIndex, '');
934
+ const periodType = this.getNodeParameter('periodType', itemIndex, '');
935
+ const query = {};
936
+ if (coin)
937
+ query.coin = coin.toUpperCase();
938
+ if (periodType)
939
+ query.periodType = periodType;
940
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.EARN_PRODUCTS, {}, query);
941
+ }
942
+ case 'subscribe': {
943
+ const productId = this.getNodeParameter('productId', itemIndex);
944
+ const amount = this.getNodeParameter('amount', itemIndex);
945
+ const body = {
946
+ productId,
947
+ amount,
948
+ };
949
+ return await transport_1.bitgetApiRequestWithRetry.call(this, 'POST', constants_1.ENDPOINTS.EARN_SUBSCRIBE, body);
950
+ }
951
+ case 'redeem': {
952
+ const productId = this.getNodeParameter('productId', itemIndex);
953
+ const amount = this.getNodeParameter('amount', itemIndex);
954
+ const body = {
955
+ productId,
956
+ amount,
957
+ };
958
+ return await transport_1.bitgetApiRequestWithRetry.call(this, 'POST', constants_1.ENDPOINTS.EARN_REDEEM, body);
959
+ }
960
+ case 'getSubscriptions': {
961
+ const coin = this.getNodeParameter('coin', itemIndex, '');
962
+ const productId = this.getNodeParameter('productId', itemIndex, '');
963
+ const query = {};
964
+ if (coin)
965
+ query.coin = coin.toUpperCase();
966
+ if (productId)
967
+ query.productId = productId;
968
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.EARN_SUBSCRIPTIONS, {}, query);
969
+ }
970
+ case 'getHistory': {
971
+ const coin = this.getNodeParameter('coin', itemIndex, '');
972
+ const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
973
+ const query = {};
974
+ if (coin)
975
+ query.coin = coin.toUpperCase();
976
+ if (additionalOptions.productId)
977
+ query.productId = additionalOptions.productId;
978
+ if (additionalOptions.operationType)
979
+ query.operationType = additionalOptions.operationType;
980
+ if (additionalOptions.startTime)
981
+ query.startTime = (0, utils_1.toTimestamp)(additionalOptions.startTime);
982
+ if (additionalOptions.endTime)
983
+ query.endTime = (0, utils_1.toTimestamp)(additionalOptions.endTime);
984
+ if (additionalOptions.limit)
985
+ query.limit = additionalOptions.limit;
986
+ if (additionalOptions.idLessThan)
987
+ query.idLessThan = additionalOptions.idLessThan;
988
+ return await transport_1.bitgetApiRequest.call(this, 'GET', constants_1.ENDPOINTS.EARN_HISTORY, {}, query);
989
+ }
990
+ default:
991
+ throw new Error(`Unknown operation: ${operation}`);
992
+ }
993
+ }
994
+ //# sourceMappingURL=Bitget.node.js.map