bitget-f-close

n8n custom node for Bitget Futures — Flash Close All (positions + orders + TP/SL)

Package Information

Released: 4 mo ago
Downloads: 24 weeklyĀ /Ā 99 monthly
Latest Version: 1.1.1
Author: Your Name

Documentation

n8n-nodes-bitget-futures

A custom n8n community node for Bitget Futures trading — featuring a Flash Close All operation that closes every open position and cancels every order (including TP/SL) in a single node execution, just like Bitget's own "Flash Close" button.


šŸ“¦ Installation

Option A — n8n Community Nodes (Recommended)

  1. In n8n, go to Settings → Community Nodes
  2. Click Install
  3. Enter package name: n8n-nodes-bitget-futures
  4. Click Install

Option B — Manual (this ZIP)

  1. Copy this folder to your n8n custom extensions directory:

    ~/.n8n/custom/
    

    So the path becomes: ~/.n8n/custom/n8n-nodes-bitget-futures/

  2. Restart n8n. The Bitget Futures node will appear in the node palette.

Option C — Docker

Mount the folder as a volume and set the env var:

environment:
  - N8N_CUSTOM_EXTENSIONS=/home/node/.n8n/custom
volumes:
  - ./n8n-nodes-bitget-futures:/home/node/.n8n/custom/n8n-nodes-bitget-futures

šŸ”‘ Credentials Setup

  1. In n8n go to Credentials → New Credential → Bitget Futures API
  2. Fill in:
    • API Key — from Bitget API management page
    • Secret Key — your API secret
    • Passphrase — the passphrase you set when creating the key
    • Trading Environment — choose Demo (safe) or Live (real money)

āš ļø Always test with Demo first! Live trading uses real funds.

API Key Permissions Required

  • āœ… Trade — required for all order/position operations
  • āœ… Read — required for fetching positions

āš™ļø Operations

⚔ Flash Close All — Positions + Orders + TP/SL (Main Feature)

Executes a full account nuke in 3 sequential steps:

Step API Endpoint What it does
1 POST /api/v2/mix/order/cancel-all-orders Cancels ALL regular open limit/market orders
2 POST /api/v2/mix/order/cancel-plan-order Cancels ALL TP/SL plan orders (per-symbol, auto-detected from positions)
3 POST /api/v2/mix/order/close-positions Flash-closes ALL open positions at market price

Parameters:

  • Product Type — USDT-FUTURES / COIN-FUTURES / USDC-FUTURES
  • Margin Coin — USDT, USDC, or base coin
  • Symbol (optional) — restrict to one trading pair (e.g. BTCUSDT), empty = ALL
  • Hold Side (hedge mode) — Both / Long only / Short only
  • Continue on Partial Failure — if true, continues even if one step errors

Returns:

{
  "environment": "DEMO",
  "productType": "SUSDT-FUTURES",
  "symbol": "ALL",
  "overallStatus": "success",
  "cancelAllOrders": { "status": "success", "data": {...} },
  "cancelTpslOrders": { "status": "success", "data": [...] },
  "flashClosePositions": { "status": "success", "data": {...} },
  "timestamp": "2024-01-15T10:30:00.000Z"
}

Flash Close Positions Only

Closes all open positions at market price without touching pending orders.

  • Endpoint: POST /api/v2/mix/order/close-positions

Cancel All Open Orders

Cancels all regular limit/market orders (not plan/TP/SL orders).

  • Endpoint: POST /api/v2/mix/order/cancel-all-orders

Cancel All TP/SL Plan Orders

Cancels all take-profit and stop-loss plan orders.

  • Endpoint: POST /api/v2/mix/order/cancel-plan-order
  • Auto-fetches open positions to determine which symbols to target

Get All Open Positions

Returns a full list of currently open futures positions.

  • Endpoint: GET /api/v2/mix/position/all-position

šŸŒ Demo vs Live Environment

The environment can be set in two places:

  1. Credential level — set a default in the API credential
  2. Node level — per-node override via Trading Environment dropdown

The node-level setting wins over the credential setting (unless set to "Use Credential Setting").

How Demo Works

Bitget uses separate product type prefixes for demo accounts:

Live Demo
USDT-FUTURES SUSDT-FUTURES
COIN-FUTURES SCOIN-FUTURES
USDC-FUTURES SUSDC-FUTURES

The node automatically maps product types when demo mode is active — you always select the "live" name and it converts internally.


šŸ” Authentication (Technical)

Bitget uses HMAC-SHA256 signed requests:

Signature = Base64(HMAC-SHA256(timestamp + METHOD + path + body, secretKey))

Headers required on every request:

  • ACCESS-KEY — your API key
  • ACCESS-SIGN — computed signature
  • ACCESS-TIMESTAMP — Unix ms timestamp
  • ACCESS-PASSPHRASE — your API passphrase
  • Content-Type: application/json

All signing is handled automatically by the node.


šŸ“ File Structure

n8n-nodes-bitget-futures/
ā”œā”€ā”€ package.json                          # npm package manifest + n8n registration
ā”œā”€ā”€ tsconfig.json                         # TypeScript config
ā”œā”€ā”€ README.md                             # This file
ā”œā”€ā”€ src/                                  # TypeScript source
│   ā”œā”€ā”€ index.ts
│   ā”œā”€ā”€ credentials/
│   │   └── BitgetFuturesApi.credentials.ts
│   └── nodes/
│       └── BitgetFutures/
│           ā”œā”€ā”€ BitgetFutures.node.ts     # Main node logic
│           ā”œā”€ā”€ bitgetApi.ts              # API signing + request helper
│           └── bitget.svg                # Node icon
└── dist/                                 # Pre-compiled JavaScript (ready to use)
    ā”œā”€ā”€ index.js
    ā”œā”€ā”€ credentials/
    │   └── BitgetFuturesApi.credentials.js
    └── nodes/
        └── BitgetFutures/
            ā”œā”€ā”€ BitgetFutures.node.js
            ā”œā”€ā”€ bitgetApi.js
            └── bitget.svg

šŸ”§ Building from Source (Optional)

If you want to modify the TypeScript source and rebuild:

npm install
npm run build

Requires Node.js 18+ and TypeScript 5+.


āš ļø Disclaimer

This node is provided as-is for automation purposes. Futures trading involves significant financial risk. Always test with the Demo environment before using with real funds. The authors are not responsible for any trading losses.

Discussion