Ccmmutty logo
Commutty IT
36 min read

【仮想通貨】草コインわらしべ長者プロジェクト【ステラルーメン】

https://cdn.magicode.io/media/notebox/7477849c-307f-4d0f-9a3b-cd788cc77180.jpeg

1. はじめに

この企画は最底辺の草コイン(ステラルーメン)を活用して資産を形成しようと考えている企画です.
ステラルーメンはXLMで表記された底辺のコインです.
シンボル(XYM)やネム(XEM)の方が底辺ですが,ビットフライヤーのAPIでサポートされていないため除外します.
*そのため,ここでの底辺とはビットフライヤーで取り扱いがあるコインの中で底辺ということになります.
このような草コインならリスクを最小に抑えつつ,取引するプログラミング,価格を予測するデータサイエンスや自動売買するサーバーなどを勉強できて,旨くいけば資産も形成できる,1石4鳥の欲張り企画です.

2. 価格データ取得

bitflyerいなごフライヤーのデータを取得します.
今後,データ解析中に他のサイトを追加するかもしれません.

2.1. 仮想環境の構築

conda で構築していきます.
ちなみに,Minicondaを使っています.
conda create -n PolaMbot
仮想環境に入ります.
conda activate PolaMbot

2.2. パッケージインストール

必要パッケージをインストールしていきます.
pip install ccxt
pip install websocket-client==0.47.0
pip install pandas
pip install selenium 
selenium でchromedriverを使うのでこちらからダウンロードしておいてくださ い.
chromedriverとselenium関係は▼▼▼こちら▼▼▼をご参照ください.

2.3. 取得プログラム

import json
import websocket
import os 
import time
from time import sleep

from logging import getLogger,INFO,StreamHandler
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(INFO)
logger.setLevel(INFO)
logger.addHandler(handler)

import pprint
from datetime import datetime as dt

from selenium import webdriver
from selenium.webdriver.chrome.options import Options


"""

データセット収集プログラムです.

"""
# TARGET_PRODUCT = "BTC"
TARGET_PRODUCT = "XLM"
# TARGET_PRODUCT = "ETH"

class RealtimeBFlyInago(object):
    def __init__(self, url, channel, webdriver):
        #########################################################
        # 初期化
        #
        self.url = url
        self.channel = channel
        #
        # 保存フォルダを指定
        self.save_dir = '../log/{}/output'.format(TARGET_PRODUCT)
        #
        # 保存フォルダが無ければ作成
        os.makedirs(self.save_dir, exist_ok=True)

        self.webdriver = webdriver
        
        self.ws = websocket.WebSocketApp(self.url,header=None,on_open=self.on_open, on_message=self.on_message, on_error=self.on_error, on_close=self.on_close)
        websocket.enableTrace(True)


    # -------------------------------------------------------------------------------------------
    # BF api
    #
    def run(self):
        #ws has loop. To break this press ctrl + c to occur Keyboard Interruption Exception.
        self.ws.run_forever()   
        logger.info('Web Socket process ended.')
    """
    Below are callback functions of websocket.
    """
    #########################################################
    # 基本的にこの関数を編集する形になります.
    #
    # when we get message
    def on_message(self, ws, message):
        output = json.loads(message)['params']
        # ---------------------------------------------------------
        # csv write 
        #
        # 日付情報を文字列に変換します.
        #
        tdatetime = dt.now()
        tstr   = tdatetime.strftime('%Y%m%d')
        tstr2  = tdatetime.strftime('%Y-%m-%d %H:%M:%S.%f')
        tstr_hour  = tdatetime.strftime('%H')
        tstr_min   = tdatetime.strftime('%M')
        tstr3  = tdatetime.strftime('%Y%m%d-%H%M%S%f')
        t_unix = tdatetime.timestamp()
        #
        # create dir 
        # 日付のフォルダを作成します.
        #
        self.save_dir_day = self.save_dir + "/" + tstr
        os.makedirs(self.save_dir_day, exist_ok=True)
        #
        #
        # 日付のフォルダ内にsingleフォルダを作成します.
        #
        self.save_dir_day_single = self.save_dir + "/" + tstr + "/single/" + tstr_hour + "/" + tstr_min
        os.makedirs(self.save_dir_day_single, exist_ok=True)

        # --------------------------
        # inago
        #
        total_ask_vol, total_bid_vol = self._get_inago_vol()
        output['message']["total_ask_vol"] = total_ask_vol
        output['message']["total_bid_vol"] = total_bid_vol


        # --------------------------
        # create json files
        #
        # 板情報は1つのjsonファイルとして保存します.
        #
        with open('{}/{}-{}.json'.format(self.save_dir_day_single, tstr3, t_unix), 'w') as f:
            json.dump(output['message'], f, indent=2, ensure_ascii=False)
        print("time : {}, unix : {}".format(tstr2, t_unix))

    # when error occurs
    def on_error(self, ws, error):
        logger.error(error)
    # when websocket closed.
    def on_close(self, ws):
        logger.info('disconnected streaming server')
    # when websocket opened.
    def on_open(self, ws):
        logger.info('connected streaming server')
        output_json = json.dumps(
            {'method' : 'subscribe',
            'params' : {'channel' : self.channel}
            }
        )
        ws.send(output_json)

    # -------------------------------------------------------------------------------------------
    # Inago
    #
    def _get_inago_vol(self):
        for buyvol in self.webdriver.find_elements_by_id("buyVolumePerMeasurementTime"):
            total_ask_vol = buyvol.text
        for sellvol in self.webdriver.find_elements_by_id("sellVolumePerMeasurementTime"):
            total_bid_vol = sellvol.text
        return total_ask_vol, total_bid_vol
        
