PowerShellでBitfinexのファンディング情報(lendbook)を取得する操作例を以下に記します。
Bitfinexでは、レンディングではなくファンディングと呼んでいるようですね。
Fundingbook APIのページを見ると lendbookとなっていますが…
Bitfinexのファンディング情報(lendbook)を取得するAPIドキュメントURL
Fundingbook API仕様は、以下のURLで確認してください。
https://bitfinex.readme.io/v1/reference#rest-public-fundingbook
以下、URLでBTCのファンディング(レンディング)情報が取得できます。
https://api.bitfinex.com/v1/lendbook/BTC
PowerShellのInvoke-RestMethodコマンドレットと、Invoke-WebRequest+ConvertFrom-Jsonコマンドレットを使って、
指定した通貨のファンディング(レンディング)情報を取得してみます。
Invoke-RestMethodコマンドレットを使用して、指定した通貨のファンディング(レンディング)情報を取得する操作例になります。
PS C:\> $v1_lendbook_api = "https://api.bitfinex.com/v1/lendbook/" PS C:\> $currency = "BTC" PS C:\> $lendbook = Invoke-RestMethod -UseBasicParsing ($v1_lendbook_api + $currency) PS C:\> $lendbook bids ---- {@{rate=5.548; amount=85.02918116; period=30; timestamp=1530817703.0; frr=No}, @{rate=5.548; amount=101.74978106; pe...
bits, asksの情報はデフォルトでは、最大50件となっていたので、取得件数を確認してみます。
PS C:\> $lendbook.bids.Count 50 PS C:\> $lendbook.asks.Count 50
パラメータとして、limit_bids, limit_asks があります。
これは、bids, asks の最大取得件数を指定するパラメータになります。
bids, asksともに2件と指定し、取得してみます。
PS C:\> $currency = "ETH" PS C:\> $limit_bids = 2 PS C:\> $limit_asks = 2 PS C:\> $lendbook = Invoke-RestMethod -UseBasicParsing ($v1_lendbook_api + $currency + "?limit_bids=${limit_bids}&limit_asks=${limit_asks}") PS C:\> $lendbook bids asks ---- ---- {@{rate=3.285; amount=677.4577947; period=30; timestamp=1531314687.0; frr=No}, @{rate=2.993; amount=1840.63028393; period=30; timestamp=1530807405.0; frr=No}} {@{rate=1.8826; amount=0.6076321; perio d=2; time...
PS C:\> $lendbook.bids.Count 2 PS C:\> $lendbook.asks.Count 2
PS C:\> $lendbook.bids rate : 3.285 amount : 677.4577947 period : 30 timestamp : 1531314687.0 frr : No rate : 2.993 amount : 1840.63028393 period : 30 timestamp : 1530807405.0 frr : No
PS C:\> $lendbook.asks rate : 1.8826 amount : 0.6076321 period : 2 timestamp : 1531409769.0 frr : No rate : 1.8826 amount : 0.420347 period : 2 timestamp : 1531409848.0 frr : No
bids, asksともに指定した件数が取得されているのが確認できます。
上記の例では、currencyにBTCとETHを指定しました。
Invoke-WebRequest使うことにより、HTTPステータスや、Content-Typeなどを取得することができます。
取得したContent部分をConvertFrom-Jsonコマンドレットを使うことにより、Invoke-RestMethodと同様に、
JSON形式でアクセスすることができます。
PS C:\> $v1_lendbook_api = "https://api.bitfinex.com/v1/lendbook/" PS C:\> $currency = "XRP" PS C:\> $limit_bids = 1 PS C:\> $limit_asks = 1 PS C:\> $response = Invoke-WebRequest -UseBasicParsing ($v1_lendbook_api + $currency + "?limit_bids=${limit_bids}&limit_asks=${limit_asks}")
PS C:\> $response StatusCode : 200 StatusDescription : OK Content : {"bids":[{"rate":"0.0219","amount":"12183.20629104","period":30,"timestamp":"1531288055.0","frr":"No"}],"asks":[{"rate":"0.0107","amount":"27999.95578344","period":2,"timestamp":"1531340089. 0","frr":"... 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: a13c409a-6ba4-4134-92fc-831a67d49c55 X... Forms : Headers : {[Connection, keep-alive], [X-Frame-Options, SAMEORIGIN,SAMEORIGIN], [X-XSS-Protection, 1; mode=block], [X-Content-Type-Options, nosniff]...} Images : {} InputFields : {} Links : {} ParsedHtml : RawContentLength : 206
PS C:\> $response.StatusCode 200 PS C:\> $response.Headers Key Value --- ----- Connection keep-alive X-Frame-Options SAMEORIGIN,SAMEORIGIN X-XSS-Protection 1; mode=block X-Content-Type-Options nosniff X-Request-Id a13c409a-6ba4-4134-92fc-831a67d49c55 X-Runtime 0.111515 Strict-Transport-Security max-age=31536000 Expect-CT max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" CF-RAY 4394ac61ce696ef9-NRT Content-Length 206 Cache-Control max-age=0, private, must-revalidate Content-Type application/json; charset=utf-8 Date Thu, 12 Jul 2018 15:51:49 GMT ETag W/"2307dfec05c81f6dec04bca6736668d9" Set-Cookie __cfduid=d8e96e5fad527ff5c6808a2c4275200b51531410708; expires=Fri, 12-Jul-19 15:51:48 GMT; path=/; domain=.bitfinex.com; HttpOnly Server cloudflare PS C:\> $response.Headers.'Content-Type' application/json; charset=utf-8
PS C:\> $json = ConvertFrom-Json $response.Content PS C:\> $json bids asks ---- ---- {@{rate=0.0219; amount=12183.20629104; period=30; timestamp=1531288055.0; frr=No}} {@{rate=0.0107; amount=27999.95578344; period=2; timestamp=1531340089.0; frr=No}}
上記のコマンドレットを実行すると、APIサーバとのやり取りのプログレスメッセージが表示されます。
これを非表示にしたい場合は、以下のようにしてください。
非表示にするには、$ProgressPreferenceにSilentlyContinueを設定します。
変更前は以下のように Continue が設定されています。
PS C:\> $ProgressPreference Continue
非表示にするには、以下のように変更します。
PS C:\> $ProgressPreference = "SilentlyContinue"
以上、PowerShellを使って、BitfinexのFundingbook APIを呼び出す方法でした。