Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Examples to make them run against current API with modern Python. #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clientExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def print_out(ws, msg):

coinfloor.WatchOrders(
base = Assets["XBT"],
counter = Assets["USD"],
counter = Assets["GBP"],
watch = True
)
coinfloor.WatchTicker(
base = Assets["XBT"],
counter = Assets["USD"],
counter = Assets["GBP"],
watch = True
)

Expand Down
28 changes: 14 additions & 14 deletions coinfloor.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, url,
)


def _open_handler(self, ws):
def _open_handler(self):
self.conditional.acquire()
self.connected = True
self.conditional.notifyAll()
Expand All @@ -122,14 +122,14 @@ def _open_handler(self, ws):
self.open_handler(self)


def _err_handler(self, ws, error):
def _err_handler(self, error):
if self.err_handler is not None:
self.err_handler(self, error)
else:
raise ConnectionError("Connection to %s failed: %s"%(self.url, error))


def _msg_handler(self, ws, message):
def _msg_handler(self, message):
if not self.auth_complete:
body = json.loads(message)
self._body_scan(body)
Expand All @@ -140,15 +140,15 @@ def _msg_handler(self, ws, message):

def _process_welcome_message(self, body):
if "nonce" not in body:
self._err_handler(self, "Invalid 'Welcome' message received")
self._err_handler("Invalid 'Welcome' message received")
elif self.server_nonce is not None:
self._err_handler(self, "Server nonce received more than once")
self._err_handler("Server nonce received more than once")
else:
try:
self.conditional.acquire()
self.server_nonce = base64.b64decode(body["nonce"])
except TypeError:
self._err_handler(self, "Server nonce received is invalid")
self._err_handler("Server nonce received is invalid")
finally:
self.conditional.notify_all()
self.conditional.release()
Expand Down Expand Up @@ -229,7 +229,7 @@ def _smart_connect(self):
lambda: self.connected
)
except KeyboardInterrupt:
self._err_handler(self, "Interrupted while establishing the connection")
self._err_handler("Interrupted while establishing the connection")


def _wait_for_server_nonce(self):
Expand All @@ -238,7 +238,7 @@ def _wait_for_server_nonce(self):
lambda: self.server_nonce is not None
)
except KeyboardInterrupt:
self._err_handler(self, "Interrupted while waiting for server nonce")
self._err_handler("Interrupted while waiting for server nonce")


def _wait_for_auth_response(self):
Expand All @@ -247,7 +247,7 @@ def _wait_for_auth_response(self):
lambda: self.auth_complete is True
)
except KeyboardInterrupt:
self._err_handler(self, "Interrupted while waiting for authentication to complete")
self._err_handler("Interrupted while waiting for authentication to complete")


def _compute_ecdsa_signature(self):
Expand Down Expand Up @@ -278,7 +278,7 @@ def _compute_ecdsa_signature(self):
return r, s

except ValueError:
self._err_handler(self, "Invalid signature data")
self._err_handler("Invalid signature data")


def _send_signature(self, **sig_data):
Expand All @@ -290,14 +290,14 @@ def authenticate(self):
return

if self.user_id is None or self.cookie is None or self.passphrase is None:
self._err_handler(self, "Missing authentication data")
self._err_handler("Missing authentication data")
return

self._smart_connect()

self._wait_for_server_nonce()
if self.server_nonce is None:
self._err_handler(self, "Server nonce not received before timeout")
self._err_handler("Server nonce not received before timeout")

else:
signature = self._compute_ecdsa_signature()
Expand All @@ -313,9 +313,9 @@ def authenticate(self):

self._wait_for_auth_response()
if not self.auth_complete:
self._err_handler(self, "Unable to complete authentication")
self._err_handler("Unable to complete authentication")
elif not self.auth_okay:
self._err_handler(self, "Authentication failed")
self._err_handler("Authentication failed")


def GetBalances(self, **data):
Expand Down