Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_update(self, mock_updating):
self.order.status = OrderStatus.EXECUTABLE
with self.assertRaises(OrderUpdateError):
self.order.update("PERSIST")
self.mock_order_type.ORDER_TYPE = OrderTypes.LIMIT
self.mock_order_type.persistence_type = "LAPSE"
self.order.update("PERSIST")
self.assertEqual(self.mock_order_type.persistence_type, "PERSIST")
mock_updating.assert_called_with()
with self.assertRaises(OrderUpdateError):
self.order.update("PERSIST")
def test_cancel(self, mock_cancelling, mock_size_remaining):
mock_size_remaining.return_value = 20
self.order.status = OrderStatus.EXECUTABLE
with self.assertRaises(OrderUpdateError):
self.order.cancel(12)
self.mock_order_type.ORDER_TYPE = OrderTypes.LIMIT
self.order.cancel(0.01)
self.assertEqual(self.order.update_data, {"size_reduction": 0.01})
mock_cancelling.assert_called_with()
self.order.cancel()
self.assertEqual(self.order.update_data, {"size_reduction": None})
def update(self, new_persistence_type: str) -> None:
if self.order_type.ORDER_TYPE == OrderTypes.LIMIT:
if self.order_type.persistence_type == new_persistence_type:
raise OrderUpdateError("Persistence types match")
elif self.status != OrderStatus.EXECUTABLE:
raise OrderUpdateError("Current status: %s" % self.status)
self.order_type.persistence_type = new_persistence_type
self.updating()
else:
raise OrderUpdateError("Only LIMIT orders can be updated.")
def replace(self, new_price: float) -> None:
if self.order_type.ORDER_TYPE in [OrderTypes.LIMIT, OrderTypes.LIMIT_ON_CLOSE]:
if self.order_type.price == new_price:
raise OrderUpdateError("Prices match")
elif self.status != OrderStatus.EXECUTABLE:
raise OrderUpdateError("Current status: %s" % self.status)
self.update_data["new_price"] = new_price
self.replacing()
else:
raise OrderUpdateError(
"Only LIMIT or LIMIT_ON_CLOSE orders can be replaced."
)
def update(self, new_persistence_type: str) -> None:
if self.order_type.ORDER_TYPE == OrderTypes.LIMIT:
if self.order_type.persistence_type == new_persistence_type:
raise OrderUpdateError("Persistence types match")
elif self.status != OrderStatus.EXECUTABLE:
raise OrderUpdateError("Current status: %s" % self.status)
self.order_type.persistence_type = new_persistence_type
self.updating()
else:
raise OrderUpdateError("Only LIMIT orders can be updated.")
def __init__(self, message):
super(OrderUpdateError, self).__init__(message)
def replace(self, new_price: float) -> None:
if self.order_type.ORDER_TYPE in [OrderTypes.LIMIT, OrderTypes.LIMIT_ON_CLOSE]:
if self.order_type.price == new_price:
raise OrderUpdateError("Prices match")
elif self.status != OrderStatus.EXECUTABLE:
raise OrderUpdateError("Current status: %s" % self.status)
self.update_data["new_price"] = new_price
self.replacing()
else:
raise OrderUpdateError(
"Only LIMIT or LIMIT_ON_CLOSE orders can be replaced."
)
def cancel(self, size_reduction: float = None) -> None:
if self.order_type.ORDER_TYPE == OrderTypes.LIMIT:
if size_reduction and self.size_remaining - size_reduction < 0:
raise OrderUpdateError("Size reduction too large")
if self.status != OrderStatus.EXECUTABLE:
raise OrderUpdateError("Current status: %s" % self.status)
self.update_data["size_reduction"] = size_reduction
self.cancelling()
else:
raise OrderUpdateError(
"Only LIMIT orders can be cancelled or partially cancelled once placed."
)
def update(self, new_persistence_type: str) -> None:
if self.order_type.ORDER_TYPE == OrderTypes.LIMIT:
if self.order_type.persistence_type == new_persistence_type:
raise OrderUpdateError("Persistence types match")
elif self.status != OrderStatus.EXECUTABLE:
raise OrderUpdateError("Current status: %s" % self.status)
self.order_type.persistence_type = new_persistence_type
self.updating()
else:
raise OrderUpdateError("Only LIMIT orders can be updated.")
def cancel(self, size_reduction: float = None) -> None:
if self.order_type.ORDER_TYPE == OrderTypes.LIMIT:
if size_reduction and self.size_remaining - size_reduction < 0:
raise OrderUpdateError("Size reduction too large")
if self.status != OrderStatus.EXECUTABLE:
raise OrderUpdateError("Current status: %s" % self.status)
self.update_data["size_reduction"] = size_reduction
self.cancelling()
else:
raise OrderUpdateError(
"Only LIMIT orders can be cancelled or partially cancelled once placed."
)