sunx-perps

n8n node for SunX Perpetual Futures Trading

Package Information

Downloads: 42 weekly / 107 monthly
Latest Version: 1.2.9
Author: Deepak Dhaka

Documentation

SunX Perps n8n Node - Project Summary

Overview

Complete n8n community node implementation for SunX Perpetual Futures API with all requested features.

✅ Implemented Features

Account Operations (2)

  1. ✅ Get Account Balance
  2. ✅ Get Trading Bills

Market Data Operations (7)

  1. ✅ Get Contract Info
  2. ✅ Get Swap Index Price
  3. ✅ Get Leverage Info (Risk Limit)
  4. ✅ Get Funding Rate
  5. ✅ Get Historical Funding Rate
  6. ✅ Get Multi-Asset Collateral
  7. ✅ Get Fee Info

Order Operations (10)

  1. ✅ Place Order
  2. ✅ Place Multiple Orders
  3. ✅ Cancel Order
  4. ✅ Cancel Multiple Orders
  5. ✅ Cancel All Orders
  6. ✅ Close Symbol at Market Price
  7. ✅ Close All at Market Price
  8. ✅ Get Current Orders
  9. ✅ Get Order History
  10. ✅ Get Order Info

Position Operations (4)

  1. ✅ Get Current Position
  2. ✅ Set Leverage
  3. ✅ Get Position Mode
  4. ✅ Set Position Mode

Total: 23 Operations Implemented

📁 Project Structure

n8n-nodes-sunx-perps/
├── credentials/
│   └── SunxPerpsApi.credentials.ts    # API authentication
├── nodes/
│   └── SunxPerps/
│       ├── SunxPerps.node.ts          # Main node with all operations
│       ├── SunxPerpsUtils.ts          # Auth & API utilities
│       └── sunx.svg                   # Node icon
├── .github/
│   ├── workflows/
│   │   └── ci.yml                     # CI/CD pipeline
│   └── ISSUE_TEMPLATE/
│       ├── bug_report.md
│       └── feature_request.md
├── package.json                        # Dependencies & scripts
├── tsconfig.json                       # TypeScript config
├── gulpfile.js                         # Build scripts
├── .eslintrc.js                        # Linting rules
├── .prettierrc.js                      # Code formatting
├── .gitignore
├── .npmignore
├── README.md                           # User documentation
├── DEVELOPMENT.md                      # Developer guide
├── TESTING.md                          # Testing guide
├── CHANGELOG.md                        # Version history
├── LICENSE.md                          # MIT License
└── example-workflow.json              # Example n8n workflow

🔑 Key Features

Authentication

  • ✅ HMAC SHA256 signature generation
  • ✅ Automatic timestamp handling
  • ✅ Full SunX API v2 authentication support
  • ✅ Secure credential storage

Error Handling

  • ✅ Comprehensive error messages
  • ✅ API error parsing
  • ✅ Continue on fail support
  • ✅ Detailed error context

API Coverage

  • ✅ All public endpoints (no auth required)
  • ✅ All authenticated endpoints
  • ✅ Query string parameter support
  • ✅ Request body support for POST/PUT

Developer Experience

  • ✅ TypeScript with full type safety
  • ✅ ESLint configuration
  • ✅ Prettier formatting
  • ✅ Build scripts
  • ✅ Development mode (watch)

📦 Files Created

Core Implementation (5 files)

  1. credentials/SunxPerpsApi.credentials.ts - API credential configuration
  2. nodes/SunxPerps/SunxPerps.node.ts - Main node with all 23 operations
  3. nodes/SunxPerps/SunxPerpsUtils.ts - Authentication & HTTP utilities
  4. nodes/SunxPerps/sunx.svg - Custom node icon
  5. gulpfile.js - Icon build script

Configuration (7 files)

  1. package.json - NPM package configuration
  2. tsconfig.json - TypeScript compiler options
  3. .eslintrc.js - ESLint rules
  4. .prettierrc.js - Code formatting rules
  5. .gitignore - Git exclusions
  6. .npmignore - NPM publish exclusions
  7. LICENSE.md - MIT License

Documentation (5 files)

  1. README.md - Installation & usage guide
  2. DEVELOPMENT.md - Developer documentation
  3. TESTING.md - Comprehensive testing guide
  4. CHANGELOG.md - Version history
  5. example-workflow.json - Sample n8n workflow

CI/CD & Templates (3 files)

  1. .github/workflows/ci.yml - GitHub Actions workflow
  2. .github/ISSUE_TEMPLATE/bug_report.md - Bug report template
  3. .github/ISSUE_TEMPLATE/feature_request.md - Feature request template

Total: 20 Files Created

🚀 Installation & Usage

Quick Start

  1. Install in n8n:

    npm install n8n-nodes-sunx-perps
    
  2. Configure Credentials:

  3. Use in Workflow:

    • Add "SunX Perps" node
    • Select resource (Account, Market Data, Order, Position)
    • Select operation
    • Configure parameters
    • Execute!

Example Operations

Get Funding Rate:

  • Resource: Market Data
  • Operation: Get Funding Rate
  • Contract Code: BTC-USDT

Place Limit Order:

  • Resource: Order
  • Operation: Place Order
  • Contract Code: BTC-USDT
  • Direction: buy
  • Offset: open
  • Order Price Type: limit
  • Volume: 1
  • Price: 50000
  • Leverage Rate: 10

Get Account Balance:

  • Resource: Account
  • Operation: Get Balance

🔧 Development

Build

npm run build

Watch Mode

npm run dev

Lint

npm run lint
npm run lintfix

Format

npm run format

📊 API Endpoint Mapping

Operation Method Endpoint Auth
Get Balance GET /sapi/v1/account/balance
Get Trading Bills GET /sapi/v1/account/financial_record
Get Contract Info GET /sapi/v1/public/contract_info
Get Fee Info GET /sapi/v1/public/swap_fee
Get Funding Rate GET /sapi/v1/public/funding_rate
Get Historical Funding GET /sapi/v1/public/historical_funding_rate
Get Leverage Info GET /sapi/v1/public/swap_adjustfactor
Get Multi-Asset GET /sapi/v1/public/cross_transfer_info
Get Swap Index GET /sapi/v1/public/swap_index
Place Order POST /sapi/v1/order
Place Multiple Orders POST /sapi/v1/order/batch
Cancel Order POST /sapi/v1/order/cancel
Cancel All Orders POST /sapi/v1/order/cancelall
Close Symbol POST /sapi/v1/order/close_position
Close All POST /sapi/v1/order/close_all_position
Get Current Orders GET /sapi/v1/order/openorders
Get Order History GET /sapi/v1/order/hisorders
Get Order Info GET /sapi/v1/order/info
Get Position GET /sapi/v1/position/info
Set Leverage POST /sapi/v1/position/switch_lever_rate
Get Position Mode GET /sapi/v1/position/position_mode
Set Position Mode POST /sapi/v1/position/switch_position_mode

🎯 Next Steps

  1. Testing: Follow TESTING.md to test all operations
  2. Publishing: Publish to npm registry
  3. Documentation: Add to n8n community nodes registry
  4. Monitoring: Set up error tracking
  5. Updates: Monitor SunX API for changes

📝 Notes

  • All 23 requested operations are fully implemented
  • Authentication uses HMAC SHA256 as per SunX API requirements
  • Public endpoints don't require authentication
  • Error handling includes API-specific error messages
  • Supports both single and batch operations
  • Includes comprehensive documentation
  • Ready for npm publishing
  • CI/CD pipeline configured

🤝 Support


Status: ✅ Complete and Ready for Use
Version: 1.0.0
License: MIT

Discussion