Skip to content

Commit

Permalink
updated WebsocketClient, requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
drewrice2 committed Oct 10, 2017
1 parent 95b6e7e commit f26d97f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions gdax/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import time
from threading import Thread
from websocket import create_connection, WebSocketConnectionClosedException

from pymongo import MongoClient

class WebsocketClient(object):
def __init__(self, url="wss://ws-feed.gdax.com", products=None, message_type="subscribe", auth=False, api_key="", api_secret="", api_passphrase=""):
def __init__(self, url="wss://ws-feed.gdax.com", products=None, message_type="subscribe",
mongo_collection=None, should_print=True, auth=False, api_key="", api_secret="", api_passphrase=""):
self.url = url
self.products = products
self.type = message_type
Expand All @@ -26,6 +27,7 @@ def __init__(self, url="wss://ws-feed.gdax.com", products=None, message_type="su
self.api_key = api_key
self.api_secret = api_secret
self.api_passphrase = api_passphrase
self.mongo_collection = mongo_collection

def start(self):
def _go():
Expand Down Expand Up @@ -99,7 +101,10 @@ def on_close(self):
print("\n-- Socket Closed --")

def on_message(self, msg):
print(msg)
if should_print:
print(msg)
if self.mongo_collection: # dump JSON to given mongo collection
self.mongo_collection.insert_one(msg)

def on_error(self, e):
print(e)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ bintrees==2.0.7
requests==2.13.0
six==1.10.0
websocket-client==0.40.0
pymongo

0 comments on commit f26d97f

Please sign in to comment.