Orders: add meta field and support for aff_code

This commit is contained in:
JacobPlaster
2019-12-04 12:07:02 +00:00
committed by Jacob Plaster
parent 821f8831b9
commit 39e79da9a1
5 changed files with 19 additions and 9 deletions

View File

@@ -58,6 +58,7 @@ class OrderClosedModel:
PRICE_AUX_LIMIT = 19 PRICE_AUX_LIMIT = 19
NOTIFY = 23 NOTIFY = 23
PLACE_ID = 25 PLACE_ID = 25
META = 31
class OrderFlags: class OrderFlags:
@@ -109,7 +110,7 @@ class Order:
def __init__(self, oid, gid, cid, symbol, mts_create, mts_update, amount, def __init__(self, oid, gid, cid, symbol, mts_create, mts_update, amount,
amount_orig, o_type, typePrev, flags, status, price, price_avg, 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.id = oid # pylint: disable=invalid-name
self.gid = gid self.gid = gid
self.cid = cid self.cid = cid
@@ -172,10 +173,11 @@ class Order:
price_aux_limit = raw_order[OrderClosedModel.PRICE_AUX_LIMIT] price_aux_limit = raw_order[OrderClosedModel.PRICE_AUX_LIMIT]
notfiy = raw_order[OrderClosedModel.NOTIFY] notfiy = raw_order[OrderClosedModel.NOTIFY]
place_id = raw_order[OrderClosedModel.PLACE_ID] place_id = raw_order[OrderClosedModel.PLACE_ID]
meta = raw_order[OrderClosedModel.META] or {}
return Order(oid, gid, cid, symbol, mts_create, mts_update, amount, return Order(oid, gid, cid, symbol, mts_create, mts_update, amount,
amount_orig, o_type, type_prev, flags, status, price, price_avg, 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 @staticmethod
def from_raw_order_snapshot(raw_order_snapshot): def from_raw_order_snapshot(raw_order_snapshot):

View File

@@ -491,8 +491,8 @@ class BfxRest:
async def submit_order(self, symbol, price, amount, market_type=Order.Type.LIMIT, async def submit_order(self, symbol, price, amount, market_type=Order.Type.LIMIT,
hidden=False, price_trailing=None, price_aux_limit=None, hidden=False, price_trailing=None, price_aux_limit=None,
oco_stop_price=None, close=False, reduce_only=False, oco_stop_price=None, close=False, reduce_only=False,
post_only=False, oco=False, time_in_force=None, leverage=None, post_only=False, oco=False, aff_code=None, time_in_force=None,
gid=None): leverage=None, gid=None):
""" """
Submit a new order Submit a new order
@@ -514,6 +514,7 @@ class BfxRest:
match with a pre-existing order match with a pre-existing order
@param oco: cancels other order option allows you to place a pair of orders stipulating @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 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 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 leverage: the amount of leverage to apply to the order as an integer
""" """
@@ -524,6 +525,7 @@ class BfxRest:
"symbol": symbol, "symbol": symbol,
"amount": str(amount), "amount": str(amount),
"price": str(price), "price": str(price),
"meta": {}
} }
# calculate and add flags # calculate and add flags
flags = calculate_order_flags(hidden, close, reduce_only, post_only, oco) flags = calculate_order_flags(hidden, close, reduce_only, post_only, oco)
@@ -541,6 +543,8 @@ class BfxRest:
payload['gid'] = gid payload['gid'] = gid
if leverage is not None: if leverage is not None:
payload['lev'] = str(leverage) payload['lev'] = str(leverage)
if aff_code is not None:
payload['meta']['aff_code'] = str(aff_code)
endpoint = "auth/w/order/submit" endpoint = "auth/w/order/submit"
raw_notification = await self.post(endpoint, payload) raw_notification = await self.post(endpoint, payload)
return Notification.from_raw_order(raw_notification) return Notification.from_raw_order(raw_notification)

View File

@@ -124,7 +124,7 @@ class GenericWebsocket:
async with websockets.connect(self.host) as websocket: async with websockets.connect(self.host) as websocket:
self.sockets[socket.id].set_websocket(websocket) self.sockets[socket.id].set_websocket(websocket)
self.sockets[socket.id].set_connected() 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: while True:
await asyncio.sleep(0) await asyncio.sleep(0)
message = await websocket.recv() message = await websocket.recv()

View File

@@ -87,8 +87,8 @@ class OrderManager:
async def submit_order(self, symbol, price, amount, market_type=Order.Type.LIMIT, async def submit_order(self, symbol, price, amount, market_type=Order.Type.LIMIT,
hidden=False, price_trailing=None, price_aux_limit=None, hidden=False, price_trailing=None, price_aux_limit=None,
oco_stop_price=None, close=False, reduce_only=False, oco_stop_price=None, close=False, reduce_only=False,
post_only=False, oco=False, time_in_force=None, leverage=None, post_only=False, oco=False, aff_code=None, time_in_force=None,
onConfirm=None, onClose=None, gid=None, *args, **kwargs): leverage=None, onConfirm=None, onClose=None, gid=None, *args, **kwargs):
""" """
Submit a new order Submit a new order
@@ -109,7 +109,7 @@ class OrderManager:
match with a pre-existing order match with a pre-existing order
@param oco: cancels other order option allows you to place a pair of orders stipulating @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 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 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 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 @param onConfirm: function called when the bitfinex websocket receives signal that the order
@@ -125,6 +125,7 @@ class OrderManager:
"symbol": symbol, "symbol": symbol,
"amount": str(amount), "amount": str(amount),
"price": str(price), "price": str(price),
"meta": {}
} }
# calculate and add flags # calculate and add flags
flags = calculate_order_flags(hidden, close, reduce_only, post_only, oco) flags = calculate_order_flags(hidden, close, reduce_only, post_only, oco)
@@ -142,6 +143,8 @@ class OrderManager:
payload['gid'] = gid payload['gid'] = gid
if leverage is not None: if leverage is not None:
payload['lev'] = str(leverage) payload['lev'] = str(leverage)
if aff_code is not None:
payload['meta']['aff_code'] = str(aff_code)
# submit the order # submit the order
self.pending_orders[cid] = payload self.pending_orders[cid] = payload
self._create_callback(cid, onConfirm, self.pending_order_confirm_callbacks) self._create_callback(cid, onConfirm, self.pending_order_confirm_callbacks)

View File

@@ -374,7 +374,7 @@ __Attributes__
## submit_order ## submit_order
```python ```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 Submit a new order
@@ -398,6 +398,7 @@ __Attributes__
match with a pre-existing order match with a pre-existing order
- `@param oco`: cancels other order option allows you to place a pair of orders stipulating - `@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 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 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 leverage`: the amount of leverage to apply to the order as an integer