GDAX websocketを使用すると、複数のペアを購読することができます。 以下に示すように、私はBTC-USD
とETH-USD
の両方のペアを購読しています。私は無制限のペアを購読することができると思います。
import websocket
from json import dumps, loads
try:
import thread
except ImportError:
import _thread as thread
def on_message(ws, message):
parsed_msg = loads(message)
print(parsed_msg["product_id"], parsed_msg["price"])
def on_open(ws):
def run(*args):
params = {
"type": "subscribe",
"channels": [{"name": "ticker", "product_ids": ["BTC-USD", "ETH-USD"]}]
}
ws.send(dumps(params))
thread.start_new_thread(run,())
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://ws-feed.gdax.com", on_open=on_open, on_message = on_message)
ws.run_forever()
GDAXがこれを許可しなかった場合は、複数のスレッドで複数のWebソケットを開くことができますが、この場合は必要ありません。