API/zaif/残高確認・get_info, get_info2(PHP)
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* Zaifのアカウント残高をAPIで取得する・get_info, get_info...
get_info, get_info2 APIを使用することにより、&htmlinsert(...
以下にPHPを使用したサンプルソースおよび実行例を記します。
----
&color(red){当サイトに記載されている会社名、製品名などは...
----
#contents
#htmlinsert(zaif_wide_1.html)
* 関連記事 [#p1eb9f8d]
-[[API動作環境構築>API/環境構築]]
-[[currencies・通貨情報の取得(PHP)>API/zaif/currencies(PH...
-[[currency_pairs・通貨ペア情報を取得(PHP)>API/zaif/curre...
-[[last_price・現在の終値を取得(PHP)>API/zaif/last_price(...
-[[ticker・ティッカーを取得(PHP)>API/zaif/ticker(PHP)]]
-[[depth・板情報を取得(PHP)>API/zaif/depth(PHP)]]
-[[trades・全ての取引履歴を取得(PHP)>API/zaif/trades(PHP)]]
-[[取引通貨一覧の取得(PHP)>API/zaif/取引通貨一覧の取得(PH...
-[[ZaifのAPIキー生成手順>API/zaif/APIキー生成手順]]
-[[アカウントの残高確認(PHP)>API/zaif/残高確認・get_info,...
* get_info, get_info2 API使用 [#v9b03191]
本APIを使用するには、&htmlinsert(zaif.html);の口座開設が...
- ''get_info'' API仕様~
ZaifAPI ドキュメントページから抜粋
get_info
現在の残高(余力および残高・トークン)、APIキーの権限、...
パラメータ
なし
戻り値
<省略>
キー 詳細 型
funds 資産の残高 dict
deposit 資産の残高に注文情報を加味したもの dict
rights キーが保持している権限 dict
trade_count 実行したトレード数 int
open_orders アクティブな注文数 int
server_time UNIX時間で換算された日本時間 int
deposit計算式
depositは現在の資産の残高に注文情報を加味したものになり...
買い注文が存在する場合、その注文の値段と量をかけ合わせた...
売り注文が存在する場合は、その注文の量のみが加味されます。
- ''get_info2'' API仕様~
ZaifAPI ドキュメントページから抜粋
get_info2
get_infoの軽量版で、過去のトレード数を除く項目を返します。
<省略>
** get_info, get_info2 APIの違い [#nfd04909]
上記API仕様の抜粋に記されている通り、過去のトレード数の有...
[trade_count]
* 残高出力のサンプルコード [#n81195d8]
get_info, get_info2で取得したfundsとdeposit一覧を表示する...
get_info.phpもget_info''2''.phpの処理内容は全く同じです。~
メソッド名が異なるだけです。($method変数参照)
$ diff get_info.php get_info2.php
2c2
< // API doc : http://techbureau-api-document.readthedoc...
---
> // API doc : http://techbureau-api-document.readthedoc...
7c7
< $method = "get_info";
---
> $method = "get_info2";
メソッド名が異なるだけなので、get_info APIを使用したget_i...
(get_info2を使用したget_info2.phpもダウンロード可能です。)~
&ref(get_info.php.zip); &ref(get_info2.php.zip);~
<?php
// API doc : http://techbureau-api-document.readthedocs....
// zaif trade api url
$zaif_api_url = "https://api.zaif.jp/tapi";
// api method name
$method = "get_info";
// Please set API_KEY and API_SECRET_KEY
$API_KEY = "APIキーを設定してください";
$API_SECRET_KEY = "APIシークレットキーを設定してください...
// proxy settings
$proxy = "";
$proxy_port = "";
$nonce = time();
$body = http_build_query(
array(
"nonce"=>$nonce,
"method"=>$method
)
);
$signature = hash_hmac("sha512", $body, $API_SECRET_KEY);
$headers = array(
"Sign: {$signature}",
"Key: {$API_KEY}"
);
$curl = curl_init();
if ($curl == FALSE) {
fputs(STDERR, "[ERR] curl_init(): " . curl_error($cu...
die(1);
}
// curl set options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
// set proxy server settings
if (!empty($proxy) && !empty($proxy_port)) {
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($curl, CURLOPT_PROXY, $proxy . ":" . $pr...
curl_setopt($curl, CURLOPT_PROXYPORT, $proxy_port);
}
curl_setopt($curl, CURLOPT_URL, $zaif_api_url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
if ($response == FALSE) {
fputs(STDERR, "[ERR] curl_exec(): " . curl_error($cu...
die(1);
}
// json decode
$json_decode = json_decode($response, true);
if ($json_decode == NULL) {
fputs(STDERR, "[ERR] json_decode(): " . json_last_er...
die(1);
}
curl_close($curl);
//print_r($json_decode);
if (!$json_decode["success"]) {
fputs(STDERR, "[ERR] " . $json_decode["error"] . PHP...
die(1);
}
// funds key sort array
$funds = $json_decode["return"]["funds"];
ksort($funds);
// deposit key sort array
$deposit = $json_decode["return"]["deposit"];
ksort($deposit);
print("-------- Funds --------" . PHP_EOL);
foreach ($funds as $key => $val) {
printf("%10s\t%f" . PHP_EOL, $key, $val);
}
print("-------- Deposit --------" . PHP_EOL);
foreach ($deposit as $key => $val) {
printf("%10s\t%f" . PHP_EOL, $key, $val);
}
exit(0);
#htmlinsert(zaif_wide_2.html)
** APIキー, APIシークレットキー [#cb4af129]
上記サンプルコード内にある、以下の部分ですが、APIキーの設...
$API_KEY = "APIキーを設定してください";
$API_SECRET_KEY = "APIシークレットキーを設定してください...
以下の記事を参考にAPIキーを取得してください。
-[[Zaif APIキー生成手順>API/zaif/APIキー生成手順]]
APIキーを生成すると以下のスクリーンショットのように2つのA...
#ref(zaifapi.png)
* 実行例 [#bcb68e47]
上記のサンプルコードを実行した結果です。~
funds, depositを表示します。
$ php get_info.php
-------- Funds --------
BCH 0.000001
ETH 0.000001
PEPECASH 1.009010
ZAIF 1.000000
btc 0.010000
jpy 1.000000
mona 1.000000
xem 1.000000
-------- Deposit --------
BCH 0.000001
ETH 0.000001
PEPECASH 1.009010
ZAIF 1.000000
btc 0.010000
jpy 1.000000
mona 1.000000
xem 1.000000
以上、get_info, get_info2 APIを使用し残高を確認するサンプ...
#htmlinsert(zaif_wide_3.html)
終了行:
#navi(../)
* Zaifのアカウント残高をAPIで取得する・get_info, get_info...
get_info, get_info2 APIを使用することにより、&htmlinsert(...
以下にPHPを使用したサンプルソースおよび実行例を記します。
----
&color(red){当サイトに記載されている会社名、製品名などは...
----
#contents
#htmlinsert(zaif_wide_1.html)
* 関連記事 [#p1eb9f8d]
-[[API動作環境構築>API/環境構築]]
-[[currencies・通貨情報の取得(PHP)>API/zaif/currencies(PH...
-[[currency_pairs・通貨ペア情報を取得(PHP)>API/zaif/curre...
-[[last_price・現在の終値を取得(PHP)>API/zaif/last_price(...
-[[ticker・ティッカーを取得(PHP)>API/zaif/ticker(PHP)]]
-[[depth・板情報を取得(PHP)>API/zaif/depth(PHP)]]
-[[trades・全ての取引履歴を取得(PHP)>API/zaif/trades(PHP)]]
-[[取引通貨一覧の取得(PHP)>API/zaif/取引通貨一覧の取得(PH...
-[[ZaifのAPIキー生成手順>API/zaif/APIキー生成手順]]
-[[アカウントの残高確認(PHP)>API/zaif/残高確認・get_info,...
* get_info, get_info2 API使用 [#v9b03191]
本APIを使用するには、&htmlinsert(zaif.html);の口座開設が...
- ''get_info'' API仕様~
ZaifAPI ドキュメントページから抜粋
get_info
現在の残高(余力および残高・トークン)、APIキーの権限、...
パラメータ
なし
戻り値
<省略>
キー 詳細 型
funds 資産の残高 dict
deposit 資産の残高に注文情報を加味したもの dict
rights キーが保持している権限 dict
trade_count 実行したトレード数 int
open_orders アクティブな注文数 int
server_time UNIX時間で換算された日本時間 int
deposit計算式
depositは現在の資産の残高に注文情報を加味したものになり...
買い注文が存在する場合、その注文の値段と量をかけ合わせた...
売り注文が存在する場合は、その注文の量のみが加味されます。
- ''get_info2'' API仕様~
ZaifAPI ドキュメントページから抜粋
get_info2
get_infoの軽量版で、過去のトレード数を除く項目を返します。
<省略>
** get_info, get_info2 APIの違い [#nfd04909]
上記API仕様の抜粋に記されている通り、過去のトレード数の有...
[trade_count]
* 残高出力のサンプルコード [#n81195d8]
get_info, get_info2で取得したfundsとdeposit一覧を表示する...
get_info.phpもget_info''2''.phpの処理内容は全く同じです。~
メソッド名が異なるだけです。($method変数参照)
$ diff get_info.php get_info2.php
2c2
< // API doc : http://techbureau-api-document.readthedoc...
---
> // API doc : http://techbureau-api-document.readthedoc...
7c7
< $method = "get_info";
---
> $method = "get_info2";
メソッド名が異なるだけなので、get_info APIを使用したget_i...
(get_info2を使用したget_info2.phpもダウンロード可能です。)~
&ref(get_info.php.zip); &ref(get_info2.php.zip);~
<?php
// API doc : http://techbureau-api-document.readthedocs....
// zaif trade api url
$zaif_api_url = "https://api.zaif.jp/tapi";
// api method name
$method = "get_info";
// Please set API_KEY and API_SECRET_KEY
$API_KEY = "APIキーを設定してください";
$API_SECRET_KEY = "APIシークレットキーを設定してください...
// proxy settings
$proxy = "";
$proxy_port = "";
$nonce = time();
$body = http_build_query(
array(
"nonce"=>$nonce,
"method"=>$method
)
);
$signature = hash_hmac("sha512", $body, $API_SECRET_KEY);
$headers = array(
"Sign: {$signature}",
"Key: {$API_KEY}"
);
$curl = curl_init();
if ($curl == FALSE) {
fputs(STDERR, "[ERR] curl_init(): " . curl_error($cu...
die(1);
}
// curl set options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
// set proxy server settings
if (!empty($proxy) && !empty($proxy_port)) {
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($curl, CURLOPT_PROXY, $proxy . ":" . $pr...
curl_setopt($curl, CURLOPT_PROXYPORT, $proxy_port);
}
curl_setopt($curl, CURLOPT_URL, $zaif_api_url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
if ($response == FALSE) {
fputs(STDERR, "[ERR] curl_exec(): " . curl_error($cu...
die(1);
}
// json decode
$json_decode = json_decode($response, true);
if ($json_decode == NULL) {
fputs(STDERR, "[ERR] json_decode(): " . json_last_er...
die(1);
}
curl_close($curl);
//print_r($json_decode);
if (!$json_decode["success"]) {
fputs(STDERR, "[ERR] " . $json_decode["error"] . PHP...
die(1);
}
// funds key sort array
$funds = $json_decode["return"]["funds"];
ksort($funds);
// deposit key sort array
$deposit = $json_decode["return"]["deposit"];
ksort($deposit);
print("-------- Funds --------" . PHP_EOL);
foreach ($funds as $key => $val) {
printf("%10s\t%f" . PHP_EOL, $key, $val);
}
print("-------- Deposit --------" . PHP_EOL);
foreach ($deposit as $key => $val) {
printf("%10s\t%f" . PHP_EOL, $key, $val);
}
exit(0);
#htmlinsert(zaif_wide_2.html)
** APIキー, APIシークレットキー [#cb4af129]
上記サンプルコード内にある、以下の部分ですが、APIキーの設...
$API_KEY = "APIキーを設定してください";
$API_SECRET_KEY = "APIシークレットキーを設定してください...
以下の記事を参考にAPIキーを取得してください。
-[[Zaif APIキー生成手順>API/zaif/APIキー生成手順]]
APIキーを生成すると以下のスクリーンショットのように2つのA...
#ref(zaifapi.png)
* 実行例 [#bcb68e47]
上記のサンプルコードを実行した結果です。~
funds, depositを表示します。
$ php get_info.php
-------- Funds --------
BCH 0.000001
ETH 0.000001
PEPECASH 1.009010
ZAIF 1.000000
btc 0.010000
jpy 1.000000
mona 1.000000
xem 1.000000
-------- Deposit --------
BCH 0.000001
ETH 0.000001
PEPECASH 1.009010
ZAIF 1.000000
btc 0.010000
jpy 1.000000
mona 1.000000
xem 1.000000
以上、get_info, get_info2 APIを使用し残高を確認するサンプ...
#htmlinsert(zaif_wide_3.html)
ページ名: