Created
July 18, 2015 21:35
-
-
Save jjmalina/34fa032080672ced34d1 to your computer and use it in GitHub Desktop.
Real-time Coinbase orders and trades
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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