#author("2018-04-25T13:22:18+09:00","","") #author("2018-04-25T13:28:36+09:00","","") #navi(../) * PowerShellでZaifの通貨ペア情報を取得するcurrency_pairsAPIの呼び出し方法 [#m01ef00c] &color(red){当サイトに記載されている会社名、製品名などは一般に各社または団体の商標または登録商標です。&br;当サイトの資料により直接的および間接的障害が生じても一切責任を負いません。&br;あらかじめご了承ください。}; ---- PowerShellを使って&htmlinsert(zaif.html);の[[currency_pairs・通貨ペア情報を取得>http://techbureau-api-document.readthedocs.io/ja/latest/public/2_individual/2_currency_pairs.html]]APIの使用例を以下に記します。 #contents ---- 以下のバナーは&htmlinsert(zaif.html);へのリンクです。~ #htmlinsert(zaif_wide_1.html) * 関連記事 [#g2d13b83] PHP~ -[[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)]] PowerShell~ -[[currency_pairs・通貨ペア情報を取得(PowerShell)>API/zaif/currency_pairs・通貨ペア情報を取得する方法(PowerShell)]] -[[ZaifのAPIキー生成手順>API/zaif/APIキー生成手順]] -[[アカウントの残高確認(PHP)>API/zaif/残高確認・get_info, get_info2(PHP)]] * ブラウザで通貨ペア情報APIを呼び出してみる [#of294028] 公開APIなので&htmlinsert(zaif.html);に取引口座を開設していなくても使用することができます。 「currency_pairs・通貨ペア情報を取得」API仕様(Zaif APIページから抜粋) ~ http://techbureau-api-document.readthedocs.io/ja/latest/public/2_individual/2_currency_pairs.html currency_pairs 通貨ペア情報を取得します。 リクエスト /currency_pairs/{currency_pair} 例. https://api.zaif.jp/api/1/currency_pairs/btc_jpy パラメータ なし 戻り値 currency_pairにallを指定した場合、有効な全ての通貨ペア情報を取得します。 キー 詳細 型 name 通貨ペアの名前 str title 通貨ペアのタイトル str currency_pair 通貨ペアのシステム文字列 str description 通貨ペアの詳細 str is_token token種別 boolean event_number イベントトークンの場合、0以外 int seq 通貨シークエンス int item_unit_min アイテム通貨最小値 float item_unit_step アイテム通貨入力単位 float item_japanese アイテム通貨 日本語表記 str aux_unit_min 相手通貨最小値 float aux_unit_step 相手通貨入力単位 float aux_unit_point 相手通貨小数点 int aux_japanese 相手通貨 日本語表記 str 以下、{currency_pair}にallを指定したPowerShellによる操作方法を公開します。 * ブラウザでアクセスしてみる [#d36f3b4f] PowerShellで呼び出す前にブラウザでアクセスしてみます。~ https://api.zaif.jp/api/1/currency_pairs/all~ FirefoxでアクセスするとJSONが以下のスクリーンショットのように表示されるので、とても見やすいです。~ #ref(01.png) このJSONをPowerShellで取得し操作してみます。 * Invoke-RestMethodコマンドレットで簡単に取得 [#e589c038] 以下の手順でZaifの通貨ペア情報を簡単に取得することができます。 +通貨ペアを取得するURLをせってしました。。 +通貨ペアを取得するURLを設定します。 PS C:\> $cur_pair_url = "https://api.zaif.jp/api/1/currency_pairs/all" + Invoke-RestMethodコマンドレットを使用し、返却された情報を$cur_pair変数に代入しました。 PS C:\> $cur_pair = Invoke-RestMethod $cur_pair_url + $cur_pairを表示すると、Zaifの通貨ペア情報を取得できているのが確認できます。 PS C:\> $cur_pair aux_unit_step : 0.0001 currency_pair : xcp_jpy id : 8 event_number : 0 seq : 8 name : XCP/JPY aux_unit_min : 0.0001 title : XCP/JPY 取引所 - Zaif Exchange item_unit_step : 0.1 aux_unit_point : 4 item_unit_min : 0.1 item_japanese : XCP aux_japanese : 日本円 description : XCP/JPY取引所。XCPと日本円の取引が行えます。 is_token : True aux_unit_step : 1E-08 currency_pair : pepecash_btc id : 130 event_number : 0 seq : 133 name : PEPECASH/BTC aux_unit_min : 1E-08 title : PEPECASH/BTC 取引所 - ZAIF Exchange item_unit_step : 1.0 aux_unit_point : 8 item_unit_min : 1.0 item_japanese : PEPECASH aux_japanese : ビットコイン description : PEPECASH/BTC 取引所。PEPECASHとビットコインの取引が行えます。 is_token : True <省略> 以下のように$cur_pair変数にアクセスします。 +通貨ペア数を取得してみました。 PS C:\> $cur_pair.Count 28 +28個取得した1番目の通貨ペア情報を表示してみます。 PS C:\> $cur_pair[0] aux_unit_step : 0.0001 currency_pair : xcp_jpy id : 8 event_number : 0 seq : 8 name : XCP/JPY aux_unit_min : 0.0001 title : XCP/JPY 取引所 - Zaif Exchange item_unit_step : 0.1 aux_unit_point : 4 item_unit_min : 0.1 item_japanese : XCP aux_japanese : 日本円 description : XCP/JPY取引所。XCPと日本円の取引が行えます。 is_token : True +1番目のcurrency_pair, titleを表示しています。 PS C:\> $cur_pair[0].currency_pair xcp_jpy PS C:\> $cur_pair[0].title XCP/JPY 取引所 - Zaif Exchange 以上のように簡単に、APIを呼び出し値にアクセスすることができます。 * HTTPステータスなどを取得したい場合 [#mb5903c7] 上記では、Invoke-RestMethodにてJSONをPowerShellで扱いやすい状態に変換してくれます。~ しかし、Webサーバから返却された値を変換せず、取得後JSONを別のコマンドレットで変換する操作手順を以下に記します。 + 通貨ペアを取得するURLを設定します。 PS C:\> $cur_pair_url = "https://api.zaif.jp/api/1/currency_pairs/all" + Invoke-WebRequestを使って、APIにリクエストし、レスポンスを$resに格納しています。 PS C:\> $res = Invoke-WebRequest -UseBasicParsing $cur_pair_url + 取得したレスポンスを表示しています。 PS C:\> $res StatusCode : 200 StatusDescription : OK Content : [{"aux_unit_min": 0.0001, "item_japanese": "\u30b6\u30a4\u30d5", "name": "ZAIF/JPY", "event_number" : 0, "item_unit_min": 0.1, "item_unit_step": 0.1, "is_token": true, "seq": 6, "id": 6, "aux_unit_po in... RawContent : HTTP/1.1 200 OK Connection: keep-alive Content-Length: 14042 Content-Type: application/json Date: Tue, 24 Apr 2018 15:49:48 GMT Set-Cookie: api.zaif.jp.chat_client_id=; Max-Age=0; Path=/; expires... Forms : Headers : {[Connection, keep-alive], [Content-Length, 14042], [Content-Type, application/json], [Date, Tue, 2 4 Apr 2018 15:49:48 GMT]...} Images : {} InputFields : {} Links : {} ParsedHtml : RawContentLength : 14042 + レスポンスのコンテンツ部分をConvertFrom-Jsonコマンドレットにて変換しています。 PS C:\> $res.Content | ConvertFrom-Json aux_unit_min : 0.0001 item_japanese : ザイフ name : ZAIF/JPY event_number : 0 item_unit_min : 0.1 item_unit_step : 0.1 is_token : True seq : 6 id : 6 aux_unit_point : 4 aux_japanese : 日本円 title : ZAIF取引所 - Zaif Exchange description : ZAIF取引所。ZAIFの取引が行えます。 aux_unit_step : 0.0001 currency_pair : zaif_jpy aux_unit_min : 0.0001 item_japanese : XEM name : XEM/JPY event_number : 0 item_unit_min : 0.1 item_unit_step : 0.1 is_token : False seq : 1 id : 4 aux_unit_point : 4 aux_japanese : 日本円 title : XEM/JPY description : XEM・日本円の取引を行うことができます aux_unit_step : 0.0001 currency_pair : xem_jpy +上記同様、変換した内容を$cur_pairに格納し、2番目の情報を指定して確認しています。 PS C:\> $cur_pair = ($res.Content | ConvertFrom-Json) PS C:\> $res.StatusCode 200 PS C:\> PS C:\> $cur_pair[1].title XEM/JPY PS C:\> $cur_pair[1].currency_pair xem_jpy PS C:\> $cur_pair[1].description XEM・日本円の取引を行うことができます 以上、PowerShellを使ってZaif APIにアクセスする方法でした。 ---- 以下のバナーは&htmlinsert(zaif.html);へのリンクです。~ #htmlinsert(zaif_wide_2.html)