def test_process_current_orders_with_default_sep(self): mock_log_control = mock.Mock() mock_add_market = mock.Mock() market_book = mock.Mock() markets = Markets() market = Market( flumine=mock.Mock(), market_id="market_id", market_book=market_book ) markets.add_market("market_id", market) strategies = Strategies() cheap_hash = create_cheap_hash("strategy_name", 13) trade = mock.Mock(market_id="market_id") trade.strategy.name_hash = cheap_hash current_order = mock.Mock( customer_order_ref=f"{cheap_hash}I123", market_id="market_id", bet_id=None ) betfair_order = BetfairOrder(trade=trade, side="BACK", order_type=mock.Mock()) betfair_order.id = "123" market.blotter = {"123": betfair_order} event = mock.Mock(event=[mock.Mock(orders=[current_order])]) process.process_current_orders( markets=markets, strategies=strategies, event=event, log_control=mock_log_control, add_market=mock_add_market, ) self.assertEqual(current_order, betfair_order.responses.current_order)
def test_create_order_from_current(self): mock_add_market = mock.Mock() market_book = mock.Mock() mock_client = mock.Mock() markets = Markets() market = Market(flumine=mock.Mock(), market_id="market_id", market_book=market_book) markets.add_market("market_id", market) cheap_hash = create_cheap_hash("strategy_name", 13) strategy = mock.Mock(name_hash=cheap_hash) strategies = Strategies() strategies(strategy=strategy, clients=mock.Mock()) current_order = mock.Mock( customer_order_ref=f"{cheap_hash}I123", market_id="market_id", bet_id=None, selection_id="selection_id", handicap="handicap", order_type="LIMIT", price_size=PriceSize(price=10.0, size=2.0), persistence_type="LAPSE", ) new_order = process.create_order_from_current( markets=markets, strategies=strategies, current_order=current_order, add_market=mock_add_market, client=mock_client, ) self.assertEqual(market.blotter["123"], new_order) self.assertEqual(new_order.market_id, "market_id") self.assertEqual(new_order.selection_id, "selection_id") self.assertEqual(new_order.handicap, "handicap") self.assertEqual(new_order.order_type.ORDER_TYPE, OrderTypes.LIMIT) self.assertEqual(new_order.order_type.size, 2.0) self.assertEqual(new_order.order_type.price, 10.0) self.assertEqual(new_order.client, mock_client)
def test_process_current_orders_with_default_sep( self, mock_process_current_order): mock_log_control = mock.Mock() mock_add_market = mock.Mock() market_book = mock.Mock() markets = Markets() market = Market(flumine=mock.Mock(), market_id="market_id", market_book=market_book) markets.add_market("market_id", market) strategies = Strategies() cheap_hash = create_cheap_hash("strategy_name", 13) trade = mock.Mock(market_id="market_id") trade.strategy.name_hash = cheap_hash current_order = mock.Mock(customer_order_ref=f"{cheap_hash}I123", market_id="market_id", bet_id=None) betfair_order = BetfairOrder(trade=trade, side="BACK", order_type=mock.Mock()) betfair_order.id = "123" betfair_order.complete = True market.blotter["123"] = betfair_order event = mock.Mock(event=[mock.Mock(orders=[current_order])]) process.process_current_orders( markets=markets, strategies=strategies, event=event, log_control=mock_log_control, add_market=mock_add_market, ) mock_process_current_order.assert_called_with(betfair_order, current_order, mock_log_control) self.assertEqual(market.blotter._live_orders, [])
def test_create_cheap_hash(self): self.assertEqual( utils.create_cheap_hash("test"), utils.create_cheap_hash("test"), ) self.assertEqual(len(utils.create_cheap_hash("test", 16)), 16)