当サイトに記載されている会社名、製品名などは一般に各社または団体の商標または登録商標です。
当サイトの資料により直接的および間接的障害が生じても一切責任を負いません。
あらかじめご了承ください。
PowerShellを使ってZaif のcurrency_pairs・通貨ペア情報を取得APIの使用例を以下に記します。
以下のバナーはZaif
へのリンクです。
PHP
PowerShell
公開APIなのでZaif に取引口座を開設していなくても使用することができます。
「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による操作方法を公開します。
PowerShellで呼び出す前にブラウザでアクセスしてみます。
https://api.zaif.jp/api/1/currency_pairs/all
FirefoxでアクセスするとJSONが以下のスクリーンショットのように表示されるので、とても見やすいです。
このJSONをPowerShellで取得し操作してみます。
以下の手順でZaifの通貨ペア情報を簡単に取得することができます。
PS C:\> $cur_pair_url = "https://api.zaif.jp/api/1/currency_pairs/all"
PS C:\> $cur_pair = Invoke-RestMethod $cur_pair_url
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
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
PS C:\> $cur_pair[0].currency_pair xcp_jpy PS C:\> $cur_pair[0].title XCP/JPY 取引所 - Zaif Exchange
以上のように簡単に、APIを呼び出し値にアクセスすることができます。
上記では、Invoke-RestMethodにてJSONをPowerShellで扱いやすい状態に変換してくれます。
しかし、Webサーバから返却された値を変換せず、取得後JSONを別のコマンドレットで変換する操作手順を以下に記します。
PS C:\> $cur_pair_url = "https://api.zaif.jp/api/1/currency_pairs/all"
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
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
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・日本円の取引を行うことができます