@binance/connector-typescript

中文文档
0.3.16发布于 2025/03/24MITTypeScriptESM + CJS近 30 天下载 2106

This is a lightweight library that works as a connector to the Binance public API.

原始使用文档
文档目录7 节
  1. Installation
  2. Documentation
  3. RESTful APIs
  4. Websockets
  5. Test
  6. Limitation
  7. License

Binance connector in Typescript - DEPRECATED

npm version License: MIT

This repository is deprecated. Please use the new repository: binance-connector-js

This library is an easy, simple and clean connector to the Binance public API. It is divided into three distinct endpoints:

Installation

npm install @binance/connector-typescript

Documentation

RESTful APIs

All REST API endpoints are linked to a unique module called Spot. To start working with the REST API, you will need to import and create the client. Keep in mind that some of the endpoints require authentication with your API credentials keys:

import { Spot } from '@binance/connector-typescript';

const API_KEY = '';
const API_SECRET = '';
const BASE_URL = 'https://api.binance.com';

const client = new Spot(API_KEY, API_SECRET, { baseURL: BASE_URL });
client.exchangeInformation().then((res) => {
    console.log(res);
}).catch(err => { console.log(err) });

Please look at examples/restful folder to check for more endpoints.

Testnet

While /sapi/* endpoints don't have testnet environment yet, /api/* endpoints can be tested in Spot Testnet. You can use it by changing the base URL:

// provide the testnet base url
const client = new Spot(apiKey, apiSecret, { baseURL: 'https://testnet.binance.vision'})

If base_url is not provided, it defaults to api.binance.com.

Websockets

Websocket API Client

All websocket are available with the WebsocketAPI module. To work with the websocket API, you will need to import the client and generate a callBack function to handle the messages:

import { WebsocketAPI } from '@binance/connector-typescript';

const API_KEY = '';
const API_SECRET = '';

const callbacks = {
    open: (client: WebsocketAPI) => client.exchangeInfo(),
    close: () => console.debug('Disconnected from WebSocket server'),
    message: (data: string) => console.info(JSON.parse(data))
}
const websocketAPIClient = new WebsocketAPI(API_KEY, API_SECRET, { callbacks });
setTimeout(() => websocketAPIClient.disconnect(), 20000);

Please look at examples/websocketAPI folder to check for more endpoints.

Websocket Stream Client

All websocket streams are available with the WebsocketStream module. To work with the websocket API, you will need to import the client and generate a callBack function to handle the messages:

import { WebsocketStream } from '@binance/connector-typescript';

const callbacks = {
  open: () => console.debug('Connected to WebSocket server'),
  close: () => console.debug('Disconnected from WebSocket server'),
  message: (data: string) => console.info(data)
}

const websocketStreamClient = new WebsocketStream({ callbacks });
websocketStreamClient.aggTrade('bnbusdt');
setTimeout(() => websocketStreamClient.disconnect(), 6000);

Please look at examples/websocketStream folder to check for more endpoints.

Test

npm install

npm run test

Limitation

Futures and European Options APIs are not supported:

  • /fapi/*
  • /dapi/*
  • /eapi/*
  • Associated Websocket Market and User Data Streams

License

MIT

版本与发布记录

@binance/connector-typescript 共发布 17 个版本,首次发布于 2023/10/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.16latest2025/03/241.6 年前
0.3.152025/01/081.8 年前
0.3.142024/11/271.9 年前
0.3.132024/10/112 年前
0.3.122024/10/022 年前
0.3.112024/09/182 年前

关于 @binance/connector-typescript 的常见问题

@binance/connector-typescript 是什么?

This is a lightweight library that works as a connector to the Binance public API.

如何安装 @binance/connector-typescript?

在项目目录运行 npm install @binance/connector-typescript,或使用 pnpm add / yarn add / bun add。

@binance/connector-typescript 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@binance/connector-typescript 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@binance/connector-typescript 可以商用吗?

@binance/connector-typescript 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@binance/connector-typescript 的下载量有多少?

根据 npm 官方下载统计,@binance/connector-typescript 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,106 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@binance/connector-typescript 还在维护吗?

最新版本 0.3.16 发布于 2025/03/24(1.6 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/10/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。