API/zaif/last_price(PHP)
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* zaifのlast_price・現在の終値を取得APIのサンプルコード(P...
&color(red){当サイトに記載されている会社名、製品名などは...
----
PHPを使って&htmlinsert(zaif.html);の[[last_price・現在の...
#contents
----
以下のバナーは&htmlinsert(zaif.html);へのリンクです。~
#htmlinsert(zaif_wide_1.html)
* 関連記事 [#t71ff04c]
-[[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,...
* ブラウザで通貨情報を取得APIを呼び出してみる [#tb8aab3f]
公開APIなので&htmlinsert(zaif.html);に取引口座を開設して...
「last_price・現在の終値を取得」API仕様(Zaif APIページか...
http://techbureau-api-document.readthedocs.io/ja/latest/p...
last_price
現在の終値を取得します。
リクエスト
/last_price/{currency_pair}
例. https://api.zaif.jp/api/1/last_price/btc_jpy
currency_pairに指定できる値は currency_pairs を参照して...
パラメータ
なし
戻り値
last_price 現在の終値 float
上記の指定するcurrency_pairsですが、以下のAPIサンプルコー...
-[[currency_pairs・通貨ペア情報を取得(PHP)>API/zaif/curre...
* ブラウザで現在の終値を取得 [#n1ff8c26]
GETなのでブラウザで現在の終値を取得することができます。~
以下は{currency_pair}にxem_jpyを指定しています。~
https://api.zaif.jp/api/1/last_price/xem_jpy
* ブラウザで現在の終値を取得APIにアクセスした結果 [#s0a0d...
以下ブラウザから上記URLにアクセスしたときの出力です。
-Firefox ver56.0~
JSONが整形され表示されています。~
見やすいですね。~
(生データをクリックすると上記同様にJSON形式の返却された文...
#ref(01.png)
----
以下のバナーは&htmlinsert(zaif.html);へのリンクです。~
#htmlinsert(zaif_wide_2.html)
* PHPで「last_price・現在の終値を取得」APIを呼び出してみ...
PHPのサンプルコードは以下のようになります。
#ref(last_price.php.zip)
<?php
// API doc : http://techbureau-api-document.readthedocs....
// API url : https://api.zaif.jp/api/1/last_price/{curre...
// last_price api url
$zaif_api_url = "https://api.zaif.jp/api/1/last_price/";
// proxy settings
$proxy = "";
$proxy_port = "";
$currency_pairs = array(
"bch_btc" ,"bch_jpy" ,"bitcrystals_btc"
,"bitcrystals_jpy" ,"btc_jpy" ,"cicc_btc"
,"cicc_jpy" ,"eth_btc" ,"eth_jpy"
,"fscc_btc" ,"fscc_jpy" ,"jpyz_jpy"
,"mona_btc" ,"mona_jpy" ,"ncxc_btc"
,"ncxc_jpy" ,"pepecash_btc" ,"pepecash_jpy"
,"sjcx_btc" ,"sjcx_jpy" ,"xcp_btc"
,"xcp_jpy" ,"xem_btc" ,"xem_jpy"
,"zaif_btc" ,"zaif_jpy"
);
if (!check_arguments($argc, $argv, $currency_pairs)) {
usage();
die(1);
}
// show currency pairs
if ($argv[1] == "list") {
print("- currency_pairs -" . PHP_EOL);
foreach ($currency_pairs as $value) {
printf("%s" . PHP_EOL, $value);
}
exit(0);
}
if ($argv[1] != "all") {
$currency_pairs = array($argv[1]);
}
$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);
}
// call last_price api
foreach ($currency_pairs as $currency) {
curl_setopt($curl, CURLOPT_URL, $zaif_api_url . $cur...
$response = curl_exec($curl);
if ($response == FALSE) {
fputs(STDERR, "[ERR] curl_exec(): " . curl_error...
die(1);
}
// json decode
$json_decode = json_decode($response, true);
if ($json_decode == NULL) {
fputs(STDERR, "[ERR] json_decode(): " . json_las...
die(1);
}
//print_r($json_decode);
printf("%s : %f" . PHP_EOL, $currency, $json_decode[...
}
curl_close($curl);
exit(0);
//------------------------------
// function
//------------------------------
function check_arguments($argc, $argv, $currency_pair) {
if ($argc != 2) {
return FALSE;
}
$opts = $currency_pair;
array_push($opts, "all", "list");
if (!in_array($argv[1], $opts)) {
return FALSE;
}
return TRUE;
}
function usage() {
fputs(STDERR,
"Usage: php last_price.php OPTION" . PHP_EOL .
"OPTION:" . PHP_EOL .
" all : show all currency pair price" . PHP_E...
" list : show all currency pair code" . PHP_EO...
" currency pair code : show specified currency...
" e.g. php last_price.php btc_jpy" . PHP_E...
PHP_EOL);
}
* 実行例 [#kae1674d]
上記のPHPサンプルソースを実行してみます。~
** オプション [#hf6d14ec]
-- all すべての通貨の現在の終値を表示します。
-- list 通貨ペアコード一覧を表示します。
-- 通貨ペアコード(e.g. btc_jpy) 指定した通貨ペアコードの...
** listで実行 [#cde823bc]
$ php last_price.php list
- currency_pairs -
bch_btc
bch_jpy
bitcrystals_btc
bitcrystals_jpy
btc_jpy
cicc_btc
cicc_jpy
eth_btc
eth_jpy
fscc_btc
fscc_jpy
jpyz_jpy
mona_btc
mona_jpy
ncxc_btc
ncxc_jpy
pepecash_btc
pepecash_jpy
sjcx_btc
sjcx_jpy
xcp_btc
xcp_jpy
xem_btc
xem_jpy
zaif_btc
zaif_jpy
** allで実行 [#g504dc36]
$ php last_price.php all
bch_btc : 0.085200
bch_jpy : 70100.000000
bitcrystals_btc : 0.000050
bitcrystals_jpy : 36.100100
btc_jpy : 815005.000000
cicc_btc : 0.000023
cicc_jpy : 14.500000
eth_btc : 0.041000
eth_jpy : 33600.000000
fscc_btc : 0.000041
fscc_jpy : 33.000100
jpyz_jpy : 1.300000
mona_btc : 0.000380
mona_jpy : 302.900000
ncxc_btc : 0.000148
ncxc_jpy : 111.900200
pepecash_btc : 0.000003
pepecash_jpy : 2.190200
sjcx_btc : 0.000105
sjcx_jpy : 64.889900
xcp_btc : 0.001781
xcp_jpy : 1360.100000
xem_btc : 0.000025
xem_jpy : 20.439900
zaif_btc : 0.000001
zaif_jpy : 0.492700
** 通貨ペアコードを指定して実行 [#q0461ebe]
$ php last_price.php btc_jpy
btc_jpy : 816530.000000
$ php last_price.php zaif_jpy
zaif_jpy : 0.492700
$ php last_price.php mona_jpy
mona_jpy : 305.400000
以上、&htmlinsert(zaif.html);の公開APIである現在の終値を...
----
以下のバナーは&htmlinsert(zaif.html);へのリンクです。~
#htmlinsert(zaif_wide_3.html)
終了行:
#navi(../)
* zaifのlast_price・現在の終値を取得APIのサンプルコード(P...
&color(red){当サイトに記載されている会社名、製品名などは...
----
PHPを使って&htmlinsert(zaif.html);の[[last_price・現在の...
#contents
----
以下のバナーは&htmlinsert(zaif.html);へのリンクです。~
#htmlinsert(zaif_wide_1.html)
* 関連記事 [#t71ff04c]
-[[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,...
* ブラウザで通貨情報を取得APIを呼び出してみる [#tb8aab3f]
公開APIなので&htmlinsert(zaif.html);に取引口座を開設して...
「last_price・現在の終値を取得」API仕様(Zaif APIページか...
http://techbureau-api-document.readthedocs.io/ja/latest/p...
last_price
現在の終値を取得します。
リクエスト
/last_price/{currency_pair}
例. https://api.zaif.jp/api/1/last_price/btc_jpy
currency_pairに指定できる値は currency_pairs を参照して...
パラメータ
なし
戻り値
last_price 現在の終値 float
上記の指定するcurrency_pairsですが、以下のAPIサンプルコー...
-[[currency_pairs・通貨ペア情報を取得(PHP)>API/zaif/curre...
* ブラウザで現在の終値を取得 [#n1ff8c26]
GETなのでブラウザで現在の終値を取得することができます。~
以下は{currency_pair}にxem_jpyを指定しています。~
https://api.zaif.jp/api/1/last_price/xem_jpy
* ブラウザで現在の終値を取得APIにアクセスした結果 [#s0a0d...
以下ブラウザから上記URLにアクセスしたときの出力です。
-Firefox ver56.0~
JSONが整形され表示されています。~
見やすいですね。~
(生データをクリックすると上記同様にJSON形式の返却された文...
#ref(01.png)
----
以下のバナーは&htmlinsert(zaif.html);へのリンクです。~
#htmlinsert(zaif_wide_2.html)
* PHPで「last_price・現在の終値を取得」APIを呼び出してみ...
PHPのサンプルコードは以下のようになります。
#ref(last_price.php.zip)
<?php
// API doc : http://techbureau-api-document.readthedocs....
// API url : https://api.zaif.jp/api/1/last_price/{curre...
// last_price api url
$zaif_api_url = "https://api.zaif.jp/api/1/last_price/";
// proxy settings
$proxy = "";
$proxy_port = "";
$currency_pairs = array(
"bch_btc" ,"bch_jpy" ,"bitcrystals_btc"
,"bitcrystals_jpy" ,"btc_jpy" ,"cicc_btc"
,"cicc_jpy" ,"eth_btc" ,"eth_jpy"
,"fscc_btc" ,"fscc_jpy" ,"jpyz_jpy"
,"mona_btc" ,"mona_jpy" ,"ncxc_btc"
,"ncxc_jpy" ,"pepecash_btc" ,"pepecash_jpy"
,"sjcx_btc" ,"sjcx_jpy" ,"xcp_btc"
,"xcp_jpy" ,"xem_btc" ,"xem_jpy"
,"zaif_btc" ,"zaif_jpy"
);
if (!check_arguments($argc, $argv, $currency_pairs)) {
usage();
die(1);
}
// show currency pairs
if ($argv[1] == "list") {
print("- currency_pairs -" . PHP_EOL);
foreach ($currency_pairs as $value) {
printf("%s" . PHP_EOL, $value);
}
exit(0);
}
if ($argv[1] != "all") {
$currency_pairs = array($argv[1]);
}
$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);
}
// call last_price api
foreach ($currency_pairs as $currency) {
curl_setopt($curl, CURLOPT_URL, $zaif_api_url . $cur...
$response = curl_exec($curl);
if ($response == FALSE) {
fputs(STDERR, "[ERR] curl_exec(): " . curl_error...
die(1);
}
// json decode
$json_decode = json_decode($response, true);
if ($json_decode == NULL) {
fputs(STDERR, "[ERR] json_decode(): " . json_las...
die(1);
}
//print_r($json_decode);
printf("%s : %f" . PHP_EOL, $currency, $json_decode[...
}
curl_close($curl);
exit(0);
//------------------------------
// function
//------------------------------
function check_arguments($argc, $argv, $currency_pair) {
if ($argc != 2) {
return FALSE;
}
$opts = $currency_pair;
array_push($opts, "all", "list");
if (!in_array($argv[1], $opts)) {
return FALSE;
}
return TRUE;
}
function usage() {
fputs(STDERR,
"Usage: php last_price.php OPTION" . PHP_EOL .
"OPTION:" . PHP_EOL .
" all : show all currency pair price" . PHP_E...
" list : show all currency pair code" . PHP_EO...
" currency pair code : show specified currency...
" e.g. php last_price.php btc_jpy" . PHP_E...
PHP_EOL);
}
* 実行例 [#kae1674d]
上記のPHPサンプルソースを実行してみます。~
** オプション [#hf6d14ec]
-- all すべての通貨の現在の終値を表示します。
-- list 通貨ペアコード一覧を表示します。
-- 通貨ペアコード(e.g. btc_jpy) 指定した通貨ペアコードの...
** listで実行 [#cde823bc]
$ php last_price.php list
- currency_pairs -
bch_btc
bch_jpy
bitcrystals_btc
bitcrystals_jpy
btc_jpy
cicc_btc
cicc_jpy
eth_btc
eth_jpy
fscc_btc
fscc_jpy
jpyz_jpy
mona_btc
mona_jpy
ncxc_btc
ncxc_jpy
pepecash_btc
pepecash_jpy
sjcx_btc
sjcx_jpy
xcp_btc
xcp_jpy
xem_btc
xem_jpy
zaif_btc
zaif_jpy
** allで実行 [#g504dc36]
$ php last_price.php all
bch_btc : 0.085200
bch_jpy : 70100.000000
bitcrystals_btc : 0.000050
bitcrystals_jpy : 36.100100
btc_jpy : 815005.000000
cicc_btc : 0.000023
cicc_jpy : 14.500000
eth_btc : 0.041000
eth_jpy : 33600.000000
fscc_btc : 0.000041
fscc_jpy : 33.000100
jpyz_jpy : 1.300000
mona_btc : 0.000380
mona_jpy : 302.900000
ncxc_btc : 0.000148
ncxc_jpy : 111.900200
pepecash_btc : 0.000003
pepecash_jpy : 2.190200
sjcx_btc : 0.000105
sjcx_jpy : 64.889900
xcp_btc : 0.001781
xcp_jpy : 1360.100000
xem_btc : 0.000025
xem_jpy : 20.439900
zaif_btc : 0.000001
zaif_jpy : 0.492700
** 通貨ペアコードを指定して実行 [#q0461ebe]
$ php last_price.php btc_jpy
btc_jpy : 816530.000000
$ php last_price.php zaif_jpy
zaif_jpy : 0.492700
$ php last_price.php mona_jpy
mona_jpy : 305.400000
以上、&htmlinsert(zaif.html);の公開APIである現在の終値を...
----
以下のバナーは&htmlinsert(zaif.html);へのリンクです。~
#htmlinsert(zaif_wide_3.html)
ページ名: