mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
Rename bfxapi/utils/decimal.py to encoder.py. Add support for datetime JSON serialization. Update class reference in BfxWebsocketClient.py.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import json
|
||||
|
||||
from decimal import Decimal
|
||||
from datetime import datetime
|
||||
|
||||
class DecimalEncoder(json.JSONEncoder):
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
if isinstance(obj, Decimal) or isinstance(obj, datetime):
|
||||
return str(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
@@ -10,7 +10,7 @@ from .typings import Inputs
|
||||
from .handlers import Channels, PublicChannelsHandler, AuthenticatedChannelsHandler
|
||||
from .exceptions import ConnectionNotOpen, TooManySubscriptions, WebsocketAuthenticationRequired, InvalidAuthenticationCredentials, EventNotSupported, OutdatedClientVersion
|
||||
|
||||
from ..utils.decimal import DecimalEncoder
|
||||
from ..utils.encoder import JSONEncoder
|
||||
|
||||
from ..utils.logger import Formatter, CustomLogger
|
||||
|
||||
@@ -139,7 +139,7 @@ class BfxWebsocketClient(object):
|
||||
|
||||
@_require_websocket_authentication
|
||||
async def __handle_websocket_input(self, input, data):
|
||||
await self.websocket.send(json.dumps([ 0, input, None, data], cls=DecimalEncoder))
|
||||
await self.websocket.send(json.dumps([ 0, input, None, data], cls=JSONEncoder))
|
||||
|
||||
def __bucket_open_signal(self, index):
|
||||
if all(bucket.websocket != None and bucket.websocket.open == True for bucket in self.buckets):
|
||||
|
||||
Reference in New Issue
Block a user