bitFlyer からリアルタイムデータを取得する方法「Python編」Realtime API via PubNub

C#編はこちら

for Python 3.6

pip install tornado
pip install pubnub
# coding: utf-8
from pubnub.callbacks import SubscribeCallback
from pubnub.enums import PNStatusCategory
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub_tornado import PubNubTornado
from pubnub.pnconfiguration import PNReconnectionPolicy

c = PNConfiguration()
c.subscribe_key = 'sub-c-52a9ab50-291b-11e5-baaa-0619f8945a4f'
c.reconnect_policy = PNReconnectionPolicy.LINEAR
pubnub = PubNubTornado(c)

from tornado import gen
@gen.coroutine

def main(channels):
    class Callback(SubscribeCallback):
        
        def message(self, pubnub, message):
            print(message.message)

    s = Callback()
    pubnub.add_listener(s)
    pubnub.subscribe().channels(channels).execute()

if __name__ == '__main__':
    channels = [
        'lightning_ticker_FX_BTC_JPY',
        
    ]
    main(channels)
    pubnub.start()

 

 

参考サイト
ビットコインxシストレ
PubNub Python V4 SDK 4.0.13
bitFlyer Lightning API Documentation