From 39e79da9a1f1d25a3f3d38b9b1be54df9b027b0b Mon Sep 17 00:00:00 2001 From: JacobPlaster Date: Wed, 4 Dec 2019 12:07:02 +0000 Subject: [PATCH] Orders: add meta field and support for aff_code --- bfxapi/models/order.py | 6 ++++-- bfxapi/rest/bfx_rest.py | 8 ++++++-- bfxapi/websockets/generic_websocket.py | 2 +- bfxapi/websockets/order_manager.py | 9 ++++++--- docs/rest_v2.md | 3 ++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/bfxapi/models/order.py b/bfxapi/models/order.py index 7afb347..b507af8 100644 --- a/bfxapi/models/order.py +++ b/bfxapi/models/order.py @@ -58,6 +58,7 @@ class OrderClosedModel: PRICE_AUX_LIMIT = 19 NOTIFY = 23 PLACE_ID = 25 + META = 31 class OrderFlags: @@ -109,7 +110,7 @@ class Order: def __init__(self, oid, gid, cid, symbol, mts_create, mts_update, amount, amount_orig, o_type, typePrev, flags, status, price, price_avg, - price_trailing, price_aux_limit, notfiy, place_id): + price_trailing, price_aux_limit, notfiy, place_id, meta={}): self.id = oid # pylint: disable=invalid-name self.gid = gid self.cid = cid @@ -172,10 +173,11 @@ class Order: price_aux_limit = raw_order[OrderClosedModel.PRICE_AUX_LIMIT] notfiy = raw_order[OrderClosedModel.NOTIFY] place_id = raw_order[OrderClosedModel.PLACE_ID] + meta = raw_order[OrderClosedModel.META] or {} return Order(oid, gid, cid, symbol, mts_create, mts_update, amount, amount_orig, o_type, type_prev, flags, status, price, price_avg, - price_trailing, price_aux_limit, notfiy, place_id) + price_trailing, price_aux_limit, notfiy, place_id, meta) @staticmethod def from_raw_order_snapshot(raw_order_snapshot): diff --git a/bfxapi/rest/bfx_rest.py b/bfxapi/rest/bfx_rest.py index 85a60d3..3e584ba 100644 --- a/bfxapi/rest/bfx_rest.py +++ b/bfxapi/rest/bfx_rest.py @@ -491,8 +491,8 @@ class BfxRest: async def submit_order(self, symbol, price, amount, market_type=Order.Type.LIMIT, hidden=False, price_trailing=None, price_aux_limit=None, oco_stop_price=None, close=False, reduce_only=False, - post_only=False, oco=False, time_in_force=None, leverage=None, - gid=None): + post_only=False, oco=False, aff_code=None, time_in_force=None, + leverage=None, gid=None): """ Submit a new order @@ -514,6 +514,7 @@ class BfxRest: match with a pre-existing order @param oco: cancels other order option allows you to place a pair of orders stipulating that if one order is executed fully or partially, then the other is automatically canceled + @param aff_code: bitfinex affiliate code @param time_in_force: datetime for automatic order cancellation ie. 2020-01-01 10:45:23 @param leverage: the amount of leverage to apply to the order as an integer """ @@ -524,6 +525,7 @@ class BfxRest: "symbol": symbol, "amount": str(amount), "price": str(price), + "meta": {} } # calculate and add flags flags = calculate_order_flags(hidden, close, reduce_only, post_only, oco) @@ -541,6 +543,8 @@ class BfxRest: payload['gid'] = gid if leverage is not None: payload['lev'] = str(leverage) + if aff_code is not None: + payload['meta']['aff_code'] = str(aff_code) endpoint = "auth/w/order/submit" raw_notification = await self.post(endpoint, payload) return Notification.from_raw_order(raw_notification) diff --git a/bfxapi/websockets/generic_websocket.py b/bfxapi/websockets/generic_websocket.py index a01d85d..42a7e17 100644 --- a/bfxapi/websockets/generic_websocket.py +++ b/bfxapi/websockets/generic_websocket.py @@ -124,7 +124,7 @@ class GenericWebsocket: async with websockets.connect(self.host) as websocket: self.sockets[socket.id].set_websocket(websocket) self.sockets[socket.id].set_connected() - self.logger.info("Wesocket connected to {}".format(self.host)) + self.logger.info("Websocket connected to {}".format(self.host)) while True: await asyncio.sleep(0) message = await websocket.recv() diff --git a/bfxapi/websockets/order_manager.py b/bfxapi/websockets/order_manager.py index 90f5a7b..0033813 100644 --- a/bfxapi/websockets/order_manager.py +++ b/bfxapi/websockets/order_manager.py @@ -87,8 +87,8 @@ class OrderManager: async def submit_order(self, symbol, price, amount, market_type=Order.Type.LIMIT, hidden=False, price_trailing=None, price_aux_limit=None, oco_stop_price=None, close=False, reduce_only=False, - post_only=False, oco=False, time_in_force=None, leverage=None, - onConfirm=None, onClose=None, gid=None, *args, **kwargs): + post_only=False, oco=False, aff_code=None, time_in_force=None, + leverage=None, onConfirm=None, onClose=None, gid=None, *args, **kwargs): """ Submit a new order @@ -109,7 +109,7 @@ class OrderManager: match with a pre-existing order @param oco: cancels other order option allows you to place a pair of orders stipulating that if one order is executed fully or partially, then the other is automatically canceled - + @param aff_code: bitfinex affiliate code @param time_in_force: datetime for automatic order cancellation ie. 2020-01-01 10:45:23 @param leverage: the amount of leverage to apply to the order as an integer @param onConfirm: function called when the bitfinex websocket receives signal that the order @@ -125,6 +125,7 @@ class OrderManager: "symbol": symbol, "amount": str(amount), "price": str(price), + "meta": {} } # calculate and add flags flags = calculate_order_flags(hidden, close, reduce_only, post_only, oco) @@ -142,6 +143,8 @@ class OrderManager: payload['gid'] = gid if leverage is not None: payload['lev'] = str(leverage) + if aff_code is not None: + payload['meta']['aff_code'] = str(aff_code) # submit the order self.pending_orders[cid] = payload self._create_callback(cid, onConfirm, self.pending_order_confirm_callbacks) diff --git a/docs/rest_v2.md b/docs/rest_v2.md index eb89cc4..afe533b 100644 --- a/docs/rest_v2.md +++ b/docs/rest_v2.md @@ -374,7 +374,7 @@ __Attributes__ ## submit_order ```python -BfxRest.submit_order(self, symbol, price, amount, market_type='LIMIT', hidden=False, price_trailing=None, price_aux_limit=None, oco_stop_price=None, close=False, reduce_only=False, post_only=False, oco=False, time_in_force=None, leverage=None, gid=None) +BfxRest.submit_order(self, symbol, price, amount, market_type='LIMIT', hidden=False, price_trailing=None, price_aux_limit=None, oco_stop_price=None, close=False, reduce_only=False, post_only=False, oco=False, aff_code=None, time_in_force=None, leverage=None, gid=None) ``` Submit a new order @@ -398,6 +398,7 @@ __Attributes__ match with a pre-existing order - `@param oco`: cancels other order option allows you to place a pair of orders stipulating that if one order is executed fully or partially, then the other is automatically canceled +- `@param aff_code`: bitfinex affiliate code - `@param time_in_force`: datetime for automatic order cancellation ie. 2020-01-01 10:45:23 - `@param leverage`: the amount of leverage to apply to the order as an integer