LoginSignup
29
31

More than 5 years have passed since last update.

cryptowat APIの使い方(備忘録)

Last updated at Posted at 2018-03-08

仮想通貨の時系列データが欲しくって調べてたら行き着いたのでまとめておきます。

殆どオフィシャルのドキュメントの内容の抜粋なので、英語を読める方はそちらをご確認ください。

とりあえず、時系列データの取得方法って方ohlcはへ

cryptowatとは

Cryptowatch is a cryptocurrency charting and trading platform owned by Kraken. Our system serves live data on 400+ markets to clients around the world.

つまり、 タダでチャートが見れて、APIを叩けば時系列データをJSONで返してくれる素敵なサービスです。

JSONの構造

result

各リクエストの内容。リクエストによって構造が異なるので、各種サンプルのJSONを参照。

allowance

remaining - 1時間あたりに使えるCPU時間 -

1時間あたり800,0000,000nsのCPU時間が割り振られ、これを超過するとToo Many Requestsを返す。

cost - 各リクエストの使用CPU時間 -

ルートパス(https://api.cryptowat.ch) への接続は殆どcostが掛からないって書いてあるけど、5000~10000くらい使うので、チェックする時は一応注意。

APIの使い方

Assets - 全てのアセット -

全てのアセット(通貨)を返す。

Example: https://api.cryptowat.ch/assets

return_json
{
  "result": [
    {
      "id": 201,
      "symbol": "ICX",
      "name": "ICON",
      "fiat": false,
      "route": "https://api.cryptowat.ch/assets/ICX"
    },
    {
      "id": 166,
      "symbol": "ada",
      "name": "Cardano",
      "fiat": false,
      "route": "https://api.cryptowat.ch/assets/ada"
    },...
   ]
}

assets/[symbol] -単一のアセット-

指定したアセットをベースorクォートとして持つ全ての市場を返す。

Example: https://api.cryptowat.ch/assets/btc

return_json
{
  "result": {
    "id": 60,
    "symbol": "btc",
    "name": "Bitcoin",
    "fiat": false,
    "markets": {
      "base": [
        {
          "id": 1,
          "exchange": "bitfinex",
          "pair": "btcusd",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/bitfinex/btcusd"
        },
        {
          "id": 415,
          "exchange": "bitfinex",
          "pair": "btceur",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/bitfinex/btceur"},...
            ]
        }
    }
}

Pairs - 全てのペア -

全てのペアを返す。

Example: https://api.cryptowat.ch/pairs

return_json

{
  "result": [
    {
      "symbol": "adabtc",
      "id": 313,
      "base": {
        "id": 166,
        "symbol": "ada",
        "name": "Cardano",
        "fiat": false,
        "route": "https://api.cryptowat.ch/assets/ada"
      },
      "quote": {
        "id": 60,
        "symbol": "btc",
        "name": "Bitcoin",
        "fiat": false,
        "route": "https://api.cryptowat.ch/assets/btc"
      },
      "route": "https://api.cryptowat.ch/pairs/adabtc"
    },
    ...
  ]
}

pairs/[pair] -単一のアセット-

指定したペア全ての市場を返す。

Example: https://api.cryptowat.ch/pairs/ethbtc

return_json
{
  "result": {
    "symbol": "ethbtc",
    "id": 21,
    "base": {
      "id": 77,
      "symbol": "eth",
      "name": "Ethereum",
      "fiat": false,
      "route": "https://api.cryptowat.ch/assets/eth"
    },
    "quote": {
      "id": 60,
      "symbol": "btc",
      "name": "Bitcoin",
      "fiat": false,
      "route": "https://api.cryptowat.ch/assets/btc"
    },
      ...
    ]
  }
}

Exchanges - 全ての取引所 -

全ての取引所を返す。

Example: https://api.cryptowat.ch/exchanges

return_json
{
  "result": [
    {
      "symbol": "bitfinex",
      "name": "Bitfinex",
      "route": "https://api.cryptowat.ch/exchanges/bitfinex",
      "active": true
    },
    {
      "symbol": "gdax",
      "name": "GDAX",
      "route": "https://api.cryptowat.ch/exchanges/gdax",
      "active": true
    },
    ...
  ]
}

exchanges/[symbol] - 単一の取引所 -

指定した交換所を返す。

Example: https://api.cryptowat.ch/exchanges/kraken

return_json
{
  "result": {
    "symbol": "kraken",
    "name": "Kraken",
    "active": true,
    "routes": {
      "markets": "https://api.cryptowat.ch/markets/kraken"
    }
  }
  }
}

Markets - 取引所に上場しているペア -

全ての市場を返す。

Example: https://api.cryptowat.ch/markets

return_json
{
  "result": [
    {
      "id": 1,
      "exchange": "bitfinex",
      "pair": "btcusd",
      "active": true,
      "route": "https://api.cryptowat.ch/markets/bitfinex/btcusd"
    },
    {
      "id": 2,
      "exchange": "bitfinex",
      "pair": "ltcusd",
      "active": true,
      "route": "https://api.cryptowat.ch/markets/bitfinex/ltcusd"
    },
    ...
  ]
}

markets/[exchange]/[pair] - 単一のペア -

指定した交換所のペアを返す。

Example: https://api.cryptowat.ch/markets/gdax/btcusd

return_json
{
  "result": {
    "exchange": "gdax",
    "pair": "btcusd",
    "active": true,
    "routes": {
      "price": "https://api.cryptowat.ch/markets/gdax/btcusd/price",
      "summary": "https://api.cryptowat.ch/markets/gdax/btcusd/summary",
      "orderbook": "https://api.cryptowat.ch/markets/gdax/btcusd/orderbook",
      "trades": "https://api.cryptowat.ch/markets/gdax/btcusd/trades",
      "ohlc": "https://api.cryptowat.ch/markets/gdax/btcusd/ohlc"
    }
  }
}

markets/[exchange]/[pair]/price - 最終価格 -

指定した市場のペアの最終価格を返す。

Example: https://api.cryptowat.ch/markets/gdax/btcusd/price

return_json
{
  "result": {
    "price": 9962
  }
  }
}

markets/[exchange]/[pair]/Summary - 統計情報 -

最終価格に加えて、過去24時間の統計情報を返す。

  • 高値
  • 安値
  • % change
  • Absolute change
  • 出来高

Example: https://api.cryptowat.ch/markets/gdax/btcusd/summary

return_json
{
  "result": {
    "price": {
      "last": 9972.66,
      "high": 10705,
      "low": 9400,
      "change": {
        "percentage": -0.062544554,
        "absolute": -665.3496
      }
    },
    "volume": 35290.53,
    "volumeQuote": 349072670
  }
}

markets/[exchange]/[pair]/trades - 最新取引 -

最新取引を返す。
jsonの数値は[ID、タイムスタンプ、価格、数量]の順に格納されている。

limitとsinceの2つのパラメタが使える。

markets/[exchange][pair]/trades?limit=[n]

指定したn個の取引を返す。デフォルトでは50。

markets/[exchange][pair]/trades?since=[utime]

指定したUNIX timestamp以降の取引を返す。

Example: https://api.cryptowat.ch/markets/gdax/btcusd/trades

return_json
{
  "result": [
    [
      0,
      1520511865,
      9895.39,
      0.01
    ],
    [
      0,
      1520511865,
      9895.3,
      0.00282
    ],
    ...
  ]
}

markets/[exchange]/[pair]/orderbook - 注文書 -

市場の注文書を返す。
jsonの数値は[価格、数量]の順に格納されている。

Example: https://api.cryptowat.ch/markets/gdax/btcusd/orderbook

return_json
{
  "result": {
    "asks": [
      [
        9811.61,
        0.1
      ],
      [
        9815.85,
        1.3484259
      ],
      ...
    ],
    "bids": [
      [
        9800,
        0.01597909
      ],
      [
        9799.94,
        0.03
      ],
      ...
    ]
  ]
}

markets/[exchange]/[pair]/ohlc - ローソク足 -

市場のOHLCローソク足データを返す。デフォルトで直近500件。
jsonの数値は[終了時間、始値、高値、安値、終値、出来高]の順に格納されている。

before、after、periodsの3つのパラメタが使える。

markets/[exchange]/[pair]/ohlc?before=[b]

指定したbより前のデータを返す。

markets/[exchange]/[pair]/ohlc?after=[a]

指定したaより後のデータを返す。

markets/[exchange]/[pair]/ohlc?periods=[p]

指定したp秒足のデータのみを返す。指定できる値は以下の通り

分時日週
60 1分
180 3分
300 5分
900 15分
1800 30分
3600 1時間
7200 2時間
14400 4時間
21600 6時間
43200 12時間
86400 1日
259200 3日
604800 1週

Example: https://api.cryptowat.ch/markets/gdax/btcusd/ohlc

return_json
{
  "result": {
    "60": [
      [1481634360, 782.14, 782.14, 781.13, 781.13, 1.92525],
      [1481634420, 782.02, 782.06, 781.94, 781.98, 2.37578],
      [1481634480, 781.39, 781.94, 781.15, 781.94, 1.68882],
      ...
    ],
    "180": [...],
    "300": [...],
    ...
    "604800": [...]
  }
}

markets/prices - 全ての市場の価格 -

現時点の全ての市場の価格を返す。

Example: https://api.cryptowat.ch/markets/prices

return_json
{
  "result": {
    {
      "bitfinex:bfxbtc": 0.00067133,
      "bitfinex:bfxusd": 0.52929,
      "bitfinex:btcusd": 776.73,
      ...
    }
  }
}

markets/summaries - 全ての市場の概要 -

全ての市場の概要を返す。

Example: https://api.cryptowat.ch/markets/summaries

return_json
{
  "result": {
    {
      "bitfinex:bfxbtc": {
        "price": {
          "last": 0.00067133,
          "high": 0.0006886,
          "low": 0.00066753,
          "change": {
            "percentage": -0.02351996,
            "absolute": -1.6169972e-05
          }
        },
        "volume":84041.625
      },
      "bitfinex:bfxusd": {
        ...
      },
      "bitfinex:btcusd": {
        ...
      },
      ...
    }
  }
}
29
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
31