blockcc-api

blockcc-api-client is a lightweight node client for interacting with the [block.cc APIv3](https://blockcc.github.io/blockcc-api-document), providing complete API coverage, and supporting synchronous and asynchronous requests, as well as event


Keywords
blockcc, api, bitcoin
License
Apache-2.0
Install
npm install blockcc-api@0.1.2

Documentation

Blockcc Api Client TypeScript

This project is designed to help you make your own projects that interact with the Blockcc API. providing complete API coverage, and supporting synchronous requests, as well as event streaming using WebSockets.

Language

简体中文|English

Installation

npm install blockcc-api

Getting started

import * as blockcc from 'blockcc-api'

Blockcc HTTP API

init the Blockcc Api Client

const client = new blockcc.HttpClient("YOUR_API_KEY");

Tickers

console.log(await client.getTickers(
  "gate-io",
  "bitcoin"
));

Prices

console.log(await client.getPrices(
  "bitcoin"
));

HistoryPrices

console.log(await client.getHistoryPrices(
  "bitcoin",
  1610596800000,
  1611288000000,
  blockcc.Interval.ONE_HOUR
));

Orderbook

console.log(await client.getOrderBook("gate-io_BTC_USDT", 10));

Markets

console.log(await client.getMarkets("gate-io"));

Symbols

console.log(await client.getSymbols("bitcoin", false));

ExchangeRates

console.log(await client.getExchangeRate());

Trades

console.log(await client.getTrades("gate-io_BTC_USDT"));

Kline

console.log(await client.getKline("gate-io_BTC_USDT"));

Brief

console.log(await client.getBriefs(Locale.zh_CN));

Announcements

console.log(await client.getAnnouncements(Locale.zh_CN, "binance"));

Articles

console.log(await client.getArticles(Locale.zh_CN));

Article

console.log(await client.getArticle("5e1d96a5aeae8770b7ff34ac"));

Social Media

console.log(await client.getSocialMedia(Source.WEIBO));

Blockcc WebSocket Implementation

Initialize the WebSocket Client

const client = new blockcc.WebSocketClient("YOUR_API_KEY");

Subscribe Topics

After connecting to the WebSocket client, you need to reply to the subscription message. The format of the subscription message is as follows

{
  "op": "subscribe",
  "args": [
    "price:bitcoin"
  ]
}

Our client provides a method to directly construct a subscription message, which can be used directly as parameters, as shown below

new Promise<void>(resolve => {
  client.subscribe((data: any) => {
      console.log(data);
      resolve();
    },
    blockcc.price("bitcoin"),
    blockcc.ticker("binance_BNB_USDT"),
    blockcc.orderbook("binance_BTC_USDT"));
});