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_take_sp(self):
self.assertFalse(self.simulated.take_sp)
self.simulated.order.order_type.ORDER_TYPE = OrderTypes.LIMIT_ON_CLOSE
self.assertTrue(self.simulated.take_sp)
self.simulated.order.order_type.ORDER_TYPE = OrderTypes.MARKET_ON_CLOSE
self.assertTrue(self.simulated.take_sp)
self.simulated.order.order_type.ORDER_TYPE = OrderTypes.LIMIT
self.simulated.order.order_type.persistence_type = "MARKET_ON_CLOSE"
self.assertTrue(self.simulated.take_sp)
def __call__(self, market_book: MarketBook, runner_analytics):
# simulates order matching
runner = self._get_runner(market_book)
if (
self._bsp_reconciled is False
and market_book.bsp_reconciled
and self.take_sp
):
self._process_sp(market_book.publish_time_epoch, runner)
if self.order.order_type.ORDER_TYPE == OrderTypes.LIMIT and self.size_remaining:
# todo piq cancellations
self._process_traded(
market_book.publish_time_epoch, runner_analytics.traded
)
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."
)