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_init(self):
self.assertEqual(self.order_type.EXCHANGE, ExchangeType.BETFAIR)
self.assertEqual(self.order_type.ORDER_TYPE, OrderTypes.LIMIT)
self.assertEqual(self.order_type.price, 1.01)
self.assertEqual(self.order_type.size, 2)
self.assertEqual(self.order_type.persistence_type, "PERSIST")
self.assertEqual(self.order_type.time_in_force, "YES")
self.assertEqual(self.order_type.min_fill_size, 34.5)
self.assertEqual(self.order_type.bet_target_type, "NO")
self.assertEqual(self.order_type.bet_target_size, 2)
def update(self, instruction: dict):
# simulates updateOrder request->update->response
if (
self.order.order_type.ORDER_TYPE == OrderTypes.LIMIT
and self.size_remaining > 0
):
self.order.order_type.persistence_type = instruction.get(
"newPersistenceType"
)
return SimulatedUpdateResponse(status="SUCCESS")
else:
return SimulatedCancelResponse(
status="FAILURE", error_code="BET_ACTION_ERROR",
)
def setUp(self) -> None:
self.mock_order_type = mock.Mock(
price=12, size=2.00, ORDER_TYPE=OrderTypes.LIMIT
)
self.mock_order = mock.Mock(
selection_id=1234, handicap=1, side="BACK", order_type=self.mock_order_type
)
self.simulated = simulated.Simulated(self.mock_order)
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 _validate_betfair_min_size(self, order, order_type):
client = self.flumine.client
if order_type == OrderTypes.LIMIT:
if (
order.order_type.size < client.min_bet_size
and (order.order_type.price * order.order_type.size)
< client.min_bet_payout
):
self._on_error(
order,
"Order size is less than min bet size ({0}) or payout ({1}) for currency".format(
client.min_bet_size, client.min_bet_payout
),
)
else: # todo is this correct?
if (
order.side == "BACK"
and order.order_type.liability < client.min_bet_size
):
def _validate_betfair_order(self, order):
if order.order_type.ORDER_TYPE == OrderTypes.LIMIT:
self._validate_betfair_size(order)
self._validate_betfair_price(order)
self._validate_betfair_min_size(order, OrderTypes.LIMIT)
elif order.order_type.ORDER_TYPE == OrderTypes.LIMIT_ON_CLOSE:
self._validate_betfair_price(order)
self._validate_betfair_liability(order)
self._validate_betfair_min_size(order, OrderTypes.LIMIT_ON_CLOSE)
elif order.order_type.ORDER_TYPE == OrderTypes.MARKET_ON_CLOSE:
self._validate_betfair_liability(order)
self._validate_betfair_min_size(order, OrderTypes.MARKET_ON_CLOSE)
else:
self._on_error(order, "Unknown orderType")
def _validate_betfair_order(self, order):
if order.order_type.ORDER_TYPE == OrderTypes.LIMIT:
self._validate_betfair_size(order)
self._validate_betfair_price(order)
self._validate_betfair_min_size(order, OrderTypes.LIMIT)
elif order.order_type.ORDER_TYPE == OrderTypes.LIMIT_ON_CLOSE:
self._validate_betfair_price(order)
self._validate_betfair_liability(order)
self._validate_betfair_min_size(order, OrderTypes.LIMIT_ON_CLOSE)
elif order.order_type.ORDER_TYPE == OrderTypes.MARKET_ON_CLOSE:
self._validate_betfair_liability(order)
self._validate_betfair_min_size(order, OrderTypes.MARKET_ON_CLOSE)
else:
self._on_error(order, "Unknown orderType")
EXCHANGE = None
ORDER_TYPE = None
def place_instruction(self) -> dict:
raise NotImplementedError
@property
def info(self):
raise NotImplementedError
class LimitOrder(BaseOrderType):
EXCHANGE = ExchangeType.BETFAIR
ORDER_TYPE = OrderTypes.LIMIT
def __init__(
self,
price: float,
size: float,
persistence_type: str = "LAPSE",
time_in_force: str = None,
min_fill_size: float = None,
bet_target_type: str = None,
bet_target_size: float = None,
):
self.price = price
self.size = size
self.persistence_type = persistence_type
self.time_in_force = time_in_force
self.min_fill_size = min_fill_size