LiquidTap Python Clientを使う①

# 目次

* [はじめに](#はじめに)
* [「Liquid by Quoine」の"Order Book"を取得する](#liquid-by-quoineのorder-bookを取得する)

# はじめに

[「Liquid by Quoine」](https://www.liquid.com/ja/)のAPIが公開されているので色々叩いてみます。
まずは、WebSocketサービスから。

# 「Liquid by Quoine」の"Order Book"を取得する

ライブラリをインストールしてBTC/JPYを取得してみます。
(2020.01.22)

## ライブラリをインストール

```sh
$ pip3 install liquidtap
```

## 本家のサンプルを参考にコードを書く

本家：https://github.com/QuoineFinancial/liquid-tap-python

```py:price.py
import liquidtap
import time

def update_callback_buy(data):
    print("buy:" + data)

def update_callback_sell(data):
    print("sell:" + data)

def on_connect(data):
    tap.pusher.subscribe("price_ladders_cash_btcjpy_buy").bind('updated', update_callback_buy)
    tap.pusher.subscribe("price_ladders_cash_btcjpy_sell").bind('updated', update_callback_sell)

if __name__ == "__main__":
    tap = liquidtap.Client()
    tap.pusher.connection.bind('pusher:connection_established', on_connect)
    tap.pusher.connect()

    while True: # 無限ループ
        time.sleep(1)
```

## 実行

実行してbuyとsellが(何行も)表示されれば成功です。

```sh
$ python3 price.py
sell:[["948886.00000","0.01419278"],["948922.00000","0.02100000"],["948934.00000","0.00191306"],["948944.94000","0.00100000"],["948946.00000","0.03242956"],["948947.00000","0.03242988"],["948954.00000","0.00850000"],["948955.94000","0.03243954"],["948956.94000","0.01621739"],["948959.94000","0.03243965"],["948962.94000","0.02800000"],["948975.00000","0.00100000"],["948987.00000","0.00900000"],["948987.93700","0.03705000"],["948991.65500","0.07000000"],["948996.00000","0.02100000"],["949000.00000","2.00000000"],["949018.00000","0.01000000"],["949046.89124","0.01000000"],["949087.99999","0.06000000"],["949101.61000","0.00100000"],["949103.00000","0.04900000"],["949143.43000","0.25140000"],["949158.06000","1.32366279"],["949183.00000","0.04000000"],["949206.50000","0.01000000"],["949219.97000","0.00100000"],["949249.50000","0.07000000"],["949265.27000","0.01220000"],["949283.00000","0.15000000"],["949307.69000","0.00860000"],["949354.00000","0.38919067"],["949355.00000","0.22500000"],["949357.00000","4.00000000"],["949371.00000","0.01000000"],["949384.00000","0.01100000"],["949390.11000","0.03999999"],["949399.00000","0.04000000"],["949421.11000","0.03999999"],["949427.00000","0.01710000"]]
buy:[["948627.00000","0.03242956"],["948626.00000","0.03242988"],["948619.00000","0.04000000"],["948618.50000","0.00200000"],["948611.66000","0.03243954"],["948609.16000","0.03979000"],["948607.66000","0.01621955"],["948604.66000","0.01622010"],["948601.66000","0.00950000"],["948591.65500","0.07000000"],["948556.00000","0.03750000"],["948549.67000","0.01000000"],["948537.00001","0.01621739"],["948522.01000","0.01400000"],["948520.63000","0.00200000"],["948519.00001","0.03000000"],["948472.38000","0.01000000"],["948468.10000","0.10000000"],["948441.00000","0.02610000"],["948437.00000","0.04076885"],["948434.00000","0.00500000"],["948409.18000","0.00200000"],["948409.00000","0.06000000"],["948406.00000","0.03000000"],["948405.00000","0.01000000"],["948393.75000","0.02800000"],["948393.00000","0.02880000"],["948379.00000","0.02520000"],["948371.01000","0.13080000"],["948371.00000","0.03478991"],["948363.57077","0.00852120"],["948350.16098","0.00345380"],["948341.00000","0.50000013"],["948323.98000","0.17633721"],["948287.75000","0.00100000"],["948275.00000","0.09761507"],["948269.00000","0.01989854"],["948239.51000","0.01000000"],["948239.00000","0.20692222"],["948223.00000","0.15000000"]]
buy:[["948627.00000","0.03242956"],["948626.00000","0.03242988"],["948619.00000","0.04000000"],["948618.50000","0.00200000"],["948611.66000","0.03243954"],["948609.16000","0.03979000"],["948607.66000","0.01621955"],["948604.66000","0.01622010"],["948601.66000","0.00950000"],["948591.65500","0.07000000"],["948556.00000","0.03750000"],["948549.67000","0.01000000"],["948537.00001","0.01621739"],["948522.01000","0.01400000"],["948520.63000","0.00200000"],["948472.38000","0.01000000"],["948468.10000","0.10000000"],["948441.00000","0.02610000"],["948437.00000","0.04076885"],["948434.00000","0.00500000"],["948409.18000","0.00200000"],["948409.00000","0.06000000"],["948406.00000","0.03000000"],["948405.00000","0.01000000"],["948393.75000","0.02800000"],["948393.00000","0.02880000"],["948379.00000","0.02520000"],["948371.01000","0.13080000"],["948371.00000","0.03478991"],["948363.57077","0.00852120"],["948350.16098","0.00345380"],["948341.00000","0.50000013"],["948323.98000","0.17633721"],["948287.75000","0.00100000"],["948275.00000","0.09761507"],["948269.00000","0.01989854"],["948239.51000","0.01000000"],["948239.00000","0.20692222"],["948223.00000","0.15000000"],["948184.00000","0.22500000"]]
buy:[["948627.00000","0.03242956"],["948626.00000","0.03242988"],["948619.00000","0.04000000"],["948618.50000","0.00200000"],["948611.66000","0.03243954"],["948609.16000","0.03979000"],["948607.66000","0.01621955"],["948604.66000","0.01622010"],["948601.66000","0.00950000"],["948591.65500","0.07000000"],["948556.00000","0.03750000"],["948549.67000","0.01000000"],["948537.00001","0.01621739"],["948522.01000","0.01400000"],["948520.63000","0.00200000"],["948488.00001","0.03000000"],["948472.38000","0.01000000"],["948468.10000","0.10000000"],["948441.00000","0.02610000"],["948437.00000","0.04076885"],["948434.00000","0.00500000"],["948409.18000","0.00200000"],["948409.00000","0.06000000"],["948406.00000","0.03000000"],["948405.00000","0.01000000"],["948393.75000","0.02800000"],["948393.00000","0.02880000"],["948379.00000","0.02520000"],["948371.01000","0.13080000"],["948371.00000","0.03478991"],["948363.57077","0.00852120"],["948350.16098","0.00345380"],["948341.00000","0.50000013"],["948323.98000","0.17633721"],["948287.75000","0.00100000"],["948275.00000","0.09761507"],["948269.00000","0.01989854"],["948239.51000","0.01000000"],["948239.00000","0.20692222"],["948223.00000","0.15000000"]]
buy:[["948627.00000","0.03242956"],["948626.00000","0.03242988"],["948619.00000","0.04000000"],["948618.50000","0.00200000"],["948611.66000","0.03243954"],["948609.16000","0.03979000"],["948607.66000","0.01621955"],["948604.66000","0.01622010"],["948601.66000","0.00950000"],["948591.65500","0.07000000"],["948556.00000","0.03750000"],["948549.67000","0.01000000"],["948537.00001","0.01621739"],["948522.01000","0.01400000"],["948520.63000","0.00200000"],["948488.00001","0.03000000"],["948472.38000","0.01000000"],["948468.10000","0.10000000"],["948441.00000","0.02610000"],["948434.00000","0.00500000"],["948411.00000","0.04076885"],["948409.18000","0.00200000"],["948409.00000","0.06000000"],["948406.00000","0.03000000"],["948405.00000","0.01000000"],["948393.75000","0.02800000"],["948393.00000","0.02880000"],["948379.00000","0.02520000"],["948371.01000","0.13080000"],["948371.00000","0.03478991"],["948363.57077","0.00852120"],["948350.16098","0.00345380"],["948341.00000","0.50000013"],["948323.98000","0.17633721"],["948287.75000","0.00100000"],["948275.00000","0.09761507"],["948269.00000","0.01989854"],["948239.51000","0.01000000"],["948239.00000","0.20692222"],["948223.00000","0.15000000"]]
```

無事表示されました。
無限ループなので Ctrl+c で停止してください。。。