概要
- Bitbankの公式API~日本語版~
- 公式サイトを見て、phpでデータ取得!
- phpのソースが無く困った〜;;時間かかった・・・コマンドで叩けば一発だった
準備
認証
パブリックAPI:認証情報無しでok!
プライベートAPI:認証情報必要!! HTTPリクエストヘッダーに付与してリクエストを行う。
ヘッダー
-
ACCESS-KEY
APIキーページで取得したAPIキー。 -
ACCESS-NONCE
整数値。(例) 1592996340
リクエスト毎に数を増加させる必要があります。
通常はUNIXタイムスタンプを使用してください。 -
ACCESS-SIGNATURE
署名を記述。
署名作成は、以下の文字列を HMAC-SHA256 形式でAPIシークレットキーを使って署名した結果となります。
【GETの場合】
「ACCESS-NONCE、リクエストのパス、クエリパラメータ」 を連結させたもの
【POSTの場合】
「ACCESS-NONCE、リクエストボディのJson文字列」 を連結させたもの
アセット
公式
アセット一覧を返す
GET /user/assets
https://api.bitbank.cc/v1/user/assets
HTTPリクエストヘッダー
ACCESS-KEY
:APIキー
ACCESS-NONCE
:UNIXタイムスタンプ
ACCESS-SIGNATURE
: "$ACCESS_NONCE/v1/user/assets"をHMAC-SHA256 形式でAPIシークレットキーを使って署名
公式のサンプルコード
ターミナル
export API_KEY=___your api key___
export API_SECRET=___your api secret___
export ACCESS_NONCE="$(date +%s)"
export ACCESS_SIGNATURE="$(echo -n "$ACCESS_NONCE/v1/user/assets" | openssl dgst -sha256 -hmac "$API_SECRET")"
curl -H 'ACCESS-KEY:'"$API_KEY"'' -H 'ACCESS-NONCE:'"$ACCESS_NONCE"'' -H 'ACCESS-SIGNATURE:'"$ACCESS_SIGNATURE"'' https://api.bitbank.cc/v1/user/assets
/**
* API_資産状況取得.
*
* @param Request $request
* @return void
*/
public function getUserAssets(Request $request) {
$ACCESS_NONCE = strtotime("now");
$API_KEY = env('BITBANK_API_KEY');
$API_SECRET = env('BITBANK_API_SECRET');
$API_URL = 'v1/user/assets';
$ACCESS_SIGNATURE = str_replace(
'(stdin)= ',
'',
exec(
"echo -n '{$ACCESS_NONCE}/{$API_URL}'| openssl dgst -sha256 -hmac '{$API_SECRET}'"
)
);
$json = exec("curl -H 'ACCESS-KEY:'{$API_KEY}'' -H 'ACCESS-NONCE:'{$ACCESS_NONCE}'' -H 'ACCESS-SIGNATURE:'{$ACCESS_SIGNATURE}'' https://api.bitbank.cc/{$API_URL}");
return response()->json(json_decode($json));
}
実行結果(json)
{
"success": 1,
"data": {
"assets": [
{
"asset": "jpy",
"amount_precision": 4,
"onhand_amount": "341373.8485",
"locked_amount": "341373.8456",
"free_amount": "0.0029",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": {
"threshold": "30000.0000",
"under": "550.0000",
"over": "770.0000"
}
},
{
"asset": "btc",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "0.00060000"
},
{
"asset": "ltc",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "0.00100000"
},
{
"asset": "xrp",
"amount_precision": 6,
"onhand_amount": "0.000000",
"locked_amount": "0.000000",
"free_amount": "0.000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "0.150000"
},
{
"asset": "eth",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "0.00500000"
},
{
"asset": "mona",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "0.00100000"
},
{
"asset": "bcc",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "0.00100000"
},
{
"asset": "xlm",
"amount_precision": 7,
"onhand_amount": "0.0000000",
"locked_amount": "0.0000000",
"free_amount": "0.0000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "0.0100000"
},
{
"asset": "qtum",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "0.01000000"
},
{
"asset": "bat",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "45.00000000"
},
{
"asset": "omg",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "5.00000000"
},
{
"asset": "xym",
"amount_precision": 6,
"onhand_amount": "0.000000",
"locked_amount": "0.000000",
"free_amount": "0.000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "2.000000"
},
{
"asset": "link",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "1.10000000"
},
{
"asset": "mkr",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "0.02000000"
},
{
"asset": "boba",
"amount_precision": 8,
"onhand_amount": "0.00000000",
"locked_amount": "0.00000000",
"free_amount": "0.00000000",
"stop_deposit": false,
"stop_withdrawal": false,
"withdrawal_fee": "17.00000000"
}
]
}
}