皆さんはcoincheckで使えるAPIの存在はご存知でしょうか?
このブログに訪れたということは、これから暗号通貨取引を何らかのプログラムを使って自動化しようとお考えなのではないでしょうか?
暗号通貨で確実に利益を出すためには伸びている時に漬けておいても大丈夫ですが、アービトラージ取引であれば市場が乱高下している時でも安定して稼げるので仮想通貨取引に向いている手法だと言えます。
アービトラージ取引をする場合は手動で売買を繰り返すには限界があるので、プログラムで取引所のAPIを使い自動化してしまうのがもっとも効率的なのです。
そこで、比較的初心者でも扱いやすいJavaScript (Node) を使って仮想通貨取引所であるcoincheckのAPIの使い方について詳しく解説していきます。
coincheck (コインチェック) APIで何ができるのか?

coincheckAPIを使えば、取引所の管理画面で手動で行っていた操作をほとんどプログラム側で手を触れることなく操ることができるようになります。
具体的に何ができるかと言うと、板情報の取得・販売レートの取得・新規注文・ビットコインの送金など、取引を自動化する上で必要な操作をAPI経由で行うことができるようになります。
それ以外にも色々なことがAPIを通じて出来るので、他の仕様についても紹介していきたいと思います。
また、APIを利用する際には必ずコインチェックでの会員登録が必須になりますので、「https://coincheck.com/」にて登録と同時に本人確認も合わせて手続きを済ませておきましょう。
coincheck (コインチェック) APIの使い方と制限

coincheck APIの全ての機能を使うためには会員登録の後にAPIキーの作成を行う必要があります。
APIキーの作成をするためには取引所にログインした状態で「https://coincheck.com/ja/api_settings」にアクセスして、「新たにAPIキーを追加」するのボタンを押し、「パスワード」にコインチェックにログインする時と同じパスワードを入力しましょう。
また、新たにAPIキーを追加するためには二段階認証の設定をオンにしておく必要がありますので、「https://coincheck.com/ja/accounts/two_factor_auth」から設定を済ませておきましょう。
もしも、APIにアクセスできるIPアドレスに制限を掛けておきたい場合は、「編集」ボタンを押すとIPアドレスを入力する欄がありますので、設定しておくと良いでしょう。
完了すると、以下のように「アクセスキー」と「シークレットキー」が確認できる画面が表示されます。

coincheck API リファレンス (取引所)
coincheck APIには主に種類が二つあり、認証のないPublic APIと認証が必要なPrivate APIが存在します。
認証が必要な場合、先ほど作成したAPIキーとは別のシークレットキーを使いAPIにアクセスする必要がありますでの、まず以下のサンプルコードのようにCoincheckクラスを作成してAPIにアクセスする専用のメソッドを作成しておくと良いでしょう。
リクエストを送る際にsslを使用するので「crypto」と「request」モジュールを読み込んでおきましょう。
また、これから紹介していくコードに関しては基本的にクラスにメソッドを追加していく形で実装を行っていますので、どんどんクラスに書き足していきましょう。
そしてメソッドを実行する場合はコードの上部に「const coincheck = require('./coincheck.js');」と記述しておきましょう。
const crypto = require('crypto');
const request = require('request');
class Coincheck {
constructor() {
this.origin_url = 'https://coincheck.com/';
this.api_documents = `${this.origin_url}ja/documents/exchange/api`;
this.access_key = ''; //APIキー (アクセスキー)
this.secret_access_key = ''; //APIキー (シークレットキー)
}
api_request(path, query = '', method = 'GET') { //APIリクエスト
let self = this;
return new Promise(function(resolve, reject) {
let access_nonce = new Date().getTime();
let access_signature = crypto.createHmac('sha256', self.secret_access_key).update(`${access_nonce}${self.origin_url}${path}${query}`).digest('hex');
let options = {
url: `${self.origin_url}${path}${query}`,
method: method,
headers: {
'ACCESS-KEY': self.access_key,
'ACCESS-NONCE': access_nonce,
'ACCESS-SIGNATURE': access_signature
}
};
request(options, function(error, response, body) {
if(!error && response.statusCode == 200) {
let result = JSON.parse(body);
/* ========== debug ========== */
//console.log(JSON.stringify(result, undefined, 1));
resolve(result);
}
else {
/* ========== debug ========== */
//console.log(JSON.stringify(error, undefined, 1));
reject(error);
}
});
});
}
}
module.exports = new Coincheck();
ティッカー
GETメソッドで「/api/ticker」にリクエストを送れば、各種最新情報を得ることができます。
メソッドのサンプル
ticker() {
let self = this;
return (async function() {
let result = null;
let path = 'api/ticker';
result = await self.api_request(path);
return result;
})();
}
実行方法
(async function() {
let ticker = await coincheck.ticker();
console.log(ticker);
})();
実行結果
{
last: 6002000,
bid: 6002000,
ask: 6003772,
high: 6347536,
low: 5874060,
volume: 2783.75446399,
timestamp: 1616465602
}- last:最後の取引価格
- bid:現在の買い注文の最高価格
- ask:現在の売り注文の最安価格
- high:24時間での最高取引価格
- low:24時間での最安取引価格
- volume:24時間での取引量
- timestamp:現在の時刻
全取引履歴
GETメソッドで「/api/trades」にリクエストを送れば、最新の取引履歴を取得できます。
リクエストパラメーター
※ pair:取引ペア (btc_jpy、etc_jpy、fct_jpy、mona_jpy)
メソッドのサンプル
trades(dataset) {
let self = this;
return (async function() {
let result = null;
let path = 'api/trades';
let query = null;
if(dataset instanceof Object == true) {
if(dataset.pair) {
query = `?pair=${dataset.pair}`;
}
}
result = await self.api_request(path, query);
return result;
})();
}
実行方法
(async function() {
let trades = await coincheck.trades({
pair: 'btc_jpy'
});
console.log(trades);
});
実行結果
{
success: true,
pagination: {
limit: 10,
order: 'desc',
starting_after: null,
ending_before: null
},
data: [
{
id: 175860374,
amount: '0.0654',
rate: 5902789,
pair: 'btc_jpy',
order_type: 'buy',
created_at: '2021-03-24T04:27:09.000Z'
},
{
id: 175860373,
amount: '0.081',
rate: 5901239,
pair: 'btc_jpy',
order_type: 'sell',
created_at: '2021-03-24T04:27:06.000Z'
},
{
id: 175860372,
amount: '0.005',
rate: 5901239,
pair: 'btc_jpy',
order_type: 'sell',
created_at: '2021-03-24T04:27:05.000Z'
},
{
id: 175860371,
amount: '0.02',
rate: 5900582,
pair: 'btc_jpy',
order_type: 'sell',
created_at: '2021-03-24T04:26:59.000Z'
},
{
id: 175860370,
amount: '0.0654',
rate: 5900088,
pair: 'btc_jpy',
order_type: 'sell',
created_at: '2021-03-24T04:26:45.000Z'
},
{
id: 175860369,
amount: '0.005',
rate: 5902499,
pair: 'btc_jpy',
order_type: 'buy',
created_at: '2021-03-24T04:26:44.000Z'
},
{
id: 175860368,
amount: '0.029',
rate: 5901938,
pair: 'btc_jpy',
order_type: 'buy',
created_at: '2021-03-24T04:26:44.000Z'
},
{
id: 175860367,
amount: '0.00749906',
rate: 5901936,
pair: 'btc_jpy',
order_type: 'buy',
created_at: '2021-03-24T04:26:42.000Z'
},
{
id: 175860366,
amount: '0.01413561',
rate: 5899110,
pair: 'btc_jpy',
order_type: 'sell',
created_at: '2021-03-24T04:26:42.000Z'
},
{
id: 175860365,
amount: '0.31156439',
rate: 5900000,
pair: 'btc_jpy',
order_type: 'sell',
created_at: '2021-03-24T04:26:42.000Z'
}
]
}
板情報
GETメソッドで「/api/order_books」にリクエストを送れば、板情報を取得できます。
メソッドのサンプル
order_books() {
let self = this;
return (async function() {
let result = null;
let path = 'api/order_books';
result = await self.api_request(path);
return result;
})();
}
実行方法
(async function() {
let order_books = await coincheck.order_books();
console.log(order_books);
})();
実行結果
{
asks: [
[ '5903275.0', '0.0658' ],
[ '5903752.0', '0.01' ],
[ '5904057.0', '0.005' ],
...
],
bids: [
[ '5900780.0', '0.07' ],
[ '5900015.0', '0.04' ],
[ '5900012.0', '0.073' ],
...
]
}- asks:売り注文の情報
- bids:買い注文の情報
レート取得
GETメソッドで「/api/exchange/orders/rate」にリクエストを送れば、レート情報を取得できます。
リクエストパラメーター
- ※ order_type:注文のタイプ (sell または buy)
- ※ pair:取引ペア (btc_jpy、etc_jpy、fct_jpy、mona_jpy)
- amount:注文量
- price:注文金額
メソッドのサンプル
exchange_order_rate(dataset) {
let self = this;
return (async function() {
let result = null;
let path = 'api/exchange/orders/rate';
let query = null;
if(dataset instanceof Object == true) {
query = `?order_type=${dataset.order_type}&pair=${dataset.pair}`;
if(dataset.amount) {
query += `&amount=${dataset.amount}`;
}
if(dataset.price) {
query += `&price=${dataset.price}`;
}
}
result = await self.api_request(path, query);
return result;
})();
}
実行方法
(async function() {
let exchange_order_rate = await coincheck.exchange_order_rate({
order_type: 'sell',
pair: 'btc_jpy',
amount: 0.1
});
console.log(exchange_order_rate);
});
実行結果
{
success: true,
rate: '5875027.815',
amount: '0.1',
price: '587502.7815'
}- rate:注文レート
- price:注文金額
- amount:注文金額
販売レート取得
GETメソッドで「/api/rate/[pair]」の形でリクエストを送れば、販売所のレートを取得できます。
リクエストパラメーター
※ pair:通貨ペア
メソッドのサンプル
rate(dataset) {
let self = this;
return (async function() {
let result = null;
let path = null;
if(dataset instanceof Object == true) {
if(dataset.pair) {
path = `api/rate/${dataset.pair}`;
}
}
result = await self.api_request(path);
return result;
})();
}
実行方法
(async function() {
let rate = await coincheck.rate({
pair: 'btc_jpy'
});
console.log(rate);
})();
実行結果
{ rate: '5860123.5' }rate:レート
coincheck API リファレンス (Private)
取引所での新規注文とそのキャンセルや、自分の資産状況などを確認することができます。
詳しくは下記解説をご覧ください。
新規注文
POSTリクエストを「/api/exchange/orders」へ送ることで取引所に対して新規注文を行えます。
| 注文方法 (order_type) | 説明 | 必須パラメーター |
|---|---|---|
| buy | 指値注文 現物取引 買い |
|
| sell | 指値注文 現物取引 売り |
|
| market_buy | 成行注文 現物取引 買い | market_buy_amount:成り行きで買う場合の日本円金額 |
| market_sell | 成行注文 現物取引 売り | stop_loss_rate:逆指値レート |
リクエストパラメーター
- ※ pair:取引ペア
- ※ order_type:注文方法 (buy、sell、market_buy、market_sell)
- rate:注文レート
- amount:注文量
- market_buy_amount:成り行きで買う場合の日本円金額
- stop_loss_rate:逆指値レート
メソッドのサンプル
exchange_orders(dataset) {
let self = this;
return (async function() {
let result = null;
let path = 'api/exchange/orders';
let query = `?pair=${dataset.pair}&order_type=${dataset.order_type}`;
if(dataset instanceof Object == true) {
if(dataset.rate) {
query += `&rate=${dataset.rate}`;
}
if(dataset.amount) {
query += `&amount=${dataset.amount}`;
}
if(dataset.market_buy_amount) {
query += `&market_buy_amount=${dataset.market_buy_amount}`;
}
if(dataset.stop_loss_rate) {
query += `&stop_loss_rate=${dataset.stop_loss_rate}`;
}
}
result = await self.api_request(path, query, 'POST');
return result;
})();
}
実行方法
(async function() {
let exchange_orders = await coincheck.exchange_orders({
pair: 'btc_jpy',
order_type: 'sell',
rate: 30010.0,
amount: 1.3
});
console.log(exchange_orders);
});
実行結果
{
"success": true,
"id": 12345,
"rate": "30010.0",
"amount": "1.3",
"order_type": "sell",
"stop_loss_rate": null,
"pair": "btc_jpy",
"created_at": "2015-01-10T05:55:38.000Z"
}- id:新規注文のID
- rate:注文のレート
- amount:注文の量
- order_type:注文方法
- stop_loss_rate:逆指値レート
- pair:取引ぺア
- created_at:注文の作成日時
未決済の注文一覧
GETメソッドで「/api/exchange/orders/opens」にリクエストを送ることで、未決済の注文を取得できます。
メソッドのサンプル
exchange_orders_opens() {
let self = this;
return (async function() {
let result = null;
let path = 'api/exchange/orders/opens';
result = await self.api_request(path);
return result;
})();
}
実行方法
(async function() {
let exchange_orders_opens = await coincheck.exchange_orders_opens();
console.log(exchange_orders_opens);
});
実行結果
{
"success": true,
"orders": [
{
"id": 202835,
"order_type": "buy",
"rate": 26890,
"pair": "btc_jpy",
"pending_amount": "0.5527",
"pending_market_buy_amount": null,
"stop_loss_rate": null,
"created_at": "2015-01-10T05:55:38.000Z"
},
{
"id": 202836,
"order_type": "sell",
"rate": 26990,
"pair": "btc_jpy",
"pending_amount": "0.77",
"pending_market_buy_amount": null,
"stop_loss_rate": null,
"created_at": "2015-01-10T05:55:38.000Z"
},
{
"id": 38632107,
"order_type": "buy",
"rate": null,
"pair": "btc_jpy",
"pending_amount": null,
"pending_market_buy_amount": "10000.0",
"stop_loss_rate": "50000.0",
"created_at": "2016-02-23T12:14:50.000Z"
}
]
}- id:注文ID
- rate:注文レート
- pending_amount:注文未決済の量
- pending_market_buy_amount:注文の未決済量(現物成行買いのみ)
- order_type:注文タイプ (sell または buy)
- stop_loss_rate:逆指値レート
- pair:取引ペア
- created_at:注文作成日時
注文のキャンセル
DELETEメソッドを「/api/exchange/orders/[id]」の形で送ることで、注文のキャンセルができます。
リクエストパラメーター
id:新規注文か、未決済注文のID
メソッドのサンプル
exchange_order_cancel(dataset) {
let self = this;
return (async function() {
let result = null;
let path = null;
if(dataset instanceof Object == true) {
if(dataset.id) {
path = `api/exchange/orders/${dataset.id}`;
}
}
result = await self.api_request(path, '', 'DELETE');
return result;
})();
}
実行方法
(async function() {
let exchange_order_cancel = await coincheck.exchange_order_cancel({
id: 12345
});
console.log(exchange_order_cancel);
});
実行結果
{
"success": true,
"id": 12345
}id:キャンセルした注文ID
注文キャンセルのステータス
GETメソッドを「/api/exchange/orders/cancel_status?id=[id]」の形で送信することで、注文キャンセルの状況を確認することができます。
リクエストパラメーター
id:新規注文か、未決済注文のID
メソッドのサンプル
exchange_order_cancel_status(dataset) {
let self = this;
return (async function() {
let result = null;
let path = 'api/exchange/orders/cancel_status';
let query = null;
if(dataset instanceof Object == true) {
if(dataset.id) {
query = `?id=${dataset.id}`;
}
}
result = await self.api_request(path, query);
return result;
})();
}
実行方法
(async function() {
let exchange_order_cancel_status = await coincheck.exchange_order_cancel_status({
id: 12345
});
console.log(exchange_order_cancel_status);
});
実行結果
{
"success": true,
"id": 12345,
"cancel": true,
"created_at": "2020-07-29T17:09:33.000Z"
}- id:注文のID
- cancel:キャンセル済みかどうか
- 注文作成日時
取引履歴
GETメソッドを「/api/exchange/orders/transactions」に送ることで最近の取引履歴を確認できます。
メソッドのサンプル
exchange_orders_transactions() {
let self = this;
return (async function() {
let result = null;
let path = 'api/exchange/orders/transactions';
result = await self.api_request(path);
return result;
})();
}
実行方法
(async function() {
let exchange_orders_transactions = await coincheck.exchange_orders_transactions();
console.log(exchange_orders_transactions);
});
実行結果
{
"success": true,
"transactions": [
{
"id": 38,
"order_id": 49,
"created_at": "2015-11-18T07:02:21.000Z",
"funds": {
"btc": "0.1",
"jpy": "-4096.135"
},
"pair": "btc_jpy",
"rate": "40900.0",
"fee_currency": "JPY",
"fee": "6.135",
"liquidity": "T",
"side": "buy"
},
{
"id": 37,
"order_id": 48,
"created_at": "2015-11-18T07:02:21.000Z",
"funds": {
"btc": "-0.1",
"jpy": "4094.09"
},
"pair": "btc_jpy",
"rate": "40900.0",
"fee_currency": "JPY",
"fee": "-4.09",
"liquidity": "M",
"side": "sell"
}
]
}- id:ID
- order_id:注文ID
- created_at:取引が行われた時間
- funds:各残高の増減分
- pair:取引ペア
- rate:約定価格
- fee_currency:手数料の通貨
- fee:発生した手数料の額
- liquidity:Taker または Maker
- side:sell または buy
取引履歴 (ページネーション)
GETメソッドを「/api/exchange/orders/transactions_pagination」に送ることで、自分の最近の取引履歴を確認することができます。
メソッドのサンプル
exchange_orders_transactions_pagination() {
let self = this;
return (async function() {
let result = null;
let path = 'api/exchange/orders/transactions_pagination';
result = await self.api_request(path);
return result;
})();
}
実行方法
(async function() {
let exchange_orders_transactions_pagination = await coincheck.exchange_orders_transactions_pagination();
console.log(exchange_orders_transactions_pagination);
});
実行結果
{
"success": true,
"pagination": {
"limit": 1,
"order": "desc",
"starting_after": null,
"ending_before": null
},
"data": [
{
"id": 38,
"order_id": 49,
"created_at": "2015-11-18T07:02:21.000Z",
"funds": {
"btc": "0.1",
"jpy": "-4096.135"
},
"pair": "btc_jpy",
"rate": "40900.0",
"fee_currency": "JPY",
"fee": "6.135",
"liquidity": "T",
"side": "buy"
},
{
"id": 37,
"order_id": 48,
"created_at": "2015-11-18T07:02:21.000Z",
"funds": {
"btc": "-0.1",
"jpy": "4094.09"
},
"pair": "btc_jpy",
"rate": "40900.0",
"fee_currency": "JPY",
"fee": "-4.09",
"liquidity": "M",
"side": "sell"
}
]
}- id:ID
- order_id:注文ID
- created_at:取引が行われた時間
- funds:各残高の増減分
- pair:取引ペア
- rate:約定価格
- fee_currency:手数料の通貨
- liquidity:Taker または Maker
- side:sell または buy
coincheck API リファレンス (アカウント)
自分のアカウントの資産状況やその他各種情報を取得することができます。
詳しくは下記解説をご覧ください。
残高
GETメソッドを「/api/accounts/balance」に送ることで、アカウントの残高を確認できます。
メソッドのサンプル
accounts_balance() {
let self = this;
return (async function() {
let result = null;
let path = 'api/accounts/balance';
result = await self.api_request(path);
return result;
})();
}
実行方法
(async function() {
let accounts_balance = await coincheck.accounts_balance();
console.log(accounts_balance);
});
実行結果
{
"success": true,
"jpy": "0.8401",
"btc": "1.75052654",
"jpy_reserved": "3000.0",
"btc_reserved": "3.5002",
"jpy_lend_in_use": "0",
"btc_lend_in_use": "0.3",
"jpy_lent": "0",
"btc_lent": "1.2",
"jpy_debt": "0",
"btc_debt": "0"
}- jpy:日本円の残高
- btc:ビットコインの残高
- jpy_reserved:未決済の買い注文に利用している日本円の合計
- btc_reserved:未決済の売り注文に利用しているビットコインの合計
- jpy_lend_in_use:貸出申請をしている日本円の合計
- btc_lend_in_use: 貸出申請をしているビットコインの合計
- jpy_lent:貸出をしている日本円の合計
- btc_lent:貸出をしているビットコインの合計
- jpy_debt:借りている日本円の合計
- btc_debt:借りているビットコインの合計
ビットコインの送金
POSTリクエストを「/api/send_money」に送ることで、指定のアドレスにビットコインを送金することができます。
リクエストパラメーター
- ※ address:送り先のアドレス
- ※ 送りたいビットコインの量
メソッドのサンプル
post_send_money(dataset) {
let self = this;
return (async function() {
let result = null;
let path = 'api/send_money';
let query = null;
if(dataset instanceof Object == true) {
query = `?address=${dataset.address}&amount=${dataset.amount}`;
}
result = await self.api_request(path, query, 'POST');
return result;
})();
}
実行方法
(async function() {
let post_send_money = await coincheck.post_send_money({
address: '1v6zFvyNPgdRvhUufkRoTtgyiw1xigncc',
amount: 1.5
});
console.log(post_send_money);
});
実行結果
{
"success": true,
"id": "276",
"address": "1v6zFvyNPgdRvhUufkRoTtgyiw1xigncc",
"amount": "1.5",
"fee": "0.002"
}- id:送金時に割り振られるID
- address:送り先のアドレス
- amount:送ったビットコインの量
- fee:手数料
送金履歴
GETメソッドを「/api/send_money」に送ることで、ビットコインの送金履歴を確認できます。
リクエストパラメーター
※ currency:通貨
メソッドのサンプル
get_send_money(dataset) {
let self = this;
return (async function() {
let result = null;
let path = 'api/send_money';
let query = null;
if(dataset instanceof Object == true) {
if(dataset.currency) {
query = `?currency=${dataset.currency}`;
}
}
result = await self.api_request(path, query);
return result;
})();
}
実行方法
(async function() {
let get_send_money = await coincheck.get_send_money({
currency: 'BTC'
});
console.log(get_send_money);
});
実行結果
{
"success": true,
"sends": [
{
"id": 2,
"amount": "0.05",
"currency": "BTC",
"fee": "0.0",
"address": "13PhzoK8me3u5nHzzFD85qT9RqEWR9M4Ty",
"created_at": "2015-06-13T08:25:20.000Z"
},
{
"id": 1,
"amount": "0.05",
"currency": "BTC",
"fee": "0.0001",
"address": "118ekvRwx6uc4241jkuQt5eYvLiuWdMW2",
"created_at": "2015-06-13T08:21:18.000Z"
}
]
}- id:送金ID
- amount:送ったビットコインの量
- fee:手数料
- currency:通貨
- address:送り先のアドレス
- created_at:送金日時
受け取り履歴
GETメソッドを「/api/deposit_money」に送ることで、ビットコインの受け取り履歴を確認することができます。
リクエストパラメーター
※ currency:通貨
メソッドのサンプル
deposit_money(dataset) {
let self = this;
return (async function() {
let result = null;
let path = 'api/deposit_money';
let query = null;
if(dataset instanceof Object == true) {
if(dataset.currency) {
query = `?currency=${dataset.currency}`;
}
}
result = await self.api_request(path, query);
return result;
})();
}
実行方法
(async function() {
let deposit_money = await coincheck.deposit_money({
currency: 'BTC'
});
console.log(deposit_money);
});
実行結果
{
"success": true,
"deposits": [
{
"id": 2,
"amount": "0.05",
"currency": "BTC",
"address": "13PhzoK8me3u5nHzzFD85qT9RqEWR9M4Ty",
"status": "confirmed",
"confirmed_at": "2015-06-13T08:29:18.000Z",
"created_at": "2015-06-13T08:22:18.000Z"
},
{
"id": 1,
"amount": "0.01",
"currency": "BTC",
"address": "13PhzoK8me3u5nHzzFD85qT9RqEWR9M4Ty",
"status": "received",
"confirmed_at": "2015-06-13T08:21:18.000Z",
"created_at": "2015-06-13T08:21:18.000Z"
}
]
}- id:受け取りID
- amount:受け取ったビットコインの量
- currency:通貨
- address:受け取り元のアドレス
- status:ステータス
- confirmed_at:受け取りの認証日時
- created_at:受け取り日時
アカウント情報
GETメソッドを「/api/accounts」に送ることでアカウントの情報を取得できます。
メソッドのサンプル
accounts() {
let self = this;
return (async function() {
let result = null;
let path = 'api/accounts';
result = await self.api_request(path);
return result;
})();
}
実行方法
(async function() {
let accounts = await coincheck.accounts();
console.log(accounts);
});
実行結果
{
"success": true,
"id": 10000,
"email": "test@gmail.com",
"identity_status": "identity_pending",
"bitcoin_address": "1v6zFvyNPgdRvhUufkRoTtgyiw1xigncc",
"taker_fee": "0.15",
"maker_fee": "0.0",
"exchange_fees": {
"btc_jpy": {
"taker_fee": "0.15",
"maker_fee": "0.0"
},
"etc_jpy": {
"taker_fee": "0.0",
"maker_fee": "0.0"
},
"fct_jpy": {
"taker_fee": "0.1",
"maker_fee": "0.1"
},
"mona_jpy": {
"taker_fee": "0.0",
"maker_fee": "0.0"
}
}
}- id:アカウントID
- email:メールアドレス
- identity_status:本人確認書類の提出状況
- bitcoin_address:デポジット用ビットコインのアドレス
- taker_fee:Takerとして注文を行った場合の手数料
- maker_fee: Makerとして注文を行った場合の手数料
- exchange_fees:板ごとの手数料
coincheck API リファレンス (日本円出金)
日本円を銀行振り込みで出金できるようになります。
銀行口座一覧
GETメソッドを「/api/bank_accounts」に送ると、登録されている銀行口座を取得できます。
メソッドのサンプル
get_bank_accounts() {
let self = this;
return (async function() {
let result = null;
let path = 'api/bank_accounts';
result = await self.api_request(path);
return result;
})();
}
実行方法
(async function() {
let get_bank_accounts = await coincheck.get_bank_accounts();
console.log(get_bank_accounts);
});
実行結果
{
"success": true,
"data": [
{
"id": 243,
"bank_name": "みずほ",
"branch_name": "東京営業部",
"bank_account_type": "futsu",
"number": "0123456",
"name": "タナカ タロウ"
}
]
}- id:ID
- bank_name:銀行名
- branch_name:支店名
- bank_account_type:銀行口座の種類 (futsu または toza)
- number:口座番号
- name:口座名義
銀行口座の登録
POSTメソッドを「/api/bank_accounts」に送ることで、出金先の銀行口座を登録できます。
リクエストパラメーター
- ※ bank_name:銀行名
- ※ branch_name:支店名
- ※ bank_account_type:銀行口座の種類 (futsu または toza)
- number:口座番号 (文字)
- name:口座名義
メソッドのサンプル
post_bank_accounts(dataset) {
let self = this;
return (async function() {
let result = null;
let path = 'api/bank_accounts';
let query = null;
if(dataset instanceof Object == true) {
query = `?bank_name=${dataset.bank_name}&branch_name=${dataset.branch_name}&bank_account_type=${dataset.bank_account_type}&number${dataset.number}&${dataset.name}`;
}
result = await self.api_request(path, query, 'POST');
return result;
})();
}
実行方法
(async function() {
let post_bank_accounts = await coincheck.post_bank_accounts({
bank_name: '熊本',
branch_name: '田中',
bank_account_type: 'futsu',
number: '0123456',
name: 'hoge'
});
console.log(post_bank_accounts);
});
実行結果
{
"success": true,
"data": {
"id": 641,
"bank_name": "熊本",
"branch_name": "田中",
"bank_account_type": "futsu",
"number": "0123456",
"name": "hoge"
}
}- id:ID
- bank_name:銀行名
- branch_name:支店名
- bank_account_type:銀行口座の種類 (futsu または toza)
- number:口座番号 (文字)
- name:口座名義
銀行口座の削除
DELETEメソッドを「/api/bank_accounts/[id]」の形で送ることで、銀行口座の削除を行えます。
リクエストパラメーター
※ id:銀行口座一覧で表示されるID
メソッドのサンプル
delete_bank_accounts(dataset) {
let self = this;
return (async function() {
let result = null;
let path = null;
if(dataset instanceof Object == true) {
path = `/api/bank_accounts/${dataset.id}`;
}
result = await self.api_request(path, '', 'DELETE');
return result;
})();
}
実行方法
(async function() {
let delete_bank_accounts = await coincheck.delete_bank_accounts({
id: 0123456
});
console.log(delete_bank_accounts);
});
実行結果
{
"success": true
}
出金履歴
GETメソッドを「/api/withdraws」に送ることで、日本円の出金履歴を取得できます。
メソッドのサンプル
get_withdraws() {
let self = this;
return (async function() {
let result = null;
let path = 'api/withdraws';
result = await self.api_request(path);
return result;
})();
}
実行方法
(async function() {
let get_withdraws = await coincheck.get_withdraws();
console.log(get_withdraws);
});
実行結果
{
"success": true,
"pagination": {
"limit": 25,
"order": "desc",
"starting_after": null,
"ending_before": null
},
"data": [
{
"id": 398,
"status": "finished",
"amount": "242742.0",
"currency": "JPY",
"created_at": "2014-12-04T15:00:00.000Z",
"bank_account_id": 243,
"fee": "400.0",
"is_fast": true
}
]
}- id:ID
- status:出金の状態 ( pending:未処理、 processing:手続き中、 finished:完了、 canceled:キャンセル済み)
- amount:金額
- currency:通貨
- created_at:作成日時
- bank_account_id:銀行口座一覧に表示されるID
- fee:振り込み手数料
- is_fast:高速出金のオプション
出金申請の作成
POSTメソッドを「/api/withdraws」に送ると、日本円の出金申請ができます。
リクエストパラメーター
- bank_account_id:銀行口座一覧に表示されるID
- amount:金額
- currency:通貨
メソッドのサンプル
post_withdraws(dataset) {
let self = this;
return (async function() {
let result = null;
let path = 'api/withdraws';
let query = null;
if(dataset instanceof Object == true) {
query = `?bank_account_id${dataset.bank_account_id}&amount=${dataset.amount}¤cy=${dataset.currency}`;
}
result = await self.api_request(path, query, 'POST');
return result;
})();
}
実行方法
(async function() {
let post_withdraws = await coincheck.post_withdraws({
bank_account_id: 243,
amount: 10000,
currency: 'JPY'
});
console.log(post_withdraws);
});
実行結果
{
"success": true,
"data": {
"id": 1043,
"status": "pending",
"amount": "10000.0",
"currency": "JPY",
"created_at": "2015-08-31T11:32:45.213Z",
"bank_account_id": 243,
"fee": "300.0"
}
}- id:ID
- status:出金の状態 ( pending:未処理、 processing:手続き中、 finished:完了、 canceled:キャンセル済み)
- amount:金額
- currency:通貨
- created_at:作成日時
- bank_account_id:銀行口座一覧に表示されるID
- fee:振り込み手数料
出金申請のキャンセル
DELETEメソッドを「/api/withdraws/[id]」の形で送ることで、出金申請をキャンセルできます。
ただし、status が pending の出金申請のみキャンセルできます。
リクエストパラメーター
※ id:出金申請のID
メソッドのサンプル
delete_withdraws(dataset) {
let self = this;
return (async function() {
let result = null;
let path = 'api/withdraws/';
let query = null;
if(dataset instanceof Object == true) {
query = `?id${dataset.id}`;
}
result = await self.api_request(path, query, 'DELETE');
return result;
})();
}
実行方法
(async function() {
let delete_withdraws = await coincheck.delete_withdraws({
id: 0123456
});
console.log(delete_withdraws);
});
実行結果
{
"success": true
}
WebSocket API
リアルタイムで取引所に公開されている取引の履歴や板情報を取得することができます。
概要
「wss://ws-api.coincheck.com/」へWebSocket接続することにって結果を得られます。
メソッドのサンプル
ws_api_connection(dataset) {
let channel = null;
if(dataset instanceof Object == true) {
channel = `${dataset.pair}-${dataset.channel}`;
}
let client = new W3CWebSocket('wss://ws-api.coincheck.com/');
let send_data = JSON.stringify({
type: dataset.type,
channel: channel
});
client.onerror = function() {
console.log('Connection Error');
};
client.onopen = function() {
console.log('WebSocket Client Connected');
function sendData() {
if(client.readyState === client.OPEN) {
client.send(send_data);
setTimeout(sendData, 1000);
}
}
sendData();
};
client.onclose = function() {
console.log('echo-protocol Client Closed');
};
client.onmessage = function(e) {
if(typeof e.data === 'string') {
let result = JSON.parse(e.data);
if(dataset.type == 'orderbook') {
console.log(result[0]);
console.log(result[1]);
}
if(dataset.type == 'trades') {
console.log(result);
}
}
};
}
実行方法 (orderbook)
coincheck.ws_api_connection({
type: 'subscribe',
pair: 'btc_jpy',
channel: 'orderbook'
});
実行方法 (trades)
coincheck.ws_api_connection({
type: 'subscribe',
pair: 'btc_jpy',
channel: 'trades'
});
まとめ
今回は、coincheck APIを使い取引所のデータにアクセスしたり、出金などの方法ついて解説してきましたがいかがでしたでしょうか?
暗号通貨の取引を自動化する際は、取引所のAPIを使うことは必須になりますので、必ず使えるようにしておきましょう。
また、今回は自動売買の方法ではなく、あくまでAPIの使い方しか触れませんでしたので、ここからの実装は読者の方が行うことになります。
それでは皆さん良い投資ライフを!!
