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

binance-websocket-api-node

v1.0.10

Published

Binance websocket api using node js

Downloads

6

Readme

binance-websocket-api-node

Installation

yarn add binance-websocket-api-node

Getting started

Import the module and create a new client. Passing api keys is optional only if you don't plan on doing authenticated calls. Check the binance documentation here.

Note

WebSocket api allows only spot trading

import webSocket from "ws";
import BinanceWebSocketApi from 'binance-websocket-api-node'

const client = new BinanceWebSocketApi({
    webSocket: webSocket,
})

// Authenticated client, can make signed calls
const client2 = new BinanceWebSocketApi({
  apiKey: 'xxx',
  apiSecret: 'xxx',
  webSocket: webSocket,
})

client.time().then(time => console.log(time))

Every method returns a Promise, making this library async await ready. Following examples will use the await form, which requires some configuration you will have to lookup.

Table of Contents

Init

| Param | Type | Required | Info | | ----------- | -------- | -------- | -------------------------------------------- | | apiKey | String | false | Required when making private calls | | apiSecret | String | false | Required when making private calls | | webSocket | Object | true | Required to communicate with server |

Public REST Endpoints

ping

Test connectivity to the API.

console.log(await client.ping())

time

Test connectivity to the Rest API and get the current server time.

console.log(await client.time())
1508478457643

exchangeInfo

Get the current exchange trading rules and symbol information. You can optionally pass a symbol to only retrieve info of this specific one.

console.log(await client.exchangeInfo())

Authenticated Endpoints

order

Creates a new order. Doc

console.log(
  await client.order({
    symbol: "BTCUSDT",
    side: "SELL",
    type: "LIMIT",
    timeInForce: "GTC",
    price: "23416.10000000",
    quantity: "0.00847000",
  }),
)

orderTest

Test order placement. This API does not return any output on success. Validates new order parameters and verifies your signature but does not send the order into the matching engine.

orderOco

Creates a new OCO order. Doc

console.log(
  await client.orderOco({
    symbol: "BTCUSDT",
    side: "SELL",
    price: "23420.00000000",
    quantity: "0.00650000",
    stopPrice: "23410.00000000",
    stopLimitPrice: "23405.00000000",
    stopLimitTimeInForce: "GTC",
    newOrderRespType: "RESULT",
  }),
)

getOrder

Check an order's status. Doc

console.log(
  await client.getOrder({
    symbol: 'BTCUSDT',
    orderId: 12569099453,
  }),
)

getOrderOco

Retrieves a specific OCO based on provided optional parameters Doc

console.log(
  await client.getOrderOco({
    origClientOrderId: "08985fedd9ea2cf6b28996"
  }),
)

cancelOrder

Cancels an active order. Doc

console.log(
  await client.cancelOrder({
    symbol: 'BTCUSDT',
    origClientOrderId: "4d96324ff9d44481926157",
  }),
)

cancelOrderOco

Cancel an entire Order List. Doc

console.log(
  await client.cancelOrderOco({
    symbol: "BTCUSDT",
    orderListId: 1274512,
  }),
)

cancelOpenOrders

Cancel all open orders on a symbol, including OCO orders. Doc

console.log(
  await client.cancelOpenOrders({
    symbol: 'BTCUSDT'
  }),
)

openOrders

Query execution status of all open orders. Doc

console.log(
  await client.openOrders({
    symbol: 'BTCUSDT',
  }),
)

allOrders

Query information about all your orders – active, canceled, filled – filtered by time range. Doc

console.log(
  await client.allOrders({
    symbol: "BTCUSDT",
    startTime: 1660780800000,
    endTime: 1660867200000,
    limit: 5,
  }),
)

allOrdersOCO

Query information about all your OCOs, filtered by time range. Doc

console.log(
  await client.allOrdersOCO({
    startTime: 1660780800000,
    endTime: 1660867200000,
    limit: 5,
  }),
)

accountInfo

Query information about your account. Doc

console.log(await client.accountInfo())

myTrades

Query information about all your trades, filtered by time range. Doc

console.log(
  await client.myTrades({
    symbol: "BTCUSDT",
    startTime: 1660780800000,
    endTime: 1660867200000,
  }),
)

WebSockets

Every websocket utility returns a function you can call to close the opened connection and avoid memory issues.

user

Live user data feed (Account Update, Balance Update, Order Update).

Requires authentication

const clean = await client.ws.user(msg => {
  console.log(msg)
})