Socket
Socket
Sign inDemoInstall

bitget-api

Package Overview
Dependencies
14
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bitget-api

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


Version published
Weekly downloads
380
decreased by-8.43%
Maintainers
1
Install size
2.54 MB
Created
Weekly downloads
 

Readme

Source

Node.js & Typescript Bitget API SDK

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

connector logo

Updated & performant JavaScript & Node.js SDK for the Bitget V2 REST 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

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:

ClassDescription
RestClientV2V2 REST APIs
WebsocketClientUniversal client for all Bitget's V2 Websockets
SpotClient (deprecated, use RestClientV2)Spot APIs
FuturesClient (deprecated, use RestClientV2)Futures APIs
BrokerClient (deprecated, use RestClientV2)Broker APIs
WebsocketClient (deprecated, use WebsocketClientV2)Universal client for all Bitget's V1 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 endpoints should be included in the RestClientV2 class. If any endpoints are missing or need improved types, pull requests are very welcome. You can also open an issue on this repo to request an improvement. Priority will be given to github sponsors.

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/parameters/responses.

If you found the method you're looking for in the API docs, you can also search for the endpoint in the RestClientV2 class.

const { RestClientV2 } = require('bitget-api');

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

const client = new RestClientV2(
  {
    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 RestClientV2();

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

client
  .getSpotCandles({
    symbol: 'BTCUSDT',
    granularity: '1min',
    limit: '1000',
  })
  .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 (less console logs)
const customLogger = {
  ...DefaultLogger,
  silly: () => {},
};

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

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

Import

This is the "modern" way, allowing the package to be directly imported into frontend projects with full typescript support.

  1. Install these dependencies
    npm install crypto-browserify stream-browserify
    
  2. Add this to your tsconfig.json
    {
      "compilerOptions": {
        "paths": {
          "crypto": [
            "./node_modules/crypto-browserify"
          ],
          "stream": [
            "./node_modules/stream-browserify"
          ]
    }
    
  3. Declare this in the global context of your application (ex: in polyfills for angular)
    (window as any).global = window;
    

Webpack

This is the "old" way of using this package on webpages. This will build a minified js bundle that can be pulled in using a script tag on a website.

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 welcome.


Contributions & Thanks

Donations

tiagosiebler

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

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

Keywords

FAQs

Last updated on 08 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc