Coincheck APIの使い方
動作環境
環境設定
Gitが入ってなかったので入れる
$ sudo apt-get install git
Pipが入ってなかったので入れる
$ sudo apt-get install python-pip
Coincheckライブラリを入れる
gitの場合
$ cd coincheck
$ sudo python setup.py install
→インストールしなくてもいい?
Pipの場合
$ pip install coincheck
→こっちは失敗した
市場情報取得
code:python
from coincheck import order, market, account
m = market.Market()
# ティッカー
m.ticker()
#{'volume': 75583.42597217, 'last': 467344.0, 'timestamp': 1504962584, 'bid': 467440.0, 'high': 502782.0, 'low': 447003.0, 'ask': 467540.0} # 全取引履歴
m.trades()
# [{'created_at': '2017-09-09T13:12:52.000Z', 'amount': '0.2', 'id': 19233908, 'rate': 467981, 'order_type': 'buy'}, {'created_at': '2017-09-09T13:12:52.000Z', 'amount': '0.005', 'id': 19233907, 'rate': 467964, 'order_type': 'buy'}, {'created_at': '2017-09-09T13:12:51.000Z', 'amount': '0.005', 'id': 19233906, 'rate': 467908, 'order_type': 'sell'}, ...
# 板情報
m.orderbooks()
#{'bids': ['465330.0', '0.0067', '465089.0', '0.2', '465086.0', '0.22', '465085.0', '0.05',...'asks': ['465527.0', '0.0760748', '465528.0', '0.3', '465549.0', '0.015', '465553.0', '1.03721921', ... アカウント情報の取得
CoincheckでAPIキーを取得する。とりあえずアカウント情報・残高・取引履歴の権限を付与しておく。公開情報のみアクセスしたい場合はAPIキーはいらない。coincheck/settings.py にAPIキーとシークレットキーを書き込む。 code:coincheck/settings.py
access_key = "xxxxxxxxxxxxxxx"
secret_key = "xxxxxxxxxxxxxxx"
code:python
from coincheck import order, market, account, settings
a = account.Account(secret_key=settings.secret_key, access_key=settings.access_key)
# アカウントの情報を表示
a.get_info()
# {u'lending_leverage': u'5.0', u'success': True, u'maker_fee': u'0.0'
# アカウントの残高を確認
a.get_balance()
# {u'zec': u'0', u'rep_debt': u'0.0', u'xem': u'0', u'lsk': u'0', u'rep_lend_in_use': u'0.0', u'ltc_debt': u'0.0', u'xmr_reserved': u'0', u'cny': u'0', ...
注文履歴
code:python
from coincheck import order, market, account, settings
o = order.Order(secret_key=settings.secret_key, access_key=settings.access_key)
# 注文履歴を表示
o.history()
# o.history(){u'success': True, u'transactions': [{u'fee': u'0.0', u'order_id': 232001613, u'funds': {u'jpy': u'-146199.99931748', u'btc': u'0.30393241'}, u'created_at': u'2017-09-08T14:38:39.000Z', u'liquidity': u'T', u'rate': u'481028.0'...
WebSocketを使ったリアルタイムストリームの取得