Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

node-huobi-sdk

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-huobi-sdk

huobi REST API 和 WebSocket的 封装

latest
Source
npmnpm
Version
1.0.36
Version published
Weekly downloads
6
-88%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 18 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts