diff --git a/bfxapi/models/order_book.py b/bfxapi/models/order_book.py index 48a8a44..54b3709 100644 --- a/bfxapi/models/order_book.py +++ b/bfxapi/models/order_book.py @@ -4,17 +4,6 @@ Module used to describe all of the different data types import zlib - -def prepare_price(price): - """ - Convert the price to an acceptable format - """ - # convert to 4 significant figures - prep_price = '{0:.4f}'.format(price) - # remove decimal place if zero float - return '{0:g}'.format(float(prep_price)) - - class OrderBook: """ Object used to store the state of the orderbook. This can then be used @@ -107,13 +96,13 @@ class OrderBook: bid = self.bids[index] price = bid[0] amount = bid[3] if len(bid) == 4 else bid[2] - data += [prepare_price(price)] + data += [str(price)] data += [str(amount)] if index < len(self.asks): ask = self.asks[index] price = ask[0] amount = ask[3] if len(ask) == 4 else ask[2] - data += [prepare_price(price)] + data += [str(price)] data += [str(amount)] checksum_str = ':'.join(data) # calculate checksum and force signed integer diff --git a/bfxapi/websockets/BfxWebsocket.py b/bfxapi/websockets/BfxWebsocket.py index 2babff9..79d8c48 100644 --- a/bfxapi/websockets/BfxWebsocket.py +++ b/bfxapi/websockets/BfxWebsocket.py @@ -7,6 +7,7 @@ import json import time import random +from decimal import * from .GenericWebsocket import GenericWebsocket, AuthError from .SubscriptionManager import SubscriptionManager from .WalletManager import WalletManager @@ -354,7 +355,8 @@ class BfxWebsocket(GenericWebsocket): async def on_message(self, message): self.logger.debug(message) - msg = json.loads(message) + # convert float values to decimal + msg = json.loads(message, parse_float=Decimal) self._emit('all', msg) if type(msg) is dict: # System messages are received as json