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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bitget-api-mangonv2

v1.1.1

Published

Node.js connector for Bitget REST APIs and WebSockets, with TypeScript & end-to-end tests.

Downloads

110

Readme

Node.js & Typescript Bitget API SDK

Build & Test npm version npm size npm downloads last commit CodeFactor Telegram

connector logo

Node.js connector for the Bitget APIs and WebSockets:

  • Complete integration with all Bitget APIs.
  • TypeScript support (with type declarations for most API requests & responses).
  • Over 100 integration tests making real API calls & WebSocket connections, validating any changes before they reach npm.
  • Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
  • Officially listed Node.js SDK in Bitget API docs.
  • Browser support (via webpack bundle - see "Browser Usage" below).

Installation

npm install --save bitget-api

Issues & Discussion

Related projects

Check out my related projects:

Documentation

Most methods pass values as-is into HTTP requests. These can be populated using parameters specified by Bitget's API documentation, or check the type definition in each class within this repository (see table below for convenient links to each class).

Structure

This connector is fully compatible with both TypeScript and pure JavaScript projects, while the connector is written in TypeScript. A pure JavaScript version can be built using npm run build, which is also the version published to npm.

The version on npm is the output from the build command and can be used in projects without TypeScript (although TypeScript is definitely recommended).

  • src - the whole connector written in TypeScript
  • lib - the JavaScript version of the project (built from TypeScript). This should not be edited directly, as it will be overwritten with each release.
  • dist - the webpack bundle of the project for use in browser environments (see guidance on webpack below).
  • examples - some implementation examples & demonstrations. Contributions are welcome!

REST API Clients

Each REST API group has a dedicated REST client. To avoid confusion, here are the available REST clients and the corresponding API groups: | Class | Description | |:------------------------------------: |:---------------------------------------------------------------------------------------------: | | SpotClient | Spot APIs | | FuturesClient | Futures APIs | | BrokerClient | Broker APIs | | WebsocketClient | Universal client for all Bitget's Websockets |

Examples for using each client can be found in:

If you're missing an example, you're welcome to request one. Priority will be given to github sponsors.

Usage

First, create API credentials on Bitget's website.

All REST clients have can be used in a similar way. However, method names, parameters and responses may vary depending on the API category you're using!

Not sure which function to call or which parameters to use? Click the class name in the table above to look at all the function names (they are in the same order as the official API docs), and check the API docs for a list of endpoints/paramters/responses.

const {
  SpotClient,
  FuturesClient,
  BrokerClient,
} = require('bitget-api');

const API_KEY = 'xxx';
const API_SECRET = 'yyy';
const API_PASS = 'zzz';

const client = new SpotClient({
    apiKey: API_KEY,
    apiSecret: API_SECRET,
    apiPass: API_PASS,
},
  // requestLibraryOptions
);

// For public-only API calls, simply don't provide a key & secret or set them to undefined
// const client = new SpotClient();


client.getApiKeyInfo()
  .then(result => {
    console.log("getApiKeyInfo result: ", result);
  })
  .catch(err => {
    console.error("getApiKeyInfo error: ", err);
  });

const symbol = 'BTCUSDT_SPBL';
client.getCandles(symbol, '1min');
  .then(result => {
    console.log("getCandles result: ", result);
  })
  .catch(err => {
    console.error("getCandles error: ", err);
  });

WebSockets

For more examples, including how to use websockets with bitget, check the examples and test folders.


Logging

Customise logging

Pass a custom logger which supports the log methods silly, debug, notice, info, warning and error, or override methods from the default logger as desired.

const { WebsocketClient, DefaultLogger } = require('bitget-api');

// Disable all logging on the silly level
DefaultLogger.silly = () => {};

const ws = new WebsocketClient(
  {
    apiKey: 'API_KEY',
    apiSecret: 'API_SECRET',
    apiPass: 'API_PASS',
  },
  DefaultLogger,
);

Debug HTTP requests

In rare situations, you may want to see the raw HTTP requets being built as well as the API response. These can be enabled by setting the BITGETTRACE env var to true.

Browser Usage

Build a bundle using webpack:

  • npm install
  • npm build
  • npm pack

The bundle can be found in dist/. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO.


Contributions & Thanks

Donations

tiagosiebler

Support my efforts to make algo trading accessible to all - register with my referral links:

Or buy me a coffee using any of these:

  • BTC: 1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk
  • ETH (ERC20): 0xd773d8e6a50758e1ada699bb6c4f98bb4abf82da

Contributions & Pull Requests

Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.

Star History

Star History Chart