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-futures-connector

v1.4.6

Published

binance-futures-spot 币安-合约+现货-sdk,持续更新,欢迎PR一起完善。微信:wkc19891

Downloads

97

Readme

binance-futures-connector in nodejs

币安-合约+现货 sdk,持续更新,欢迎PR一起完善 策略定制联系 tg:wkc19891 微信:wkc19891

币安 返佣注册链接 实时返20%
https://accounts.binance.me/zh-CN/register?ref=JGLH0SR8
此SDK集成了币安 合约 和 现货接口,且有成熟策略案例,如需可浏览github学习。

npm version Node version Standard-Js License: MIT

This is a lightweight library that works as a connector to Binance public API. It’s designed to be simple, clean, and easy to use with minimal dependencies.

Installation 安装

npm install binance-futures-connector

or

yarn add binance-futures-connector

Documentation 参考文档

https://binance-docs.github.io/apidocs/futures/cn/#185368440e

Websocket

查看上方项目示例

常用函数使用eg

/**
 * 记录收益 打印收益曲线
 */
async function PrintProfit() {
    //记录10次收益
    for (let i = 0; i < 10; i++) {
        LogProfit(i + 1000)
        await Sleep(200)//休息0.2秒
    }
    console.log(LogProfit())
    LogProfit(null)//重置收益曲线
    console.log('重置收益曲线', LogProfit())
    // ``` 打印输出接口
    // [
    //     { income: 1000, time: '2022-11-27 10:39:07' },
    //     { income: 1001, time: '2022-11-27 10:39:07' },
    //     { income: 1002, time: '2022-11-27 10:39:08' },
    //     { income: 1003, time: '2022-11-27 10:39:08' },
    //     { income: 1004, time: '2022-11-27 10:39:08' },
    //     { income: 1005, time: '2022-11-27 10:39:08' },
    //     { income: 1006, time: '2022-11-27 10:39:08' },
    //     { income: 1007, time: '2022-11-27 10:39:09' },
    //     { income: 1008, time: '2022-11-27 10:39:09' },
    //     { income: 1009, time: '2022-11-27 10:39:09' }
    // ]
    // ```
}
PrintProfit()

/**
 * 记录10次日志
 */
async function PrintLog() {
    for (let i = 0; i < 10; i++) {
        Log(i + 1000)
        await Sleep(200)//延迟0.2秒
    }
    console.log(Log())
    Log(null)//清空日志
    console.log('清空日志', Log())
    // ``` 日志结构
    // [
    //     { key: 1, logs: '1000', time: '2022-11-27 12:12:10' },
    //     { key: 2, logs: '1001', time: '2022-11-27 12:12:11' },
    //     { key: 3, logs: '1002', time: '2022-11-27 12:12:11' },
    //     { key: 4, logs: '1003', time: '2022-11-27 12:12:11' },
    //     { key: 5, logs: '1004', time: '2022-11-27 12:12:11' },
    //     { key: 6, logs: '1005', time: '2022-11-27 12:12:11' },
    //     { key: 7, logs: '1006', time: '2022-11-27 12:12:12' },
    //     { key: 8, logs: '1007', time: '2022-11-27 12:12:12' },
    //     { key: 9, logs: '1008', time: '2022-11-27 12:12:12' },
    //     { key: 10, logs: '1009', time: '2022-11-27 12:12:12' }
    //   ]
    // ```
}
PrintLog();

async function UseG() {
    _G('key1', '123', 888, 777)//设置key1值
    _G('key2', 'hello world')//设置key2值
    _G('key3', JSON.stringify({ name: 'top', age: 18 }))
    console.log('key1=', _G('key1'))//获取key1值
    console.log('key2=', _G('key2'))//获取key2值
    console.log('key3=', _G('key3'))//获取key3值
    console.log('key3.name=', JSON.parse(_G('key3')).name)//获取key3.name值

    // ```输出
    // key1= 123888|777
    // key2= hello world
    // key3= {"name":"top","age":18}
    // key3.name= top
    // ```
}
UseG()
async function UseN() {
    let a = 1.34159;
    console.log('a=', a);
    let a1 = _N(a, 2)
    console.log('a2=', a1);
    let a2 = _N(a, 3)
    console.log('a2=', a2);
    // ```输出
    // a= 1.34059
    // a2= 1.34
    // a2= 1.341
    // ```
}
UseN();
const client = new Future(apiKey, apiSecret, { ip: proxyIp, port: proxy })
/**
 * 获取BTCUSDT 1m 10条数据
 * @param {*} coin 
 */