if __name__ == '__main__':

    # -----------------------------------------------
    # Inago
    #
    options = Options()
    # ヘッドレスモードを有効にす。指定しない場合、Chromeの画面が表示される
    options.add_argument('--headless')

    # Windows
    # webdriver  = webdriver.Chrome(options=options, executable_path=r'modules\chromedriver_win32\chromedriver.exe')

    # linux 
    webdriver  = webdriver.Chrome(options=options, executable_path=r'modules\chromedriver_linux64_v101\chromedriver')

    # Inago flyer URL
    webdriver.get("https://inagoflyer.appspot.com/btcmac")

    # -----------------------------------------------
    # BF API endpoint
    #
    url = 'wss://ws.lightstream.bitflyer.com/json-rpc'
    # channel = 'lightning_board_snapshot_BTC_JPY'
    channel = 'lightning_board_snapshot_{}_JPY'.format(TARGET_PRODUCT)
    json_rpc = RealtimeBFlyInago(url=url, channel=channel, webdriver=webdriver)

    #########################################################
    # エラーがでても10秒後には復帰します
    #
    while 1:
        try:        
            json_rpc.run()
            #ctrl + cで終了
        except Exception as e:
            print(e)
            time.sleep(10)

2.4. 実行

上記プログラムを実行します.
python RealtimeBFlyInago.py
そうするとこんな感じでログがでてきます.
(PolaMbot) H:\マイドライブ\PROJECT\503_PolaMbot_v5>python RealtimeBFlyInago.py
H:\マイドライブ\PROJECT\503_PolaMbot_v5\RealtimeBFlyInago.py:144: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  webdriver  = webdriver.Chrome(options=options, executable_path=r'modules\chromedriver_win32\chromedriver.exe')

DevTools listening on ws://127.0.0.1:53496/devtools/browser/7fc549e0-0b84-493e-a36f-59137e82739f
[0622/003944.027:INFO:CONSOLE(62)] "Mixed Content: The page at 'https://inagoflyer.appspot.com/btcmac' was loaded over HTTPS, but requested an insecure frame 'http://developers.google.com/#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh%2Conload&id=I0_1655825983700&_gfid=I0_1655825983700&parent=https%3A%2F%2Finagoflyer.appspot.com&pfname=&rpctoken=68181274'. This request has been blocked; the content must be served over HTTPS.", source: https://apis.google.com/js/platform.js (62)
--- request header ---
GET /json-rpc HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: ws.lightstream.bitflyer.com
Origin: http://ws.lightstream.bitflyer.com
Sec-WebSocket-Key: dUufRdTTFLl/nE1fE7PJBw==
Sec-WebSocket-Version: 13


