#author("2017-12-04T23:57:58+09:00","","")
#author("2017-12-07T00:36:55+09:00","","")
#navi(../)
* zaif取り扱い仮想通貨ペア一覧の取得サンプルコード(PHP) [#a8a50114]
&color(red){当サイトに記載されている会社名、製品名などは一般に各社または団体の商標または登録商標です。&br;当サイトの資料により直接的および間接的障害が生じても一切責任を負いません。&br;あらかじめご了承ください。};
----

PHPを使って&htmlinsert(zaif.html);が取り扱っている仮想通貨(通貨ペア)一覧を取得するサンプルコードを以下に記します。~
詳細な情報を取得する場合は、以下の記事を参照ください。~
-[[currency_pairs・通貨ペア情報を取得(PHP)>API/zaif/currency_pairs(PHP)]]


#contents
----
以下のバナーは&htmlinsert(zaif.html);へのリンクです。~
#htmlinsert(zaif_wide_1.html)

* 関連記事 [#s807f4c1]
-[[API動作環境構築>API/環境構築]]
-[[currencies・通貨情報の取得(PHP)>API/zaif/currencies(PHP)]]
-[[currency_pairs・通貨ペア情報を取得(PHP)>API/zaif/currency_pairs(PHP)]]
-[[last_price・現在の終値を取得(PHP)>API/zaif/last_price(PHP)]]
-[[ticker・ティッカーを取得(PHP)>API/zaif/ticker(PHP)]]
-[[depth・板情報を取得(PHP)>API/zaif/depth(PHP)]]
-[[trades・全ての取引履歴を取得(PHP)>API/zaif/trades(PHP)]]
-[[取引通貨一覧の取得(PHP)>API/zaif/取引通貨一覧の取得(PHP)]]

-[[ZaifのAPIキー生成手順>API/zaif/APIキー生成手順]]
-[[アカウントの残高確認(PHP)>API/zaif/残高確認・get_info, get_info2(PHP)]]

* トレードAPIで必要なcurrency_pair一覧を取得する [#icdc0b65]
本PHPサンプルコードは、以下の記事で紹介したサンプルコードを使用し、currency_pairのみ表示します。~
-[[currency_pairs・通貨ペア情報を取得(PHP)>API/zaif/currency_pairs(PHP)]]
トレードAPIにて売買通貨を指定する場合、currency_pairが必要になります。

** サンプルコード [#y8bdfbe1]
以下のサンプルコードを実行すると、&htmlinsert(zaif.html)で取り扱いされている通貨ペア一覧が表示されます。
#ref(zaif_cur_pairs.php.zip)
 <?php
 // API doc : http://techbureau-api-document.readthedocs.io/ja/latest/public/2_individual/2_currency_pairs.html
 // API url : https://api.zaif.jp/api/1/currency_pairs/{currency_pair}
 
 // currency_pair api url
 $zaif_api_url  = "https://api.zaif.jp/api/1/currency_pairs/";
 
 // proxy settings
 $proxy      = "";
 $proxy_port = "";
 
 $curl = curl_init();
 if ($curl == FALSE) {
     fputs(STDERR, "[ERR] curl_init(): " . curl_error($curl) . PHP_EOL);
     die(1);
 }
 
 // curl set options
 $currency = "all";  // all currency_pair
 curl_setopt($curl, CURLOPT_URL, $zaif_api_url . $currency);
 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 . ":" . $proxy_port);
     curl_setopt($curl, CURLOPT_PROXYPORT, $proxy_port);
 }
 
 // call currency_pair api
 $response = curl_exec($curl);
 if ($response == FALSE) {
     fputs(STDERR, "[ERR] curl_exec(): " . curl_error($curl) . PHP_EOL);
     die(1);
 }
 // json decode
 $json_decode = json_decode($response, true);
 if ($json_decode == NULL) {
     fputs(STDERR, "[ERR] json_decode(): " . json_last_error_msg() . PHP_EOL);
     die(1);
 }
 curl_close($curl);
 
 // show currency_pairs
 //print_r($json_decode);
 
 // sort by id
 foreach ($json_decode as $key => $value){
   $key_id[$key] = $value['id'];
 }
 array_multisort ($key_id , SORT_ASC , $json_decode);
 
 // show currency_pairs
 foreach ($json_decode as $cur_pair) {
     printf($cur_pair["currency_pair"] . PHP_EOL);
 }
 
 exit(0);

** 実行結果 [#k867dbea]
以下に上記のサンプルコードを実行したときの出力を記します。
 $ php zaif_cur_pairs.php
 btc_jpy
 mona_jpy
 mona_btc
 xem_jpy
 xem_btc
 zaif_jpy
 zaif_btc
 xcp_jpy
 xcp_btc
 bitcrystals_jpy
 bitcrystals_btc
 sjcx_jpy
 sjcx_btc
 fscc_jpy
 fscc_btc
 pepecash_jpy
 pepecash_btc
 cicc_jpy
 cicc_btc
 ncxc_jpy
 ncxc_btc
 jpyz_jpy
 bch_jpy
 bch_btc
 eth_jpy
 eth_btc
 erc20.cms_jpy
 mosaic.cms_jpy

この記事を書いている日にCOMSAが上場されました。~
COMSAも通貨ペア(currency_pair)に追加されているのが確認できます。
 $ php zaif_cur_pairs.php | grep cms
 erc20.cms_jpy
 mosaic.cms_jpy



以上、&htmlinsert(zaif.html);の公開APIである通貨ペア情報を取得APIをPHPで実行するサンプルコードでした。


----
以下のバナーは&htmlinsert(zaif.html);へのリンクです。~
#htmlinsert(zaif_wide_3.html)



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS