Coder Social home page Coder Social logo

node-bitbankcc's Introduction

node-bitbankcc

About

node-bitbankccはNode.js用のbitabank.cc APIのSDKです。

How to use

import/require

TypeScriptのimport、JavaScriptのrequireはそれぞれ以下のように行います。

TypeScript

import * as bitbank from 'node-bitbankcc';

また、tscコマンドでのコンパイルの際は以下のように行います。

$ tsc --lib ES2016 app.ts

JavaScript

var bitbank = require("node-bitbankcc");

PublicAPI

PublicApiの初期化にはApiConfigが必要です。

const conf: ApiConfig = {
  endPoint: 'https://public.bitbank.cc',	// required
  keepAlive: false,							// optional, default false
  timeout: 3000,							// optional, default 3000
};

const publicApi =new PublicApi(conf);

また、ApiOptionsとして、APIリクエストのOptionsを受け取れるoptionsCallbackと、レスポンスを受け取れるresponseCallbackにfunctionを指定することもできます。

...

const options: ApiOptions = {
  optionsCallback: function(...) {...},
  responseCallback: function(...) {...},
};

const publicApi = new PublicApi(conf, options);

サンプル実装

以下にPublic APIの呼び出しサンプル実装を記載します。

getTicker
const params: GetTickerRequest = {
  pair: 'btc_jpy', 			// required
};
const res = await publicApi.getTicker(params);
getDepth
const params: GetDepthRequest = {
  pair: 'btc_jpy', 			// required
};
const res = await publicApi.getDepth(params);
getTransactions
const params: GetTransactionsRequest = {
  pair: 'btc_jpy', 			// required
  yyyymmdd: '20180401', 	// optional
};
const res = await publicApi.getTransactions(params);
getCandlestick
const params: GetCandleStickRequest = {
  pair: 'btc_jpy', 			// required
  candleType: '1hour', 		// required
  yyyymmdd: '20180401', 	// required
};
const res = await publicApi.getCandlestick(params);
getCircuitBreakInfo
const params: GetCircuitBreakInfoRequest = {
    pair: 'btc_jpy', 			// required
};
const res = await publicApi.getCircuitBreakInfo(params);

PrivateAPI

PrivateAPIの初期化にはPrivateApiConfigが必要になります。

const conf: PrivateApiConfig = {
  endPoint: 'https://api.bitbank.cc/v1',  	// required
  apiKey: 'YOUR_API_KEY',					// required
  apiSecret: 'YOUR_SECRET_KEY',				// required
  keepAlive: false,							// optional, default->false
  timeout: 3000,							// optional, default->3000
};

const privateApi = new PrivateApi(conf);

また、PublicAPIと同様に、ApiOptionsを指定することが可能です。

...

const options: ApiOptions = {
  optionsCallback: function(...) {...},
  responseCallback: function(...) {...},
};

const privateApi = new PrivateApi(conf, options);

サンプル実装

以下にPrivate APIの呼び出しサンプル実装を記載します。

getAssets
const res = await privateApi.getAssets();
assert.equal(res.success, 1);
getOrder
const params: GetOrderRequest = {
  order_id: 14541343,				// required
  pair: 'btc_jpy',					// optional
};
const res = await privateApi.getOrder(params);
postOrder
const params: OrderRequest = {
  pair: 'btc_jpy',					// required
  amount: '0.01',					// required
  price: 1000,						// optional
  side: 'buy',						// required
  type: 'market',					// required
  post_only: false,					// optional. Except for circuit_break_info.mode is NONE, this parm is ignored.
};
const res = await privateApi.postOrder(params);
cancelOrder
const params: CancelOrderRequest = {
  order_id: 14541507,				// required
  pair: 'btc_jpy',					// required
};
const res = await privateApi.cancelOrder(params);
cancelOrders
const params: CancelOrdersRequest = {
  order_ids: [14541370, 14541371],	// required
  pair: 'btc_jpy',					// required
};
const res = await privateApi.cancelOrders(params);
getOrdersInfo
const params: GetOrdersRequest = {
  order_ids: [14541343, 14541344],	// required
  pair: 'btc_jpy',					// optional
};
const res = await privateApi.getOrdersInfo(params);
getActiveOrders
const params: ActiveOrderRequest = {
  pair: 'btc_jpy',					// optional
  count: 1,							// optional
  from_id: 14541346,				// optional
  end_id: 14541343,					// optional
  since: 1523419311277,				// optional
  end: 1523419024484,				// optional
};
const res = await privateApi.getActiveOrders(params);
getTradeHistory
const params: TradeHistoryRequest = {
  pair: 'btc_jpy',					// optional
  count: 1,							// optional
  order_id: 14541370,				// optional
  since: 1523419311277,				// optional
  end: 1523419024484,				// optional
  order: 'asc',						// optional
};
const res = await privateApi.getTradeHistory(params);
getDepositHistory
const params: DepositHistoryRequest = {
  asset: 'btc',						// required
  count: 1,							// optional
  since: 1523419311277,				// optional
  end: 1523419024484,				// optional
  order: 'asc',						// optional
};
const res = await privateApi.getDepositHistory(params);
getWithdrawalAccount
const params: WithdrawalAccountRequest = {
  asset: 'jpy',						// required
};
const res = await privateApi.getWithdrawalAccount(params);
requestWithdrawal
const params: WithdrawalRequest = {
  asset: 'jpy',						// required
  uuid: '00000000-0000-0000-0000-000000000000', // required
  amount: '1000',					// required
  otp_token: '652036',				// optional, sms_tokenとどちらか必須
  sms_token: '******', 				// optional, otp_tokenとどちらか必須
};
const res = await privateApi.requestWithdrawal(params);
getWithdrawalHistory
const params: WithdrawalHistoryRequest = {
  asset: 'btc',						// required
  count: 1,							// optional
  since: 1523419311277,				// optional
  end: 1523419024484,				// optional
  order: 'asc',						// optional
};
const res = await privateApi.getWithdrawalHistory(params);

実装の確認/モックについて

以下のリポジトリのモックサーバーを用いて SDKが正しく実装されているかを確認することができます。 https://github.com/bitbankinc/mock-bitbankcc

node-bitbankcc's People

Contributors

beeant avatar bitbankdev avatar cryptcoin-junkey avatar daiki-ojima avatar daikiojm avatar dependabot[bot] avatar dsaki avatar euxn23 avatar junderw avatar koiibb avatar koiizuka avatar matsumotokou avatar mojamonja avatar naoji avatar onomotoharu avatar soichirokodama avatar you21979 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-bitbankcc's Issues

Transactions didn't work.

onst bitbank = require('node-bitbankcc');
const api = bitbank.publicApi();

api.getTransactions('mona_jpy').then(console.log);

returns 404 error like this.

rror: StatusCodeError: 404 - "{\"success\":0,\"data\":{\"code\":10000}}"
Unhandled rejection Error: 404
    at /home/ubuntu/influx-study/node_modules/node-bitbankcc/lib/publicApi.js:23:13
    at tryCatcher (/home/ubuntu/influx-study/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/ubuntu/influx-study/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/ubuntu/influx-study/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/ubuntu/influx-study/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/ubuntu/influx-study/node_modules/bluebird/js/release/promise.js:689:18)
    at Async._drainQueue (/home/ubuntu/influx-study/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/home/ubuntu/influx-study/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/home/ubuntu/influx-study/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

Is this a temporary issue on the server side? Or some APIs were modified?

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.