function GetR() {
    client.records("BTCUSDT", "1m", 10).then(records => {
        console.log('获取BTCUSDT 1m 10条数据=', records)
        // ``` 输出
        // [
        //     {
        //       Time: 1669522920000,
        //       Open: 16524.4,
        //       High: 16526.3,
        //       Low: 16522.9,
        //       Close: 16526.2,
        //       Volume: 69.66
        //     },
        //     {
        //       Time: 1669522980000,
        //       Open: 16526.3,
        //       High: 16536.3,
        //       Low: 16526.2,
        //       Close: 16530.3,
        //       Volume: 128.14
        //     }
        //   ]
        // ```
        //获取SAR
        let sar1 = TA.SAR(records, 0.008, 0.2, 0.008);
        console.log('sar11', sar1[sar1.length - 2], 'sar21', sar1[sar1.length - 3])
    })
}
GetR()

// buy()//买入开多
// sell()//卖出开空
// buy_close()//卖出平多
// sell_close()//买入平空

常用指标调用eg

const { Future, TA, _G, _N, LogProfit, Log, DateFormat, Sleep, buy, sell, buy_close, sell_close } = require('binance-futures-connector')

const apiKey = ''
const apiSecret = ''
const proxyIp = '127.0.0.1'
const proxy = '1087'

const fs = require('fs')
const client = new Future(apiKey, apiSecret, { ip: proxyIp, port: proxy })
//sar
client.records("BTCUSDT", "1m", 1500).then(records => {    
    let sar1 = TA.SAR(records, 0.008, 0.2,0.008);
    console.log('sar11', sar1[sar1.length - 2], 'sar21', sar1[sar1.length - 3])
})

client.records("ETHUSDT", "5m").then(records => {
    if (records && records.length > 20) {
        console.log("ETHUSDT", "5m", "time now:", TA.getDate())
        let boll = TA.BOLL(records, 90, 2)
        let upLine = boll[0]
        let midLine = boll[1]
        let downLine = boll[2]
        console.log("upLine", upLine[upLine.length - 1])
        console.log("midLine", midLine[midLine.length - 1])
        console.log("downLine", downLine[downLine.length - 1])
        let macd = TA.MACD(records, 12, 26, 9)
        let dif = macd[0]
        let dea = macd[1]
        let _macd = macd[2]
        console.log("DIF:", dif[dif.length - 1], "DEA:", dea[dea.length - 1], "MACD:", _macd[_macd.length - 1])
        var kdj = TA.KDJ(records, 9, 3, 3)
        let k = kdj[0]
        let d = kdj[1]
        let j = kdj[2]
        console.log("k:", k[k.length - 1], "d:", d[d.length - 1], "MACD:", j[j.length - 1])
        var rsi = TA.RSI(records, 14)
        console.log("rsi:", rsi[rsi.length - 1])
        var atr = TA.ATR(records, 14)
        console.log("atr:", atr[atr.length - 1])
        var obv = TA.OBV(records)
        console.log("obv", obv[obv.length - 1])
        var ema = TA.EMA(records, 9)
        console.log("ema-9", ema[ema.length - 1])
        var ma = TA.MA(records, 14)
        console.log("ma-14", ma[ma.length - 1])
        let h = TA.Highest(records, 30, 'High')
        let l = TA.Lowest(records, 30, 'Low')
        console.log(`h=${h},l=${l}`)
    }
}).catch(res => {
    console.log(res)
})