diff --git a/bfxapi/websocket/BfxWebsocketClient.py b/bfxapi/websocket/BfxWebsocketClient.py index 4e7d1d1..94aeaca 100644 --- a/bfxapi/websocket/BfxWebsocketClient.py +++ b/bfxapi/websocket/BfxWebsocketClient.py @@ -39,6 +39,8 @@ class BfxWebsocketClient(object): self.buckets = [ _BfxWebsocketBucket(self.host, self.event_emitter, self.__bucket_open_signal) for _ in range(buckets) ] + self.inputs = _BfxWebsocketInputs(self.__handle_websocket_input) + self.logger = CustomLogger("BfxWebsocketClient", logLevel=log_level) def run(self): @@ -105,7 +107,7 @@ class BfxWebsocketClient(object): await self.websocket.close(code=code, reason=reason) for bucket in self.buckets: - await bucket.close(code=code, reason=reason) + await bucket._close(code=code, reason=reason) def __require_websocket_authentication(function): async def wrapper(self, *args, **kwargs): @@ -121,8 +123,8 @@ class BfxWebsocketClient(object): await self.websocket.send(json.dumps([ 0, "n", MESSAGE_ID, { "type": "ucm-test", "info": info, **kwargs } ])) @__require_websocket_authentication - async def new_order(self, data): - await self.websocket.send(json.dumps([ 0, "on", None, data ])) + async def __handle_websocket_input(self, input, data): + await self.websocket.send(json.dumps([ 0, input, None, data])) def __bucket_open_signal(self, index): if all(bucket.websocket != None and bucket.websocket.open == True for bucket in self.buckets): @@ -212,5 +214,18 @@ class _BfxWebsocketBucket(object): })) @_require_websocket_connection - async def close(self, code=1000, reason=str()): - await self.websocket.close(code=code, reason=reason) \ No newline at end of file + async def _close(self, code=1000, reason=str()): + await self.websocket.close(code=code, reason=reason) + +class _BfxWebsocketInputs(object): + def __init__(self, __handle_websocket_input): + self.__handle_websocket_input = __handle_websocket_input + + async def order_new(self, data): + await self.__handle_websocket_input("on", data) + + async def order_update(self, data): + await self.__handle_websocket_input("ou", data) + + async def order_cancel(self, data): + await self.__handle_websocket_input("oc", data) \ No newline at end of file diff --git a/bfxapi/websocket/enums.py b/bfxapi/websocket/enums.py index 9a89eb0..14c4234 100644 --- a/bfxapi/websocket/enums.py +++ b/bfxapi/websocket/enums.py @@ -7,6 +7,14 @@ class Channels(str, Enum): CANDLES = "candles" STATUS = "status" +class Flags(int, Enum): + HIDDEN = 64 + CLOSE = 512 + REDUCE_ONLY = 1024 + POST_ONLY = 4096 + OCO = 16384 + NO_VAR_RATES = 524288 + class Errors(int, Enum): ERR_UNK = 10000 ERR_GENERIC = 10001 diff --git a/bfxapi/websocket/handlers.py b/bfxapi/websocket/handlers.py index ad3f7b1..9edd986 100644 --- a/bfxapi/websocket/handlers.py +++ b/bfxapi/websocket/handlers.py @@ -124,8 +124,8 @@ class PublicChannelsHandler(object): class AuthenticatedChannelsHandler(object): __abbreviations = { - "os": "order_snapshot", "on": "new_order", "ou": "order_update", "oc": "order_cancel", - "ps": "position_snapshot", "pn": "new_position", "pu": "position_update", "pc": "position_close", + "os": "order_snapshot", "on": "order_new", "ou": "order_update", "oc": "order_cancel", + "ps": "position_snapshot", "pn": "position_new", "pu": "position_update", "pc": "position_close", "te": "trade_executed", "tu": "trade_execution_update", "fos": "funding_offer_snapshot", "fon": "funding_offer_new", "fou": "funding_offer_update", "foc": "funding_offer_cancel", "fcs": "funding_credit_snapshot", "fcn": "funding_credit_new", "fcu": "funding_credit_update", "fcc": "funding_credit_close",