mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
Orders: add meta field and support for aff_code
This commit is contained in:
committed by
Jacob Plaster
parent
821f8831b9
commit
39e79da9a1
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user