Use LiquidTap Python Client ③

table of contents

Introduction

Let's hit the API of "Liquid by Quoine" -Part 3-

Check the log of "Liquid by Quoine"

When I tried to spit out the price.py log created in Using LiquidTap Python Client ① to a file, I happened to find the LiquidTap library in the log. Since the log was spit out, let's take a look at the output contents. (2020.03.04)

Before looking at the Liquid Tap log.

This is the code and configuration file prepared to check the log.

price.py


import liquidtap
import time
from logging import config

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__":
  config.fileConfig('logging.conf')

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

  while True: #infinite loop
    time.sleep(1)

This is a log configuration file. (Because I was trying to check it on the console and the log file, ...

logging.conf


[loggers]
keys=root

[handlers]
keys=fileHandler,consoleHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=INFO
handlers=fileHandler,consoleHandler

[handler_consoleHandler]
class=StreamHandler
level=INFO
formatter=simpleFormatter
args=(sys.stdout,)

[handler_fileHandler]
class=handlers.RotatingFileHandler
level=INFO
formatter=simpleFormatter
args=("logs/default.log", "a", 1024*1024, 5)

[formatter_simpleFormatter]
#Specify format(https://docs.python.jp/3/library/logging.html#logrecord-attributes)
format=%(asctime)s %(levelname)-8s [%(module)s#%(funcName)s %(lineno)d] %(message)s

View the output Liquid Tap log

Connection (of websocket)

Around here

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

2020-03-04 19:54:17,928 INFO     [connection#_on_open 129] Connection: Connection opened
2020-03-04 19:54:17,945 INFO     [connection#_on_message 143] Connection: Message - {"data":"{\"activity_timeout\":120,\"socket_id\":\"0600663276.5838793824\"}","event":"pusher:connection_established"}

It seems to be a mechanism (?) To connect with _on_open and receive a message with _on_message. You can read the socket ID and timeout time.

Send subscribe and receive results

Around here

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)

2020-03-04 19:54:17,947 INFO     [connection#send_event 217] Connection: Sending event - {"event": "pusher:subscribe", "data": {"channel": "price_ladders_cash_btcjpy_buy"}}
2020-03-04 19:54:17,950 INFO     [connection#send_event 217] Connection: Sending event - {"event": "pusher:subscribe", "data": {"channel": "price_ladders_cash_btcjpy_sell"}}
2020-03-04 19:54:17,963 INFO     [connection#_on_message 143] Connection: Message - {"channel":"price_ladders_cash_btcjpy_buy","data":{},"event":"pusher_internal:subscription_succeeded"}
2020-03-04 19:54:17,972 INFO     [connection#_on_message 143] Connection: Message - {"channel":"price_ladders_cash_btcjpy_sell","data":{},"event":"pusher_internal:subscription_succeeded"}

PING/PONG

LiquidTap has a specification (activity_timeout value?) That disconnects when there is no communication. Therefore, I send PING regularly and receive PONG. https://developers.liquid.com/#ping-/-pong

2020-03-04 19:54:17,942 INFO     [connection#send_ping 224] Connection: ping to pusher
2020-03-04 19:54:17,961 INFO     [connection#_pong_handler 276] Connection: pong from pusher

I'm really sending and receiving PING / PONG. .. ..

PRICE reception

2020-03-04 19:54:17,966 INFO     [connection#_on_message 143] Connection: Message - {"channel":"price_ladders_cash_btcjpy_buy","data":"[[\"942742.00000\",\"0.01812556\"],[\"942740.00000\",\"0.00100000\"],[\"942731.00000\",\"0.01935063\"],[\"942700.00000\",\"0.01000000\"],[\"942678.00000\",\"0.00200000\"],[\"942667.00000\",\"0.00100000\"],[\"942662.00000\",\"0.01935057\"],[\"942653.00000\",\"0.03708848\"],[\"942640.00000\",\"0.01200000\"],[\"942639.00000\",\"0.10468137\"],[\"942615.00000\",\"0.18070000\"],[\"942613.00000\",\"0.02000000\"],[\"942577.00000\",\"0.04000000\"],[\"942567.00000\",\"0.04643000\"],[\"942551.00000\",\"0.50000013\"],[\"942524.00000\",\"0.00500000\"],[\"942502.00000\",\"0.01000000\"],[\"942490.00000\",\"0.00100000\"],[\"942467.00000\",\"0.00200000\"],[\"942459.00000\",\"0.10000000\"],[\"942451.00000\",\"0.22500000\"],[\"942424.00000\",\"0.03000000\"],[\"942419.00000\",\"1.50000000\"],[\"942409.00000\",\"0.01000000\"],[\"942393.00000\",\"0.15000000\"],[\"942351.00000\",\"0.02000000\"],[\"942328.00000\",\"0.02000000\"],[\"942290.00000\",\"1.00000013\"],[\"942275.00000\",\"0.10000000\"],[\"942240.00000\",\"0.00100000\"],[\"942144.00000\",\"0.05000000\"],[\"942129.00000\",\"0.01000000\"],[\"942071.00000\",\"0.07000000\"],[\"942059.00000\",\"0.09044679\"],[\"941982.00000\",\"0.02000000\"],[\"941966.00000\",\"0.00533240\"],[\"941862.00000\",\"0.24000000\"],[\"941780.00000\",\"0.01510000\"],[\"941779.00000\",\"4.00000000\"],[\"941771.00000\",\"0.05000000\"]]","event":"updated"}
2020-03-04 19:54:17,975 INFO     [connection#_on_message 143] Connection: Message - {"channel":"price_ladders_cash_btcjpy_sell","data":"[[\"943079.00000\",\"0.00200000\"],[\"943080.00000\",\"0.03708848\"],[\"943084.00000\",\"0.01935057\"],[\"943092.00000\",\"0.84000000\"],[\"943099.00000\",\"0.00500000\"],[\"943101.00000\",\"0.00200000\"],[\"943104.00000\",\"0.00100000\"],[\"943105.00000\",\"0.00696180\"],[\"943109.00000\",\"0.05000000\"],[\"943140.00000\",\"0.09739999\"],[\"943200.00000\",\"0.04000000\"],[\"943219.00000\",\"0.05000000\"],[\"943225.00000\",\"0.01000000\"],[\"943240.00000\",\"0.00100000\"],[\"943251.00000\",\"0.01000000\"],[\"943253.00000\",\"0.02000000\"],[\"943270.00000\",\"0.01000000\"],[\"943311.00000\",\"0.01680000\"],[\"943312.00000\",\"0.00200000\"],[\"943387.00000\",\"0.00100000\"],[\"943388.00000\",\"0.03869479\"],[\"943400.00000\",\"0.07743077\"],[\"943404.00000\",\"0.01935063\"],[\"943411.00000\",\"0.01740000\"],[\"943425.00000\",\"0.22500000\"],[\"943426.00000\",\"0.02000000\"],[\"943427.00000\",\"4.00000000\"],[\"943437.00000\",\"0.00200000\"],[\"943459.00000\",\"0.02500000\"],[\"943461.00000\",\"0.20000000\"],[\"943489.00000\",\"0.15000000\"],[\"943490.00000\",\"0.00100000\"],[\"943501.00000\",\"0.01000000\"],[\"943509.00000\",\"0.01000000\"],[\"943565.00000\",\"0.05000000\"],[\"943626.00000\",\"0.01000000\"],[\"943636.00000\",\"0.01900000\"],[\"943659.00000\",\"0.08774868\"],[\"943660.00000\",\"0.03999999\"],[\"943708.00000\",\"0.01000000\"]]","event":"updated"}

You can see that the content received by the callback is output as it is.

If you are not careful about the log output, the LiquidTap log will fill up the log file. .. ..

Recommended Posts

Use LiquidTap Python Client ③
Use LiquidTap Python Client ②
Use LiquidTap Python Client ①
Use thingsspeak from python
Use config.ini in Python
[Python] Use JSON with Python
Use fluentd from python
Python StatsD client configuration
Use dates in Python
Use Valgrind in Python
Use MySQL from Python
Use mecab with Python3
Use DynamoDB with Python
Use Python 3.8 with Anaconda
[Python] format methodical use
Use python with docker
Use MySQL from Python
Use BigQuery from python.
Use profiler in Python
Use mecab-ipadic-neologd from python
Let's use def in python
Let's use python janome easily
Use Trello API with python
Use matplotlib on Ubuntu 12 & Python
Use let expression in Python
Use Measurement Protocol in Python
python3: How to use bottle (2)
Use callback function in Python
Use parameter store in Python
[Python] Use a string sequence
[Python] How to use list 1
Try using Kubernetes Client -Python-
Python is painful. But use
Use HTTP cache in Python
Use TUN / TAP with Python
Use MongoDB ODM in Python
Use list-keyed dict in Python
How to use Python argparse
Use Random Forest in Python
Use regular expressions in Python
Use Spyder in Python IDE
Python: How to use pydub
[Python] How to use checkio
Use subsonic API with python3
Simple IRC client in python
Use Python on Windows (PyCharm)
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
Use e-Stat API from Python
How to use Python bytes
Use pymol as a python library
Python: How to use async with
Use Stanford Core NLP from Python
Use PointGrey camera with Python (PyCapture2)
Use vl53l0x with Raspberry Pi (python)
Python
Use fabric as is in python (fabric3)
[Python] How to use Pandas Series