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

@ixjb94/binance

v1.0.11

Published

[![CodeFactor](https://www.codefactor.io/repository/github/ixjb94/binance/badge)](https://www.codefactor.io/repository/github/ixjb94/binance) ![npm version](https://img.shields.io/npm/v/@ixjb94/binance) ![npm size](https://img.shields.io/bundlephobia/mi

Downloads

4

Readme

CodeFactor npm version npm size npm downloads last commit Known Vulnerabilities

Binance Connector Written in Typescript

Structure

binance contains this components

| Component | Info | Status | Document Link | | ------------- |------------- | ------------- | ------------- | | Spot | Spot API | Completed | Spot | | Futures | Futures API | Completed | Futures | | Coin-M | Coin-M API | Completed | Coin-M | | Options | European API | Completed | Options | | BLVT Streams | BLVT Streams | Completed | BLVT | | Websocket | Abstract Websocket | Completed | | | Http | Abstract Http | Completed | |

Spot: contains: Wallet, Sub-Account, Market Data, Spot, Margin, Savings, Staking, Mining, Futures, Futures Algo, Portfolio, BLVT, BSwap, Fiat, C2C, VIP Loans, Crypto Loans, Crypto Loans, Pay, Convert, Rebate, NFT, Binance Code (all available endpoints in binance spot doc)

Websocket & Http: can connect/request to any of binance ws/rest endpoints

Requirement

Node ^18.0.0 and higher
(because it's using fetch API)

Installation

npm i @ixjb94/binance

Usage

import { Futures } from "@ixjb94/binance"

Examples

Note: Everything isPromised so you need to do .then or await

All Examples

  • Rest (Public)
import { Futures } from "@ixjb94/binance"

const myFuture = new Futures({
    isTestNet: true,
})

// exchange info
myFuture.exchangeInfo()

// candles data
myFuture.klines({
    interval: "1m",
    symbol: "BTCUSDT",
    limit: 10,
})
  • Rest (Private)
import { Futures } from "@ixjb94/binance"

const myFuture = new Futures({
    api_key: "MyApiKey",
    api_secret: "MyApiSecret",
    isTestNet: true,
})

// get account balance
myFuture.balance()

// place new order
myFuture.newOrder({
    symbol: "BTCUSDT",
    side: "BUY",
    type: "MARKET",
    quantity: 0.01,
})
  • Websocket (Public)
import { Futures } from "@ixjb94/binance"

const myFuture = new Futures({
    isTestNet: true,
})

// subscribe to two market data
myFuture.ws.subscribe(["btcusdt@kline_1m", "ethusdt@kline_3m"], 1, "MyMarketData")

// listen for data coming from binance
myFuture.ws.addListener("MyMarketData", (socket) => {

    socket.addEventListener("message", (event) => {
        let data = event.data
        data = JSON.parse(data)

        console.log(data)
    })

})
  • Websocket (Private)
import { Futures } from "@ixjb94/binance"

const myFuture = new Futures({
    api_key: "MyApiKey",
    api_secret: "MyApiSecret",
    isTestNet: true,
})

async function Run() {

    // 1- get the listenKey
    const reqListenKey = await myFuture.newListenKey()
    const listenKey = reqListenKey.listenKey

    // 2- subscribe to User Data Stream
    myFuture.ws.userStream(listenKey, "MyUserData")

    // 3- Listen for data coming from binance
    myFuture.ws.addListener("MyUserData", (socket) => {
        
        socket.addEventListener("message", (event) => {
            let data = event.data
            data = JSON.parse(data)

            console.log(data)
        })

    })
}
Run()

Types & Intellisense

img1 img2

Endpoints Naming

| Starts | Example | Http Method | | ------------- |------------- | ------------- | | new | newOrder | POST | | change | changeLeverage | POST | PUT | | delete | deleteOrder | POST | DELETE| | (nothing) | exchangeInfo | GET |

Notes

  • ws data are either Buffer OR Raw string
    so you need to JSON.parse them
    example
import { Futures } from "@ixjb94/binance"

const myFuture = new Futures({
    isTestNet: true,
})

myFuture.ws.subscribe(["btcusdt@kline_1m"], 1)

myFuture.ws.addListener("DATA", (socket) => {

    // Buffer
    socket.addListener("message", (data, siBinary) => {
        console.log(data)
    })

    // Raw string data
    socket.addEventListener("message", (event) => {
        // Its raw
        let data = event.data

        // Now its parsed
        data = JSON.parse(data)
    })

})
  • You don't need to import Http OR Websocket directly
    you can access them with .http. OR .ws.
    example
import { Futures } from "@ixjb94/binance"

const myFuture = new Futures({
    isTestNet: true,
})

// websocket example
myFuture.ws.subscribe(["btcusdt@kline_1m"], 1)

// http example
myFuture.http.publicGET("/fapi/v1/exchangeInfo")

Documentation

Binance Doc