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_get_price(self):
self.assertEqual(
utils.get_price(
[{"price": 12, "size": 120}, {"price": 34, "size": 120}], 0
),
12,
)
self.assertEqual(
utils.get_price(
[{"price": 12, "size": 120}, {"price": 34, "size": 120}], 1
),
34,
)
self.assertIsNone(
utils.get_price([{"price": 12, "size": 120}, {"price": 34, "size": 120}], 3)
)
self.assertIsNone(utils.get_price([], 3))
def test_get_price(self):
self.assertEqual(
utils.get_price(
[{"price": 12, "size": 120}, {"price": 34, "size": 120}], 0
),
12,
)
self.assertEqual(
utils.get_price(
[{"price": 12, "size": 120}, {"price": 34, "size": 120}], 1
),
34,
)
self.assertIsNone(
utils.get_price([{"price": 12, "size": 120}, {"price": 34, "size": 120}], 3)
)
self.assertIsNone(utils.get_price([], 3))
def process_market_book(self, market, market_book):
for runner in market_book.runners:
if runner.last_price_traded < 2:
lay = get_price(runner.ex.available_to_lay, 0)
trade = Trade(
market_book.market_id,
runner.selection_id,
runner.handicap,
self,
)
order = trade.create_order(
side="LAY", order_type=LimitOrder(lay, 2.00),
)
self.place_order(market, order)
def place(
self, client, market_book: MarketBook, instruction: dict, bet_id: int
) -> SimulatedPlaceResponse:
# simulates placeOrder request->matching->response
# todo instruction/fillkill/timeInForce etc
if self.order.order_type.ORDER_TYPE == OrderTypes.LIMIT:
runner = self._get_runner(market_book)
available_to_back = get_price(runner.ex.available_to_back, 0) or 1.01
available_to_lay = get_price(runner.ex.available_to_lay, 0) or 1000
price = self.order.order_type.price
size = self.order.order_type.size
if self.order.side == "BACK":
if not client.best_price_execution and available_to_back > price:
return self._create_place_response(
bet_id,
status="FAILURE",
error_code="BET_LAPSED_PRICE_IMPROVEMENT_TOO_LARGE",
)
elif available_to_back >= price:
self._process_price_matched(
market_book.publish_time_epoch,
price,
size,
runner.ex.available_to_back,
def test_get_price(self):
self.assertEqual(
utils.get_price(
[{"price": 12, "size": 120}, {"price": 34, "size": 120}], 0
),
12,
)
self.assertEqual(
utils.get_price(
[{"price": 12, "size": 120}, {"price": 34, "size": 120}], 1
),
34,
)
self.assertIsNone(
utils.get_price([{"price": 12, "size": 120}, {"price": 34, "size": 120}], 3)
)
self.assertIsNone(utils.get_price([], 3))
def _calculate_middle(runner: RunnerBook) -> float:
back = get_price(runner.ex.available_to_back, 0) or 0
lay = get_price(runner.ex.available_to_lay, 0) or 1001
return (float(back) + float(lay)) / 2
def _calculate_middle(runner: RunnerBook) -> float:
back = get_price(runner.ex.available_to_back, 0) or 0
lay = get_price(runner.ex.available_to_lay, 0) or 1001
return (float(back) + float(lay)) / 2