Coder Social home page Coder Social logo

huobi-sdk's Introduction

node-huobi-sdk

本SDK为huobi官方API的ts封装。集成REST API、WebScoket行情和WebScoket账户交易V2版

Install

npm install node-huobi-sdk

Usage

import HuobiSDK, { CandlestickIntervalEnum } from 'node-huobi-sdk';

const REST_URL =  'https://api.huobi.de.com';
const MARKET_WS =  'wss://api.huobi.de.com/ws';
const ACCOUNT_WS =  'wss://api.huobi.de.com/ws/v2';

// 稳定线上,需要海外服务器
// const REST_URL =  'https://api.huobi.pro';
// const MARKET_WS =  'wss://api.huobi.pro/ws';
// const ACCOUNT_WS =  'wss://api.huobi.pro/ws/v2';

const hbsdk = new HuobiSDK({
    accessKey: "access_key",
    secretKey: "secret_key",
    // errLogger: (...msg) => {
    //     errLogger.error(...msg);
    // },
    // outLogger: (...msg) => {
    //     outLogger.info(...msg);
    // },
    url:{
        rest: REST_URL,
        market_ws: MARKET_WS,
        account_ws: ACCOUNT_WS,
    }
});

// 需要先执行(只需执行一次),才能调用 钱包、下单 等接口
hbsdk.getAccountId().then(() => {
    // 查余额
    hbsdk.getAccountBalance().then((data) => {
        console.log(data.list)
    });
});


// 下单
hbsdk.order('btcusdt', 'buy-limit', 0.001, 38000);


// 行情-深度
hbsdk.subMarketDepth({symbol: SYMBOL}, (data) => console.log(data))
// 行情-k线
hbsdk.subMarketKline({symbol: SYMBOL, period: CandlestickIntervalEnum.MIN1}, (data) => console.log(data))
// 行情-交易记录
hbsdk.subMarketTrade({symbol: SYMBOL}, (data) => console.log(data))

// 需要权鉴才能ws订阅账户、订单变化
hbsdk.subAuth((data) => {
    console.log(data)
    // 订阅账户变化
    hbsdk.subAccountsUpdate({}, (data) => {
        console.log(data)
    });
});

setOptions

import HuobiSDK, { CandlestickIntervalEnum } from 'node-huobi-sdk';

const REST_URL =  'https://api.huobi.pro';
const MARKET_WS =  'wss://api.huobi.pro/ws';
const ACCOUNT_WS =  'wss://api.huobi.pro/ws/v2';

const hbsdk = new HuobiSDK();


// 异步(查数据后再去设置)
hbsdk.setOptions({
    accessKey: 'account.access_key',
    secretKey: 'account.secret_key',
    // errLogger: (...msg) => {
    //     errLogger.error(...msg);
    // },
    // outLogger: (...msg) => {
    //     outLogger.info(...msg);
    // },
    url:{
        rest: REST_URL,
        market_ws: MARKET_WS,
        account_ws: ACCOUNT_WS,
    }
});

API






### Progress

- [ ] REST
    - [x] `market`:行情
    - [x] `common`:公共
    - [x] `account`:账户
    - [x] `order`:订单
    - [ ] `margin`:借贷
    - [ ] `dw`:虚拟币提现

- [ ] WS
    - [x] `account`:账户
    - [x] `kline`:K线
    - [x] `depth`:挂单深度
    - [x] `trade detail`:交易详情
    - [ ] `market detail`:交易聚合
    - [ ] `order`: 订单


### LICENSE
MIT

huobi-sdk's People

Contributors

bsn4 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.