Skip to main content

BB API

bitbank.cc の REST API・WebSocket・プライベートストリームを型安全に扱える TypeScript クライアントライブラリです。

クライアント一覧

クライアント認証説明
PublicRestClient不要ティッカー・板・約定履歴・ローソク足・サーキットブレイカー情報
RestClient必要資産・注文・証拠金・入出金・取引所ステータス・プライベートストリームトークン
PublicStreamClient不要パブリック WebSocket (Socket.IO)
PrivateStreamClientRestClientプライベートストリーム (PubNub)

インストール

pnpm add @pokooo/bb-api
# npm install @pokooo/bb-api
# yarn add @pokooo/bb-api

要件: Node.js(署名に Web Crypto API を使用)

クイックスタート

パブリック REST(認証不要)

import { PublicRestClient, PAIR } from '@pokooo/bb-api';

const client = new PublicRestClient();

const ticker = await client.getTicker(PAIR.BTC_JPY);
const depth = await client.getDepth(PAIR.BTC_JPY);
const tickers = await client.getTickersJpy();

認証あり REST

import { RestClient, PAIR, ORDER_TYPE, ORDER_SIDE } from '@pokooo/bb-api';

const client = new RestClient({
key: process.env.BITBANK_API_KEY!,
secret: process.env.BITBANK_API_SECRET!,
});

const assets = await client.getAssets();

const order = await client.submitOrder({
pair: PAIR.BTC_JPY,
amount: '0.001',
side: ORDER_SIDE.BUY,
type: ORDER_TYPE.MARKET,
});

パブリック WebSocket

import { PublicStreamClient, PAIR } from '@pokooo/bb-api';

const stream = new PublicStreamClient();

stream.on('connect', () => {
stream.subscribeTicker(PAIR.BTC_JPY);
});

stream.on('ticker', (roomName, data) => console.log(roomName, data));

プライベートストリーム

import { RestClient, PrivateStreamClient } from '@pokooo/bb-api';

const restClient = new RestClient({
key: process.env.BITBANK_API_KEY!,
secret: process.env.BITBANK_API_SECRET!,
});

const stream = new PrivateStreamClient({ restClient });

stream.on('spot_order', (params) => console.log('spot_order', params));

await stream.connect();

ロガー

import { setLogger } from '@pokooo/bb-api';

setLogger({
error: (...args) => console.error('[bitbank]', ...args),
info: (...args) => console.info('[bitbank]', ...args),
});

BITBANKTRACE=1 環境変数を設定すると logInfoconsole.info に出力されます。