LoginSignup
0
2

More than 5 years have passed since last update.

Python3.6で仮想通貨API で情報を取得

Posted at

1 APIのアカウント作成

2 Pythonコード取得

#!/usr/bin/env python

from __future__ import print_function

import sys
import time

from satori.rtm.client import make_client, SubscriptionMode

endpoint = "wss://open-data.api.satori.com"
appkey = undefined
channel = "cryptocurrency-market-data"

def main():
    with make_client(endpoint=endpoint, appkey=appkey) as client:
        print('Connected to Satori RTM!')

        class SubscriptionObserver(object):
            def on_subscription_data(self, data):
                for message in data['messages']:
                    print("Got message:", message)

        subscription_observer = SubscriptionObserver()
        client.subscribe(
            channel,
            SubscriptionMode.SIMPLE,
            subscription_observer)

        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            pass


if __name__ == '__main__':
    main()

3 Python 2.7.6以後の環境構築:Python 3

sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm

yum search python36
sudo yum install python36u python36u-libs python36u-devel python36u-pip

cd ~/
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

# Python 3 Library
sudo python3.6 -m pip install satori-rtm-sdk

4 実行

[centos@zzeng-test1 ~]$ python3.6 aaa.py
Connected to Satori RTM!
Got message: {'exchange': 'Bitstamp', 'cryptocurrency': 'BTC', 'basecurrency': 'USD', 'type': 'market', 'price': '8499.73', 'size': None, 'bid': '8491.83', 'ask': '8499.73', 'open': '8265.05', 'high': '8613.06', 'low': '7914.08', 'volume': '15827.26995771', 'timestamp': '1521243406'}
Got message: {'exchange': 'POLONIEX', 'cryptocurrency': 'GAME', 'basecurrency': 'BTC', 'type': 'market', 'price': '0.00014728', 'size': None, 'bid': '0.00014785', 'ask': '0.00014967', 'open': None, 'high': '0.00014989', 'low': '0.00013951', 'volume': '8.66189614', 'timestamp': None}
Got message: {'exchange': 'HitBTC', 'cryptocurrency': 'EOS', 'basecurrency': 'ETH', 'type': 'market', 'price': '0.008410', 'size': None, 'bid': '0.008383', 'ask': '0.008427', 'open': '0.008405', 'high': '0.008535', 'low': '0.008241', 'volume': '19129.43', 'timestamp': '1521243310'}
Got message: {'exchange': 'OKCoin', 'cryptocurrency': 'ETC', 'basecurrency': 'USD', 'type': 'market', 'price': '19.071', 'size': None, 'bid': '19.021', 'ask': '19.3', 'open': None, 'high': '19.559', 'low': '18.251', 'volume': '341.857', 'timestamp': '1521243410884'}
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2