-----------------------
--- response header ---
HTTP/1.1 101 Switching Protocols
Date: Tue, 21 Jun 2022 15:39:52 GMT
Connection: upgrade
Upgrade: websocket
Sec-WebSocket-Accept: im5K7JSbgAB+5L0le2ODye31XAE=
-----------------------
connected streaming server
send: b'\x81\xd2\x9d\xbb\xeaG\xe6\x99\x87"\xe9\xd3\x85#\xbf\x81\xcae\xee\xce\x884\xfe\xc9\x83%\xf8\x99\xc6g\xbf\xcb\x8b5\xfc\xd6\x99e\xa7\x9b\x91e\xfe\xd3\x8b)\xf3\xde\x86e\xa7\x9b\xc8+\xf4\xdc\x823\xf3\xd2\x84 \xc2\xd9\x85&\xef\xdf\xb54\xf3\xda\x9a4\xf5\xd4\x9e\x18\xc5\xf7\xa7\x18\xd7\xeb\xb3e\xe0\xc6'
H:\マイドライブ\PROJECT\503_PolaMbot_v5\RealtimeBFlyInago.py:128: DeprecationWarning: find_elements_by_id is deprecated. Please use find_elements(by=By.ID, value=id_) instead
  for buyvol in self.webdriver.find_elements_by_id("buyVolumePerMeasurementTime"):
H:\マイドライブ\PROJECT\503_PolaMbot_v5\RealtimeBFlyInago.py:130: DeprecationWarning: find_elements_by_id is deprecated. Please use find_elements(by=By.ID, value=id_) instead
  for sellvol in self.webdriver.find_elements_by_id("sellVolumePerMeasurementTime"):
time : 2022-06-22 00:39:48.908462, unix : 1655825988.908462, total_ask_vol : 0.02, total_bid_vol : 0.41
time : 2022-06-22 00:39:53.996633, unix : 1655825993.996633, total_ask_vol : 6.31, total_bid_vol : 14.77
・
・
・
・
・


2.5. ログの見方

