Add Flags enumeration to enums.py. Rename new_order and new_position to order_new and position_new to mantain consistency. Add _BfxWebsocketInputs class with order_new, order_update and order_cancel inputs.

This commit is contained in:
Davide Casale
2022-11-29 15:26:02 +01:00
parent fa073823ce
commit b308bbacbd
3 changed files with 30 additions and 7 deletions

View File

@@ -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)
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)

View File

@@ -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

View File

@@ -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",