npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

bitunix

v1.0.5

Published

A Node.js library for interacting with the Bitunix Exchange API for trading.

Downloads

13

Readme

Bitunix is an NPM package exclusively designed to simplify and enhance interactions with the Bitunix exchange API. This package provides a high-level abstraction for managing accounts, positions, orders, and risk parameters while ensuring data validation and signature generation for secure and reliable API communication.


Features

  • Account Management: Fetch account details, balance, and positions.
  • Position Management: Retrieve current positions and historical data.
  • Order Placement: Place market orders, set leverage, margin modes, take profits, and stop losses.
  • Risk Management: Validate inputs and enforce trading rules.
  • Secure Communication: Generate signatures and nonces for API requests.
  • Easy Integration: Configure and use with minimal setup.

Installation

To install the package, run:

npm install bitunix

Configuration

The package requires a configuration file for endpoints and base URL. Update src/config/config.json with your API details:

{
    "base_url": "https://fapi.bitunix.com",
    "endpoints": {
      "getAccount": "/api/v1/futures/account",
      "getPositionHistory": "/api/v1/futures/position/get_history_positions",
      "getPositions": "/api/v1/futures/position/get_pending_positions",
      "setLevrage": "/api/v1/futures/account/change_leverage",
      "setMarginMode": "/api/v1/futures/account/change_margin_mode",
      "setPositionMode": "/api/v1/futures/account/change_position_mode",
      "openTakeProfit": "/api/v1/futures/tpsl/place_order",
      "openStopLoss": "/api/v1/futures/tpsl/place_order",
      "getMarketPrice": "/api/v1/futures/market/depth",
      "placeOrder": "/api/v1/futures/trade/place_order"
    }
}

Usage

1. Initialization

Create an instance of the Bitunix class by passing your API credentials:

const Bitunix = require('bitunix');

const bitunix = new Bitunix({
  apiKey: 'your-api-key',
  apiSecret: 'your-api-secret',
});

2. Fetch Account Information

(async () => {
  try {
    const account = await bitunix.getAccount();
    console.log(account);
  } catch (error) {
    console.error(error.message);
  }
})();

3. Retrieve Current Positions

(async () => {
  try {
    const positions = await bitunix.getPositions('BTC');
    console.log(positions);
  } catch (error) {
    console.error(error.message);
  }
})();

4. Set Leverage

(async () => {
  try {
    const response = await bitunix.setLevrage('BTC', 10);
    console.log(response);
  } catch (error) {
    console.error(error.message);
  }
})();

5. Place an Order

(async () => {
  try {
    const payload = {
      symbol: 'BTC',
      side: 'BUY',
      type: 'MARKET',
      margin: 100,
      leverage: 10,
      marginType: 'isolated',
      stop_loss: 40000,
      take_profit: [
        { price: 45000, percent: 50 },
        { price: 47000, percent: 50 },
      ],
    };

    await bitunix.openOrder(payload);
  } catch (error) {
    console.error(error.message);
  }
})();

Methods

1. Constructor

constructor({ apiKey, apiSecret })

Initializes the Bitunix client.

2. getAccount

async getAccount()

Fetch account details.

3. getPositions

async getPositions(symbol)

Retrieve positions for a specific symbol. If no symbol is provided, returns all positions.

4. setLevrage

async setLevrage(symbol, leverage)

Set the leverage for a specific symbol.

5. setMarginMode

async setMarginMode(symbol, mode)

Set the margin mode (e.g., isolated or cross).

6. setPositionMode

async setPositionMode(symbol, mode)

Set the position mode (e.g., single or dual).

7. openOrder

async openOrder(payload)

Places an order and configures stop loss and take profit levels.


Error Handling

All methods throw descriptive errors when operations fail. Wrap your calls in try-catch blocks to handle errors gracefully.

try {
  const result = await bitunix.getAccount();
} catch (error) {
  console.error('Error:', error.message);
}

Development

Prerequisites

  • Node.js (v14 or higher)
  • npm (v6 or higher)

Cloning the Repository

git clone https://github.com/your-repo/bitunix.git
cd bitunix

Running Locally

Install dependencies:

npm install

Run tests (if any):

npm test

Contributing

Contributions are welcome! Please open an issue or submit a pull request with improvements or fixes.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Author

Hesam
Email: [email protected]
GitHub: its-hesam


Acknowledgments

Special thanks to the developers and the open-source community for their valuable tools and contributions.