指定したパスに保存されます.デフォルトではプログラムを実行した階層の1つ上の階層にlogフォルダを作成して保存します.
中身は取引された価格と,各板情報が記載されています.
一番下にはいなごフライヤーの情報が記載されています.
ログファイルの例を下に記載しておきます.
{
  "mid_price": 15.928,
  "bids": [
    {
      "price": 7.0,
      "size": 12975.0
    },
    {
      "price": 7.4,
      "size": 10.0
    },
    {
      "price": 7.6,
      "size": 10.0
    },
    {
      "price": 7.666,
      "size": 10000.0
    },
    {
      "price": 8.0,
      "size": 19975.0
    },
    {
      "price": 8.3,
      "size": 5000.0
    },
    {
      "price": 8.37,
      "size": 1000.0
    },
    {
      "price": 8.58,
      "size": 1000.0
    },
    {
      "price": 8.666,
      "size": 10000.0
    },
    {
      "price": 8.77,
      "size": 1000.0
    },
    {
      "price": 8.85,
      "size": 2000.0
    },
    {
      "price": 9.0,
      "size": 30314.4277444
    },
    {
      "price": 9.2,
      "size": 5000.0
    },
    {
      "price": 9.4,
      "size": 1005.0
    },
    {
      "price": 9.5,
      "size": 7310.5105263
    },
    {
      "price": 9.8,
      "size": 12250.0
    },
    {
      "price": 9.85,
      "size": 1000.0
    },
    {
      "price": 9.9,
      "size": 1000.0
    },
    {
      "price": 10.0,
      "size": 24881.085
    },
    {
      "price": 10.1,
      "size": 101.0
    },
    {
      "price": 10.108,
      "size": 1000.0
    },
    {
      "price": 10.2,
      "size": 7200.0
    },
    {
      "price": 10.282,
      "size": 251.72251
    },
    {
      "price": 10.291,
      "size": 20000.0
    },
    {
      "price": 10.3,
      "size": 5000.0
    },
    {
      "price": 10.5,
      "size": 2509.5095238
    },
    {
      "price": 10.666,
      "size": 10000.0
    },
    {
      "price": 11.0,
      "size": 21348.1772727
    },
    {
      "price": 11.011,
      "size": 900.0
    },
    {
      "price": 11.1,
      "size": 160.0
    },
    {
      "price": 11.11,
      "size": 5000.0
    },
    {
      "price": 11.5,
      "size": 10608.7826087
    },
    {
      "price": 11.528,
      "size": 1000.0
    },
    {
      "price": 11.72,
      "size": 900.0
    },
    {
      "price": 11.739,
      "size": 300.0
    },
    {
      "price": 11.75,
      "size": 425.0
    },
    {
      "price": 11.856,
      "size": 200.0
    },
    {
      "price": 11.94,
      "size": 420.0
    },
    {
      "price": 12.0,
      "size": 71666.0208333
    },
    {
      "price": 12.01,
      "size": 101.0
    },
    {
      "price": 12.05,
      "size": 20.0
    },
    {
      "price": 12.1,
      "size": 120.0
    },
    {
      "price": 12.11,
      "size": 7000.0
    },
    {
      "price": 12.15,
      "size": 20.0
    },
    {
      "price": 12.2,
      "size": 620.0
    },
    {
      "price": 12.25,
      "size": 20.0
    },
    {
      "price": 12.3,
      "size": 20.0
    },
    {
      "price": 12.35,
      "size": 20.0
    },
    {
      "price": 12.39,
      "size": 250.0
    },
    {
      "price": 12.4,
      "size": 20.0
    },
    {
      "price": 12.405,
      "size": 1000.0
    },
    {
      "price": 12.411,
      "size": 800.0
    },
    {
      "price": 12.45,
      "size": 20.0
    },
    {
      "price": 12.5,
      "size": 16048.088
    },
    {
      "price": 12.55,
      "size": 420.0
    },
    {
      "price": 12.555,
      "size": 1000.0
    },
    {
      "price": 12.6,
      "size": 120.0
    },
    {
      "price": 12.64,
      "size": 1000.0
    },
    {
      "price": 12.65,
      "size": 20.0
    },
    {
      "price": 12.666,
      "size": 10000.0
    },
    {
      "price": 12.7,
      "size": 1520.0
    },
    {
      "price": 12.71,
      "size": 5000.0
    },
    {
      "price": 12.75,
      "size": 20.0
    },
    {
      "price": 12.8,
      "size": 2120.0
    },
    {
      "price": 12.85,
      "size": 20.0
    },
    {
      "price": 12.9,
      "size": 120.0
    },
    {
      "price": 12.95,
      "size": 20.0
    },
    {
      "price": 12.982,
      "size": 108.3038
    },
    {
      "price": 13.0,
      "size": 12552.9217692
    },
    {
      "price": 13.05,
      "size": 20.0
    },
    {
      "price": 13.055,
      "size": 1000.0
    },
    {
      "price": 13.1,
      "size": 2670.3582999
    },
    {
      "price": 13.15,
      "size": 20.0
    },
    {
      "price": 13.2,
      "size": 1822.121212
    },
    {
      "price": 13.25,
      "size": 20.0
    },
    {
      "price": 13.3,
      "size": 4591.9699236
    },
    {
      "price": 13.33,
      "size": 51500.0
    },
    {
      "price": 13.333,
      "size": 5000.0
    },
    {
      "price": 13.35,
      "size": 40.0
    },
    {
      "price": 13.358,
      "size": 1000.0
    },
    {
      "price": 13.36,
      "size": 224.56
    },
    {
      "price": 13.4,
      "size": 3001.044776
    },
    {
      "price": 13.45,
      "size": 20.0
    },
    {
      "price": 13.5,
      "size": 10302.3481481
    },
    {
      "price": 13.55,
      "size": 20.0
    },
    {
      "price": 13.6,
      "size": 26021.029411
    },
    {
      "price": 13.65,
      "size": 20.0
    },
    {
      "price": 13.681,
      "size": 55.0
    },
    {
      "price": 13.687,
      "size": 1000.0
    },
    {
      "price": 13.697,
      "size": 3650.0
    },
    {
      "price": 13.7,
      "size": 1871.021897
    },
    {
      "price": 13.711,
      "size": 1064.0
    },
    {
      "price": 13.75,
      "size": 450.0
    },
    {
      "price": 13.789,
      "size": 7989.0
    },
    {
      "price": 13.8,
      "size": 9649.014492
    },
    {
      "price": 13.807,
      "size": 0.1
    },
    {
      "price": 13.85,
      "size": 20.0
    },
    {
      "price": 13.9,
      "size": 2373.007194
    },
    {
      "price": 13.95,
      "size": 20.0
    },
    {
      "price": 14.0,
      "size": 27964.1
    },
    {
      "price": 14.01,
      "size": 400.0
    },
    {
      "price": 14.1,
      "size": 3354.8936162
    },
    {
      "price": 14.117,
      "size": 50.0
    },
    {
      "price": 14.2,
      "size": 5001.056338
    },
    {
      "price": 14.21,
      "size": 500.0
    },
    {
      "price": 14.24,
      "size": 5213.0
    },
    {
      "price": 14.25,
      "size": 536.0
    },
    {
      "price": 14.3,
      "size": 1551.048951
    },
    {
      "price": 14.311,
      "size": 210.0
    },
    {
      "price": 14.337,
      "size": 50.0
    },
    {
      "price": 14.358,
      "size": 1000.0
    },
    {
      "price": 14.4,
      "size": 23001.041666
    },
    {
      "price": 14.48,
      "size": 500.0
    },
    {
      "price": 14.5,
      "size": 9248.034482
    },
    {
      "price": 14.54,
      "size": 500.0
    },
    {
      "price": 14.56,
      "size": 500.0
    },
    {
      "price": 14.566,
      "size": 0.1
    },
    {
      "price": 14.6,
      "size": 3001.027397
    },
    {
      "price": 14.7,
      "size": 2941.360544
    },
    {
      "price": 14.75,
      "size": 1000.0
    },
    {
      "price": 14.77,
      "size": 5000.0
    },
    {
      "price": 14.777,
      "size": 50.0
    },
    {
      "price": 14.8,
      "size": 201.013513
    },
    {
      "price": 14.82,
      "size": 500.0
    },
    {
      "price": 14.84,
      "size": 0.1
    },
    {
      "price": 14.9,
      "size": 3726.778523
    },
    {
      "price": 14.99,
      "size": 8.005
    },
    {
      "price": 15.0,
      "size": 26633.9262319
    },
    {
      "price": 15.037,
      "size": 50.0
    },
    {
      "price": 15.1,
      "size": 659.139072
    },
    {
      "price": 15.15,
      "size": 500.0
    },
    {
      "price": 15.2,
      "size": 15438.8815783
    },
    {
      "price": 15.21,
      "size": 1000.0
    },
    {
      "price": 15.242,
      "size": 4.002
    },
    {
      "price": 15.27,
      "size": 0.1
    },
    {
      "price": 15.275,
      "size": 81.14
    },
    {
      "price": 15.3,
      "size": 531.045751
    },
    {
      "price": 15.354,
      "size": 111.79
    },
    {
      "price": 15.356,
      "size": 30062.0
    },
    {
      "price": 15.375,
      "size": 30126.0
    },
    {
      "price": 15.38,
      "size": 650.0
    },
    {
      "price": 15.4,
      "size": 4101.038961
    },
    {
      "price": 15.43,
      "size": 600.0
    },
    {
      "price": 15.437,
      "size": 50.0
    },
    {
      "price": 15.474,
      "size": 6.01
    },
    {
      "price": 15.5,
      "size": 181125.1612902
    },
    {
      "price": 15.501,
      "size": 83.0
    },
    {
      "price": 15.55,
      "size": 1000.0
    },
    {
      "price": 15.557,
      "size": 30733.0
    },
    {
      "price": 15.576,
      "size": 118.0
    },
    {
      "price": 15.6,
      "size": 1487.4358974
    },
    {
      "price": 15.601,
      "size": 122.61
    },
    {
      "price": 15.657,
      "size": 61324.0
    },
    {
      "price": 15.697,
      "size": 119882.0
    },
    {
      "price": 15.701,
      "size": 81.1
    },
    {
      "price": 15.72,
      "size": 105.2
    },
    {
      "price": 15.76,
      "size": 124.0
    },
    {
      "price": 15.8,
      "size": 1156.848481
    },
    {
      "price": 15.825,
      "size": 8000.0
    },
    {
      "price": 15.826,
      "size": 306419.0
    },
    {
      "price": 15.845,
      "size": 31277.0
    },
    {
      "price": 15.86,
      "size": 12378.0
    },
    {
      "price": 15.861,
      "size": 923.5
    },
    {
      "price": 15.866,
      "size": 8000.0
    },
    {
      "price": 15.883,
      "size": 468.0
    },
    {
      "price": 15.889,
      "size": 372.0
    },
    {
      "price": 15.897,
      "size": 902.0
    },
    {
      "price": 15.9,
      "size": 500.0
    },
    {
      "price": 15.912,
      "size": 794.7
    },
    {
      "price": 15.913,
      "size": 169.35
    }
  ],
  "asks": [
    {
      "price": 15.943,
      "size": 4000.0
    },
    {
      "price": 15.944,
      "size": 12378.0
    },
    {
      "price": 15.961,
      "size": 169.35
    },
    {
      "price": 15.962,
      "size": 8000.0
    },
    {
      "price": 15.966,
      "size": 31277.0
    },
    {
      "price": 15.977,
      "size": 986.51
    },
    {
      "price": 15.993,
      "size": 761.2
    },
    {
      "price": 16.016,
      "size": 8000.0
    },
    {
      "price": 16.021,
      "size": 760.0
    },
    {
      "price": 16.036,
      "size": 303534.0
    },
    {
      "price": 16.039,
      "size": 875.6
    },
    {
      "price": 16.078,
      "size": 79.03
    },
    {
      "price": 16.1,
      "size": 30.0
    },
    {
      "price": 16.11,
      "size": 71109.0
    },
    {
      "price": 16.118,
      "size": 102.95
    },
    {
      "price": 16.15,
      "size": 8384.9
    },
    {
      "price": 16.158,
      "size": 105.0
    },
    {
      "price": 16.238,
      "size": 83.3
    },
    {
      "price": 16.3,
      "size": 2011.042945
    },
    {
      "price": 16.374,
      "size": 90.0
    },
    {
      "price": 16.4,
      "size": 16.036586
    },
    {
      "price": 16.468,
      "size": 110.5
    },
    {
      "price": 16.486,
      "size": 76.98
    },
    {
      "price": 16.5,
      "size": 56512.060607
    },
    {
      "price": 16.52,
      "size": 100.0
    },
    {
      "price": 16.6,
      "size": 7336.4595572
    },
    {
      "price": 16.66,
      "size": 1983.6683417
    },
    {
      "price": 16.672,
      "size": 117.0
    },
    {
      "price": 16.7,
      "size": 491.035929
    },
    {
      "price": 16.74,
      "size": 60.0
    },
    {
      "price": 16.777,
      "size": 50.0
    },
    {
      "price": 16.8,
      "size": 1017.02381
    },
    {
      "price": 16.879,
      "size": 98.0
    },
    {
      "price": 16.9,
      "size": 12.011835
    },
    {
      "price": 16.993,
      "size": 176.55
    },
    {
      "price": 16.999,
      "size": 54.938764
    },
    {
      "price": 17.0,
      "size": 3434.6425782
    },
    {
      "price": 17.1,
      "size": 22.105264
    },
    {
      "price": 17.111,
      "size": 968.0
    },
    {
      "price": 17.132,
      "size": 175.12
    },
    {
      "price": 17.15,
      "size": 5.0
    },
    {
      "price": 17.2,
      "size": 32.093024
    },
    {
      "price": 17.25,
      "size": 5.0
    },
    {
      "price": 17.27,
      "size": 98.0
    },
    {
      "price": 17.3,
      "size": 17.080925
    },
    {
      "price": 17.333,
      "size": 50.0
    },
    {
      "price": 17.4,
      "size": 2217.068966
    },
    {
      "price": 17.5,
      "size": 22.057143
    },
    {
      "price": 17.6,
      "size": 16680.7341963
    },
    {
      "price": 17.7,
      "size": 22.033899
    },
    {
      "price": 17.8,
      "size": 17.022472
    },
    {
      "price": 17.9,
      "size": 12.011174
    },
    {
      "price": 17.99,
      "size": 20849.8418817
    },
    {
      "price": 18.0,
      "size": 13867.0
    },
    {
      "price": 18.011,
      "size": 731.0
    },
    {
      "price": 18.1,
      "size": 2.099448
    },
    {
      "price": 18.131,
      "size": 5.0
    },
    {
      "price": 18.2,
      "size": 7.087913
    },
    {
      "price": 18.3,
      "size": 2.076503
    },
    {
      "price": 18.314,
      "size": 163.81
    },
    {
      "price": 18.4,
      "size": 1668.065218
    },
    {
      "price": 18.5,
      "size": 18719.054055
    },
    {
      "price": 18.58,
      "size": 60.0
    },
    {
      "price": 18.6,
      "size": 7.043011
    },
    {
      "price": 18.7,
      "size": 312.032086
    },
    {
      "price": 18.795,
      "size": 30000.0
    },
    {
      "price": 18.8,
      "size": 7.021277
    },
    {
      "price": 18.9,
      "size": 2.010583
    },
    {
      "price": 18.91,
      "size": 200.0
    },
    {
      "price": 18.94,
      "size": 158.4
    },
    {
      "price": 19.0,
      "size": 1107.0
    },
    {
      "price": 19.095,
      "size": 136.36706
    },
    {
      "price": 19.1,
      "size": 2.094241
    },
    {
      "price": 19.2,
      "size": 507.083334
    },
    {
      "price": 19.226,
      "size": 156.04
    },
    {
      "price": 19.3,
      "size": 5172.072539
    },
    {
      "price": 19.33,
      "size": 2003.0
    },
    {
      "price": 19.4,
      "size": 30017.061856
    },
    {
      "price": 19.45,
      "size": 616.9918787
    },
    {
      "price": 19.5,
      "size": 17429.051283
    },
    {
      "price": 19.55,
      "size": 5000.0
    },
    {
      "price": 19.6,
      "size": 5015.0
    },
    {
      "price": 19.7,
      "size": 520.0
    },
    {
      "price": 19.749,
      "size": 10.0
    },
    {
      "price": 19.781,
      "size": 100.0
    },
    {
      "price": 19.8,
      "size": 10125.0
    },
    {
      "price": 19.9,
      "size": 20.0
    },
    {
      "price": 20.0,
      "size": 25696.0
    },
    {
      "price": 20.033,
      "size": 10.0
    },
    {
      "price": 20.2,
      "size": 5000.0
    },
    {
      "price": 20.293,
      "size": 10.0
    },
    {
      "price": 20.5,
      "size": 1000.0
    },
    {
      "price": 20.55,
      "size": 70.0
    },
    {
      "price": 20.62,
      "size": 60.0
    },
    {
      "price": 21.0,
      "size": 500.0
    },
    {
      "price": 21.011,
      "size": 500.0
    },
    {
      "price": 21.98,
      "size": 1050.0
    },
    {
      "price": 22.0,
      "size": 6085.0
    },
    {
      "price": 22.1,
      "size": 4250.0
    },
    {
      "price": 22.17,
      "size": 0.1
    },
    {
      "price": 22.36,
      "size": 4000.0
    },
    {
      "price": 22.5,
      "size": 1060.9
    },
    {
      "price": 22.811,
      "size": 735.0
    },
    {
      "price": 22.89,
      "size": 60.0
    },
    {
      "price": 22.9,
      "size": 2000.0
    },
    {
      "price": 23.0,
      "size": 2128.849376
    },
    {
      "price": 23.01,
      "size": 16.849376
    },
    {
      "price": 23.611,
      "size": 735.0
    },
    {
      "price": 23.83,
      "size": 11000.0
    },
    {
      "price": 24.0,
      "size": 44850.0687292
    },
    {
      "price": 24.811,
      "size": 630.0
    },
    {
      "price": 25.0,
      "size": 3295.0
    },
    {
      "price": 25.3,
      "size": 100.0
    },
    {
      "price": 25.41,
      "size": 60.0
    },
    {
      "price": 26.0,
      "size": 2500.0
    },
    {
      "price": 26.52,
      "size": 0.1
    },
    {
      "price": 27.0,
      "size": 2000.0
    },
    {
      "price": 27.5,
      "size": 97.0
    },
    {
      "price": 28.0,
      "size": 8118.698752
    },
    {
      "price": 28.21,
      "size": 60.0
    },
    {
      "price": 28.5,
      "size": 99.0
    },
    {
      "price": 29.0,
      "size": 26225.0684893
    },
    {
      "price": 29.01,
      "size": 0.1
    },
    {
      "price": 29.04,
      "size": 30.0
    },
    {
      "price": 29.8,
      "size": 5300.53
    },
    {
      "price": 29.929,
      "size": 1995.0
    },
    {
      "price": 30.0,
      "size": 10568.9574507
    },
    {
      "price": 30.36,
      "size": 0.1
    },
    {
      "price": 31.0,
      "size": 7000.0
    },
    {
      "price": 32.0,
      "size": 5000.0
    },
    {
      "price": 32.2,
      "size": 14400.0
    },
    {
      "price": 33.0,
      "size": 5000.0
    },
    {
      "price": 33.3,
      "size": 13968.0
    },
    {
      "price": 34.0,
      "size": 5000.0
    },
    {
      "price": 35.0,
      "size": 5000.0
    },
    {
      "price": 36.0,
      "size": 5000.0
    }
  ],
  "total_ask_vol": "186.14",
  "total_bid_vol": "45.29"
}

2.6. サーバーの構築

自分が普段使っているデスクトップで動かしてもよいのですが,重くなったときなどに再起動をした場合に再度プログラムを動かすのは面倒なのでノートPC(レッツノート)にKali Linuxを導入してサーバー化し,そこで動いてもらいます.
*ちなみにノートPCをサーバー化する際には内部の掃除をきちんとして,バッテリーは外した状態で運用しましょう.
Kali linuxは結構参考になる記事が多いのでここでは割愛致します. とても便利です.
Ubuntu系統なので,ここのサイトを見てMinicondaの 環境を整えました.
仮想環境の構築などは上記と同じです.
また,chromedriverはLinux版をダウンロードしておいてください.
あとは,コードをKali側に持っていって下記コマンドを実行

nohup python RealtimeBFlyInago.py > outlog.txt &

こうすることで,SSH側で起動してSSH接続を閉じてもタスクが終了しずにデータの取得が続きます.

3. データ可視化

========= 執筆中 =========

Discussion

コメントにはログインが必要です。