GetMarketSummaries(getmarketsummaries) APIでは、すべての通貨ペアのサマリ情報が表示されました。
今回は通貨ペアを特定するMarketIDを指定して、指定した通貨ペアのマーケットサマリ情報が取得できるgetmarketsummary APIについて記します。
GetMarketSummaries(getmarketsummaries) APIについては、以下の記事を参考にしてください。
CoinExchange.io
へのリンク
以下のURLは、XSH/DOGEペアのサマリが表示されます。(2018/6/6確認)
https://www.coinexchange.io/api/v1/getmarketsummary?market_id=705
ちなみにmarket_idを指定しないとエラーが返却されました。
getmarketsummary APIにはmarket_idにMarketIDを指定しないと動作しません。
このMarketIDの一覧は getmarkets APIで取得できます。
以下、実際に取得する手順を記します。
getmarkets APIに関しては以下の記事を参考にしてください。
PS C:\> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 PS C:\> $getmarkets_url = "https://www.coinexchange.io/api/v1/getmarkets" PS C:\> $markets = Invoke-RestMethod -UseBasicParsing $getmarkets_url
PS C:\> $markets success request message result ------- ------- ------- ------ 1 /api/v1/getmarkets {@{MarketID=18; MarketAssetName=Litecoin; MarketAssetCode=LTC; MarketAssetID=2; M...
PS C:\> $markets.result.Count 829 PS C:\> $markets.result[0] MarketID : 18 MarketAssetName : Litecoin MarketAssetCode : LTC MarketAssetID : 2 MarketAssetType : currency BaseCurrency : Bitcoin BaseCurrencyCode : BTC BaseCurrencyID : 1 Active : True
PS C:\> $markets.result | Format-Table | Select-Object -First 10 MarketID MarketAssetName MarketAssetCode MarketAssetID MarketAssetType BaseCurrency BaseCurrencyCode BaseCurrencyID Active -------- --------------- --------------- ------------- --------------- ------------ ---------------- -------------- ------ 18 Litecoin LTC 2 currency Bitcoin BTC 1 True 19 Unobtanium UNO 3 currency Bitcoin BTC 1 True 20 Syscoin SYS 5 currency Bitcoin BTC 1 False 21 Dogecoin DOGE 4 currency Bitcoin BTC 1 True 22 Kobocoin KOBO 6 currency Bitcoin BTC 1 True 23 Bitz BITZ 7 currency Bitcoin BTC 1 False 24 Digitalcoin DGC 8 currency Bitcoin BTC 1 True 25 Megacoin MEC 9 currency Bitcoin BTC 1 True PS C:\>一番左側にMarketIDが表示されています。
PS C:\> $markets.result | Format-Table | Out-String -Stream | Select-String XSH 704 Shield XSH 532 currency Bitcoin BTC 1 True 705 Shield XSH 532 currency Dogecoin DOGE 4 True 706 Shield XSH 532 currency Ethereum ETH 70 True
上記の操作により、MarketIDが取得&特定できたので、getmarketsummary APIを呼び出してみます。
以下の例はXSH/ETHになります。
PS C:\> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 PS C:\> $getmarketsummary_api = "https://www.coinexchange.io/api/v1/getmarketsummary" PS C:\> $market_id = 706 PS C:\> $response = Invoke-RestMethod -UseBasicParsing "${getmarketsummary_api}?market_id=${market_id}" PS C:\> $response.result MarketID : 706 LastPrice : 0.00004701 Change : -11.29 HighPrice : 0.00006440 LowPrice : 0.00004701 Volume : 2.82678779 BTCVolume : 0.22518192 TradeCount : 37 BidPrice : 0.00004260 AskPrice : 0.00005400 BuyOrderCount : 96 SellOrderCount : 432
上記では、Invoke-RestMethodにてJSONをPowerShellで扱いやすい状態に変換してくれますが、
Webサーバから返却された値を変換せずに取得したい場合は、Invoke-WebRequestコマンドレットを使用します。
また、取得後にJSONをPowerShellで扱いやすいオブジェクトに変換するには、ConvertFrom-Jsonコマンドレットを使用します。
以下に実行例を記します。
PS C:\> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 PS C:\> $XshEth = "https://www.coinexchange.io/api/v1/getmarketsummary?market_id=706" PS C:\> $response = Invoke-WebRequest -UseBasicParsing $XshEth PS C:\> $response StatusCode : 200 StatusDescription : OK Content : {"success":"1","request":"\/api\/v1\/getmarket","message":"","result":{"MarketID":"706","LastPrice":"0.00004701","Change":"-11.29"," HighPrice":"0.00006440","LowPrice":"0.00004701","Volume":"2.82678779... RawContent : HTTP/1.1 200 OK Connection: keep-alive x-frame-options: SAMEORIGIN Content-Length: 338 Cache-Control: no-cache Content-Type: application/json Date: Wed, 06 Jun 2018 15:16:28 GMT Set-Cookie: vis... Forms : Headers : {[Connection, keep-alive], [x-frame-options, SAMEORIGIN], [Content-Length, 338], [Cache-Control, no-cache]...} Images : {} InputFields : {} Links : {} ParsedHtml : RawContentLength : 338
PS C:\> $response.StatusCode 200 PS C:\> $response.Headers.'Content-Type' application/json
PS C:\> $json = ConvertFrom-Json($response.Content) PS C:\> $json success request message result ------- ------- ------- ------ 1 /api/v1/getmarket @{MarketID=706; LastPrice=0.00004701; Change=-11.29; HighPrice=0.00006440; LowPrice=0.00004701; Volume=2.82678779; ... PS C:\> $json.result MarketID : 706 LastPrice : 0.00004701 Change : -11.29 HighPrice : 0.00006440 LowPrice : 0.00004701 Volume : 2.82678779 BTCVolume : 0.22518192 TradeCount : 37 BidPrice : 0.00004260 AskPrice : 0.00005397 BuyOrderCount : 96 SellOrderCount : 435
上記のコマンドレットを実行すると、APIサーバとのやり取りのプログレスメッセージが表示されます。
これを非表示にしたい場合は、以下のようにしてください。
非表示にするには、$ProgressPreferenceにSilentlyContinueを設定します。
変更前は以下のように Continue が設定されています。
PS C:\> $ProgressPreference Continue
非表示にするには、以下のように変更します。
PS C:\> $ProgressPreference = "SilentlyContinue"
以上、PowerShellを使って、coinexchang.io.html is not found or not readable.の getmarketsummaryとgetmarkets APIを使って通貨ペアのマーケット情報を取得する操作例でした。
CoinExchange.io
へのリンク