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.
package/README.md ADDED
@@ -0,0 +1,254 @@
1
+ # SunX Perps n8n Node - Project Summary
2
+
3
+ ## Overview
4
+ Complete n8n community node implementation for SunX Perpetual Futures API with all requested features.
5
+
6
+ ## ✅ Implemented Features
7
+
8
+ ### Account Operations (2)
9
+ 1. ✅ Get Account Balance
10
+ 2. ✅ Get Trading Bills
11
+
12
+ ### Market Data Operations (7)
13
+ 1. ✅ Get Contract Info
14
+ 2. ✅ Get Swap Index Price
15
+ 3. ✅ Get Leverage Info (Risk Limit)
16
+ 4. ✅ Get Funding Rate
17
+ 5. ✅ Get Historical Funding Rate
18
+ 6. ✅ Get Multi-Asset Collateral
19
+ 7. ✅ Get Fee Info
20
+
21
+ ### Order Operations (10)
22
+ 1. ✅ Place Order
23
+ 2. ✅ Place Multiple Orders
24
+ 3. ✅ Cancel Order
25
+ 4. ✅ Cancel Multiple Orders
26
+ 5. ✅ Cancel All Orders
27
+ 6. ✅ Close Symbol at Market Price
28
+ 7. ✅ Close All at Market Price
29
+ 8. ✅ Get Current Orders
30
+ 9. ✅ Get Order History
31
+ 10. ✅ Get Order Info
32
+
33
+ ### Position Operations (4)
34
+ 1. ✅ Get Current Position
35
+ 2. ✅ Set Leverage
36
+ 3. ✅ Get Position Mode
37
+ 4. ✅ Set Position Mode
38
+
39
+ **Total: 23 Operations Implemented**
40
+
41
+ ## 📁 Project Structure
42
+
43
+ ```
44
+ n8n-nodes-sunx-perps/
45
+ ├── credentials/
46
+ │ └── SunxPerpsApi.credentials.ts # API authentication
47
+ ├── nodes/
48
+ │ └── SunxPerps/
49
+ │ ├── SunxPerps.node.ts # Main node with all operations
50
+ │ ├── SunxPerpsUtils.ts # Auth & API utilities
51
+ │ └── sunx.svg # Node icon
52
+ ├── .github/
53
+ │ ├── workflows/
54
+ │ │ └── ci.yml # CI/CD pipeline
55
+ │ └── ISSUE_TEMPLATE/
56
+ │ ├── bug_report.md
57
+ │ └── feature_request.md
58
+ ├── package.json # Dependencies & scripts
59
+ ├── tsconfig.json # TypeScript config
60
+ ├── gulpfile.js # Build scripts
61
+ ├── .eslintrc.js # Linting rules
62
+ ├── .prettierrc.js # Code formatting
63
+ ├── .gitignore
64
+ ├── .npmignore
65
+ ├── README.md # User documentation
66
+ ├── DEVELOPMENT.md # Developer guide
67
+ ├── TESTING.md # Testing guide
68
+ ├── CHANGELOG.md # Version history
69
+ ├── LICENSE.md # MIT License
70
+ └── example-workflow.json # Example n8n workflow
71
+ ```
72
+
73
+ ## 🔑 Key Features
74
+
75
+ ### Authentication
76
+ - ✅ HMAC SHA256 signature generation
77
+ - ✅ Automatic timestamp handling
78
+ - ✅ Full SunX API v2 authentication support
79
+ - ✅ Secure credential storage
80
+
81
+ ### Error Handling
82
+ - ✅ Comprehensive error messages
83
+ - ✅ API error parsing
84
+ - ✅ Continue on fail support
85
+ - ✅ Detailed error context
86
+
87
+ ### API Coverage
88
+ - ✅ All public endpoints (no auth required)
89
+ - ✅ All authenticated endpoints
90
+ - ✅ Query string parameter support
91
+ - ✅ Request body support for POST/PUT
92
+
93
+ ### Developer Experience
94
+ - ✅ TypeScript with full type safety
95
+ - ✅ ESLint configuration
96
+ - ✅ Prettier formatting
97
+ - ✅ Build scripts
98
+ - ✅ Development mode (watch)
99
+
100
+ ## 📦 Files Created
101
+
102
+ ### Core Implementation (5 files)
103
+ 1. `credentials/SunxPerpsApi.credentials.ts` - API credential configuration
104
+ 2. `nodes/SunxPerps/SunxPerps.node.ts` - Main node with all 23 operations
105
+ 3. `nodes/SunxPerps/SunxPerpsUtils.ts` - Authentication & HTTP utilities
106
+ 4. `nodes/SunxPerps/sunx.svg` - Custom node icon
107
+ 5. `gulpfile.js` - Icon build script
108
+
109
+ ### Configuration (7 files)
110
+ 1. `package.json` - NPM package configuration
111
+ 2. `tsconfig.json` - TypeScript compiler options
112
+ 3. `.eslintrc.js` - ESLint rules
113
+ 4. `.prettierrc.js` - Code formatting rules
114
+ 5. `.gitignore` - Git exclusions
115
+ 6. `.npmignore` - NPM publish exclusions
116
+ 7. `LICENSE.md` - MIT License
117
+
118
+ ### Documentation (5 files)
119
+ 1. `README.md` - Installation & usage guide
120
+ 2. `DEVELOPMENT.md` - Developer documentation
121
+ 3. `TESTING.md` - Comprehensive testing guide
122
+ 4. `CHANGELOG.md` - Version history
123
+ 5. `example-workflow.json` - Sample n8n workflow
124
+
125
+ ### CI/CD & Templates (3 files)
126
+ 1. `.github/workflows/ci.yml` - GitHub Actions workflow
127
+ 2. `.github/ISSUE_TEMPLATE/bug_report.md` - Bug report template
128
+ 3. `.github/ISSUE_TEMPLATE/feature_request.md` - Feature request template
129
+
130
+ **Total: 20 Files Created**
131
+
132
+ ## 🚀 Installation & Usage
133
+
134
+ ### Quick Start
135
+
136
+ 1. **Install in n8n**:
137
+ ```bash
138
+ npm install n8n-nodes-sunx-perps
139
+ ```
140
+
141
+ 2. **Configure Credentials**:
142
+ - Access Key ID
143
+ - Secret Key
144
+ - Base URL (default: https://api.sunx.io)
145
+
146
+ 3. **Use in Workflow**:
147
+ - Add "SunX Perps" node
148
+ - Select resource (Account, Market Data, Order, Position)
149
+ - Select operation
150
+ - Configure parameters
151
+ - Execute!
152
+
153
+ ### Example Operations
154
+
155
+ **Get Funding Rate**:
156
+ - Resource: Market Data
157
+ - Operation: Get Funding Rate
158
+ - Contract Code: BTC-USDT
159
+
160
+ **Place Limit Order**:
161
+ - Resource: Order
162
+ - Operation: Place Order
163
+ - Contract Code: BTC-USDT
164
+ - Direction: buy
165
+ - Offset: open
166
+ - Order Price Type: limit
167
+ - Volume: 1
168
+ - Price: 50000
169
+ - Leverage Rate: 10
170
+
171
+ **Get Account Balance**:
172
+ - Resource: Account
173
+ - Operation: Get Balance
174
+
175
+ ## 🔧 Development
176
+
177
+ ### Build
178
+ ```bash
179
+ npm run build
180
+ ```
181
+
182
+ ### Watch Mode
183
+ ```bash
184
+ npm run dev
185
+ ```
186
+
187
+ ### Lint
188
+ ```bash
189
+ npm run lint
190
+ npm run lintfix
191
+ ```
192
+
193
+ ### Format
194
+ ```bash
195
+ npm run format
196
+ ```
197
+
198
+ ## 📊 API Endpoint Mapping
199
+
200
+ | Operation | Method | Endpoint | Auth |
201
+ |-----------|--------|----------|------|
202
+ | Get Balance | GET | /sapi/v1/account/balance | ✓ |
203
+ | Get Trading Bills | GET | /sapi/v1/account/financial_record | ✓ |
204
+ | Get Contract Info | GET | /sapi/v1/public/contract_info | ✗ |
205
+ | Get Fee Info | GET | /sapi/v1/public/swap_fee | ✗ |
206
+ | Get Funding Rate | GET | /sapi/v1/public/funding_rate | ✗ |
207
+ | Get Historical Funding | GET | /sapi/v1/public/historical_funding_rate | ✗ |
208
+ | Get Leverage Info | GET | /sapi/v1/public/swap_adjustfactor | ✗ |
209
+ | Get Multi-Asset | GET | /sapi/v1/public/cross_transfer_info | ✗ |
210
+ | Get Swap Index | GET | /sapi/v1/public/swap_index | ✗ |
211
+ | Place Order | POST | /sapi/v1/order | ✓ |
212
+ | Place Multiple Orders | POST | /sapi/v1/order/batch | ✓ |
213
+ | Cancel Order | POST | /sapi/v1/order/cancel | ✓ |
214
+ | Cancel All Orders | POST | /sapi/v1/order/cancelall | ✓ |
215
+ | Close Symbol | POST | /sapi/v1/order/close_position | ✓ |
216
+ | Close All | POST | /sapi/v1/order/close_all_position | ✓ |
217
+ | Get Current Orders | GET | /sapi/v1/order/openorders | ✓ |
218
+ | Get Order History | GET | /sapi/v1/order/hisorders | ✓ |
219
+ | Get Order Info | GET | /sapi/v1/order/info | ✓ |
220
+ | Get Position | GET | /sapi/v1/position/info | ✓ |
221
+ | Set Leverage | POST | /sapi/v1/position/switch_lever_rate | ✓ |
222
+ | Get Position Mode | GET | /sapi/v1/position/position_mode | ✓ |
223
+ | Set Position Mode | POST | /sapi/v1/position/switch_position_mode | ✓ |
224
+
225
+ ## 🎯 Next Steps
226
+
227
+ 1. **Testing**: Follow TESTING.md to test all operations
228
+ 2. **Publishing**: Publish to npm registry
229
+ 3. **Documentation**: Add to n8n community nodes registry
230
+ 4. **Monitoring**: Set up error tracking
231
+ 5. **Updates**: Monitor SunX API for changes
232
+
233
+ ## 📝 Notes
234
+
235
+ - All 23 requested operations are fully implemented
236
+ - Authentication uses HMAC SHA256 as per SunX API requirements
237
+ - Public endpoints don't require authentication
238
+ - Error handling includes API-specific error messages
239
+ - Supports both single and batch operations
240
+ - Includes comprehensive documentation
241
+ - Ready for npm publishing
242
+ - CI/CD pipeline configured
243
+
244
+ ## 🤝 Support
245
+
246
+ - GitHub: Create an issue for bugs or features
247
+ - n8n Community: https://community.n8n.io/
248
+ - SunX Docs: https://docs.sunx.io
249
+
250
+ ---
251
+
252
+ **Status**: ✅ Complete and Ready for Use
253
+ **Version**: 1.0.0
254
+ **License**: MIT
@@ -0,0 +1,9 @@
1
+ import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class SunxPerpsApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ documentationUrl: string;
6
+ properties: INodeProperties[];
7
+ authenticate: IAuthenticateGeneric;
8
+ test: ICredentialTestRequest;
9
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SunxPerpsApi = void 0;
4
+ class SunxPerpsApi {
5
+ constructor() {
6
+ this.name = 'sunxPerpsApi';
7
+ this.displayName = 'SunX Perps API';
8
+ this.documentationUrl = 'https://docs.sunx.io';
9
+ this.properties = [
10
+ {
11
+ displayName: 'Access Key ID',
12
+ name: 'accessKeyId',
13
+ type: 'string',
14
+ default: '',
15
+ required: true,
16
+ description: 'Your SunX API Access Key ID',
17
+ },
18
+ {
19
+ displayName: 'Secret Key',
20
+ name: 'secretKey',
21
+ type: 'string',
22
+ typeOptions: {
23
+ password: true,
24
+ },
25
+ default: '',
26
+ required: true,
27
+ description: 'Your SunX API Secret Key',
28
+ },
29
+ {
30
+ displayName: 'Base URL',
31
+ name: 'baseUrl',
32
+ type: 'string',
33
+ default: 'https://api.sunx.io',
34
+ required: true,
35
+ description: 'The base URL for SunX API',
36
+ },
37
+ ];
38
+ this.authenticate = {
39
+ type: 'generic',
40
+ properties: {},
41
+ };
42
+ this.test = {
43
+ request: {
44
+ baseURL: '={{$credentials.baseUrl}}',
45
+ url: '/sapi/v1/account/balance',
46
+ method: 'GET',
47
+ },
48
+ };
49
+ }
50
+ }
51
+ exports.SunxPerpsApi = SunxPerpsApi;
52
+ //# sourceMappingURL=SunxPerpsApi.credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SunxPerpsApi.credentials.js","sourceRoot":"","sources":["../../credentials/SunxPerpsApi.credentials.ts"],"names":[],"mappings":";;;AAOA,MAAa,YAAY;IAAzB;QACC,SAAI,GAAG,cAAc,CAAC;QACtB,gBAAW,GAAG,gBAAgB,CAAC;QAC/B,qBAAgB,GAAG,sBAAsB,CAAC;QAC1C,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,eAAe;gBAC5B,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,6BAA6B;aAC1C;YACD;gBACC,WAAW,EAAE,YAAY;gBACzB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE;oBACZ,QAAQ,EAAE,IAAI;iBACd;gBACD,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,0BAA0B;aACvC;YACD;gBACC,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,qBAAqB;gBAC9B,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,2BAA2B;aACxC;SACD,CAAC;QAEF,iBAAY,GAAyB;YACpC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,EAAE;SACd,CAAC;QAEF,SAAI,GAA2B;YAC9B,OAAO,EAAE;gBACR,OAAO,EAAE,2BAA2B;gBACpC,GAAG,EAAE,0BAA0B;gBAC/B,MAAM,EAAE,KAAK;aACb;SACD,CAAC;IACH,CAAC;CAAA;AA9CD,oCA8CC"}
@@ -0,0 +1,5 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class SunxPerps implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }