Skip to content

Instantly share code, notes, and snippets.

@jjmalina
Created July 18, 2015 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjmalina/34fa032080672ced34d1 to your computer and use it in GitHub Desktop.
Save jjmalina/34fa032080672ced34d1 to your computer and use it in GitHub Desktop.
Real-time Coinbase orders and trades
# -*- coding: utf-8 -*-
"""
coinbase
~~~~~~~~
Real time Coinbase trades and orders using their Websocket Feed
https://docs.exchange.coinbase.com/?python#overview
"""
import asyncio
import json
import websockets
COINBASE_FEED_URL = "wss://ws-feed.exchange.coinbase.com"
@asyncio.coroutine
def coinbase_feed():
websocket = yield from websockets.connect(COINBASE_FEED_URL)
yield from websocket.send(json.dumps({
"type": "subscribe",
"product_id": "BTC-USD"
}))
while True:
message = yield from websocket.recv()
print(message)
def main():
asyncio.get_event_loop().run_until_complete(coinbase_feed())
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment