mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 23:04:21 +01:00
Rewrite AuthenticatedEventsHandler with _label_array_elements logic. Add support to multiple new events. Fix bug in BfxWebsocketClient.py.
This commit is contained in:
@@ -50,11 +50,140 @@ class AuthenticatedEventsHandler(object):
|
||||
self.event_emitter = event_emitter
|
||||
|
||||
self.__handlers = {
|
||||
"bu": self.__bu_event_handler
|
||||
"bu": self.__bu_event_handler,
|
||||
"ws": self.__ws_event_handler,
|
||||
"wu": self.__wu_event_handler,
|
||||
"os": self.__os_event_handler,
|
||||
"on": self.__on_event_handler
|
||||
}
|
||||
|
||||
def handle(self, type, *parameters):
|
||||
self.__handlers[type](*parameters)
|
||||
def handle(self, type, parameters):
|
||||
if type in self.__handlers:
|
||||
self.__handlers[type](*parameters)
|
||||
|
||||
def __bu_event_handler(self, AUM, AUM_NET):
|
||||
self.event_emitter.emit("balance_update", AUM, AUM_NET)
|
||||
def __bu_event_handler(self, *parameters):
|
||||
self.event_emitter.emit("balance_update", _label_array_elements(
|
||||
[
|
||||
"AUM",
|
||||
"AUM_NET"
|
||||
],
|
||||
*parameters
|
||||
))
|
||||
|
||||
def __ws_event_handler(self, *parameters):
|
||||
self.event_emitter.emit("wallet_snapshot", [
|
||||
_label_array_elements(
|
||||
[
|
||||
"WALLET_TYPE",
|
||||
"CURRENCY",
|
||||
"BALANCE",
|
||||
"UNSETTLED_INTEREST",
|
||||
"BALANCE_AVAILABLE",
|
||||
"DESCRIPTION",
|
||||
"META"
|
||||
],
|
||||
*parameter
|
||||
) for parameter in parameters
|
||||
])
|
||||
|
||||
def __wu_event_handler(self, *parameters):
|
||||
self.event_emitter.emit("wallet_update", _label_array_elements(
|
||||
[
|
||||
"WALLET_TYPE",
|
||||
"CURRENCY",
|
||||
"BALANCE",
|
||||
"UNSETTLED_INTEREST",
|
||||
"BALANCE_AVAILABLE",
|
||||
"DESCRIPTION",
|
||||
"META"
|
||||
],
|
||||
*parameters
|
||||
))
|
||||
|
||||
def __os_event_handler(self, *parameters):
|
||||
self.event_emitter.emit("order_snapshot", [
|
||||
_label_array_elements(
|
||||
[
|
||||
"ID",
|
||||
"GID",
|
||||
"CID",
|
||||
"SYMBOL",
|
||||
"MTS_CREATE",
|
||||
"MTS_UPDATE",
|
||||
"AMOUNT",
|
||||
"AMOUNT_ORIG",
|
||||
"ORDER_TYPE",
|
||||
"TYPE_PREV",
|
||||
"MTS_TIF",
|
||||
"_PLACEHOLDER",
|
||||
"FLAGS",
|
||||
"STATUS",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
"PRICE",
|
||||
"PRICE_AVG",
|
||||
"PRICE_TRAILING",
|
||||
"PRICE_AUX_LIMIT",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
"NOTIFY",
|
||||
"HIDDEN",
|
||||
"PLACED_ID",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
"ROUTING",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
"META"
|
||||
],
|
||||
*parameter
|
||||
) for parameter in parameters
|
||||
])
|
||||
|
||||
def __on_event_handler(self, *parameters):
|
||||
self.event_emitter.emit("new_order", _label_array_elements(
|
||||
[
|
||||
"ID",
|
||||
"GID",
|
||||
"CID",
|
||||
"SYMBOL",
|
||||
"MTS_CREATE",
|
||||
"MTS_UPDATE",
|
||||
"AMOUNT",
|
||||
"AMOUNT_ORIG",
|
||||
"ORDER_TYPE",
|
||||
"TYPE_PREV",
|
||||
"MTS_TIF",
|
||||
"_PLACEHOLDER",
|
||||
"FLAGS",
|
||||
"ORDER_STATUS",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
"PRICE",
|
||||
"PRICE_AVG",
|
||||
"PRICE_TRAILING",
|
||||
"PRICE_AUX_LIMIT",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
"NOTIFY",
|
||||
"HIDDEN",
|
||||
"PLACED_ID",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
"ROUTING",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER"
|
||||
],
|
||||
*parameters
|
||||
))
|
||||
|
||||
def _label_array_elements(labels, *args):
|
||||
if len(labels) != len(args):
|
||||
raise Exception("<labels> and <*args> arguments should contain the same amount of elements.")
|
||||
|
||||
_PLACEHOLDER = "_PLACEHOLDER"
|
||||
|
||||
return { label: args[index] for index, label in enumerate(labels) if label != _PLACEHOLDER }
|
||||
Reference in New Issue
Block a user