#author("2018-07-13T09:19:59+09:00","","") #author("2018-07-13T09:23:05+09:00","","") #navi(../) * Bitfinexで指定した通貨ペアの取引量を取得する(API v1)(PowerShell) [#md3f7166] PowerShellでBitfinexのStats(取引量)を取得する例を以下に記します。 #contents #htmlinsert(cc-top.html) * 参考資料 [#lfbe48be] BitfinexのStats情報を取得するAPIドキュメントURL~ API仕様は、以下のURLで確認してください。~ https://bitfinex.readme.io/v1/reference#rest-public-stats * 関連記事 [#o9526099] -[[Bitfinexの通貨シンボル一覧の取得(API v1)(PowerShell)>API/Bitfinex/通貨ペアのシンボル一覧の取得(API v1)(PowerShell)]] -[[BitfinexのTickerの取得(API v1)(PowerShell)>API/Bitfinex/Tickerの取得(API v1)(PowerShell)]] -[[Bitfinexで指定した通貨ペアの取引量を取得する(API v1)(PowerShell)>API/Bitfinex/指定した通貨ペアの取引量を取得する(API v1)(PowerShell)]] -[[Bitfinexのファンディング情報を取得する(API v1)(PowerShell)>API/Bitfinex/ファンディング情報を取得する(API v1)(PowerShell)]] -[[Bitfinexの情報(注文一覧)を取得する(API v1)(PowerShell)>API/Bitfinex/情報情報(注文一覧)を取得する(API v1)(PowerShell)]] -[[Bitfinexの板情報(注文一覧)を取得する(API v1)(PowerShell)>API/Bitfinex/板情報(注文一覧)を取得する(API v1)(PowerShell)]] * ブラウザでアクセスしてみる [#o099729f] 以下、URLでStats(取引量)を取得できます。~ -BTC/USD~ https://api.bitfinex.com/v1/stats/btcusd~ Firefoxでアクセスした時のスクリーンショットです。~ |''JSON''| |&ref(01.png);| |''生データ''| |&ref(02.png);| #br -ETH/USD https://api.bitfinex.com/v1/stats/ethusd~ Firefoxでアクセスした時のスクリーンショットです。~ |''JSON''| |&ref(03.png);| |''生データ''| |&ref(04.png);| ''通貨シンボル一覧(通貨ペア一覧)''については、以下のリンク記事を参考にしてください。 -[[Bitfinexの通貨シンボル一覧の取得(API v1)(PowerShell)>API/Bitfinex/通貨ペアのシンボル一覧の取得(API v1)(PowerShell)]] * PowerShellによるアクセス [#r82dd07a] PowerShellの''Invoke-RestMethod''コマンドレットと、~ ''Invoke-WebRequest''+''ConvertFrom-Json''コマンドレットを使って、\~ BitfinexのStats(取引量)を取得してみます。 ** ''Invoke-RestMethod''コマンドレットでTickerを取得してみる [#c07a23c5] ''Invoke-RestMethod''コマンドレットを使用して、BitfinexのStatsを取得する操作例になります。~ 以下の操作例は、''ETH/BTC'', ''BTC/USD'', ''XLM/JPY''の通貨ペアを取得しています。~ ''通貨シンボル一覧(通貨ペア一覧)については、以下のリンク記事を参考にしてください。~ -[[Bitfinexの通貨シンボル一覧の取得(API v1)(PowerShell)>API/Bitfinex/通貨ペアのシンボル一覧の取得(API v1)(PowerShell)]] PS C:\> $v1_stats_api = "https://api.bitfinex.com/v1/stats/" PS C:\> $symbol = "ethbtc" PS C:\> $stats = Invoke-RestMethod -UseBasicParsing ($v1_stats_api + $symbol) PS C:\> $stats period volume ------ ------ 1 8259.31627208 7 92364.02434544 30 542880.30422806 PS C:\> $stats = Invoke-RestMethod -UseBasicParsing ($v1_stats_api + $symbol) PS C:\> $stats period volume ------ ------ 1 14889.14206645 7 126956.19372522 30 695910.44758821 PS C:\> $symbol = "xlmjpy" PS C:\> $stats = Invoke-RestMethod -UseBasicParsing ($v1_stats_api + $symbol) PS C:\> $stats period volume ------ ------ 1 6213.15634006 7 112901.38827411 30 314271.02362465 ** ''Invoke-WebRequest''+''ConvertFrom-Json''コマンドレットでTickerを取得する [#xaf4ef12] ''Invoke-WebRequest''使うことにより、HTTPステータスや、Content-Typeなどを取得することができます。~ 取得したContent部分を''ConvertFrom-Json''コマンドレットを使うことにより、Invoke-RestMethodと同様に、~ JSON形式でアクセスすることができます。 + Invoke-WebRequestでStats APIをアクセス PS C:\> $btcusd_stats_url = "https://api.bitfinex.com/v1/stats/btcusd" PS C:\> $response = Invoke-WebRequest -UseBasicParsing $btcusd_stats_url + 取得したレスポンスを表示します。 PS C:\> $response StatusCode : 200 StatusDescription : OK Content : [{"period":1,"volume":"14889.14206645"},{"period":7,"volume":"126956.19372522"},{"period":30,"volum e":"695910.44758821"}] RawContent : HTTP/1.1 200 OK Connection: keep-alive X-Frame-Options: SAMEORIGIN,SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff X-Request-Id: bc4db695-c18d-4e2d-9d03-22e71779a69b X... Forms : Headers : {[Connection, keep-alive], [X-Frame-Options, SAMEORIGIN,SAMEORIGIN], [X-XSS-Protection, 1; mode=blo ck], [X-Content-Type-Options, nosniff]...} Images : {} InputFields : {} Links : {} ParsedHtml : RawContentLength : 121 +ステータスコード、Content-Typeなどの値にアクセスしてみます。 PS C:\> $response.StatusCode 200 PS C:\> $response.Headers.'Content-Type' application/json; charset=utf-8 + ConvertFrom-Jsonコマンドレットを使うことにより、JSON形式に変換することができます。 PS C:\> $json = ConvertFrom-Json $response.Content PS C:\> $json period volume ------ ------ 1 20520.94195427 7 132625.56040943 30 701735.04395049 * Webの応答を読み取っています。(Waiting for response)を非表示にする方法 [#w12d22c6] 上記のコマンドレットを実行すると、APIサーバとのやり取りのプログレスメッセージが表示されます。~ #ref(51.png) これを非表示にしたい場合は、以下のようにしてください。 非表示にするには、$ProgressPreferenceにSilentlyContinueを設定します。~ 変更前は以下のように Continue が設定されています。 PS C:\> $ProgressPreference Continue 非表示にするには、以下のように変更します。 PS C:\> $ProgressPreference = "SilentlyContinue" 以上、PowerShellを使って、BitfinexのStats APIを呼び出す方法でした。 #htmlinsert(cc-btm.html)