Example #1
0
    def test_size_check(self):
        data = [
            PriceSize(**{
                'price': 12,
                'size': 13
            }),
            PriceSize(**{
                'price': 2,
                'size': 3
            })
        ]

        back_a = size_check(data, 0)
        assert back_a == 13

        back_b = size_check(data, 1)
        assert back_b == 3

        back_c = size_check(data, 2)
        assert not back_c

        back_d = size_check(data, 5)
        assert not back_d

        data = []
        back_e = size_check(data, 0)
        assert not back_e
Example #2
0
 def test_sort(self):
     self.available.sort()
     assert self.available.prices == self.prices
     assert self.available.serialise == [
         PriceSize(price=1.01, size=12),
         PriceSize(price=1.02, size=34.45),
     ]
Example #3
0
    def test_sort_short(self):
        current = [[27, 0.95], [13, 28.01], [1.02, 1157.21]]
        available = Available(current, 1)

        assert available.serialise == [
            PriceSize(price=1.02, size=1157.21),
            PriceSize(price=13, size=28.01),
            PriceSize(price=27, size=0.95),
        ]
Example #4
0
    def test_update_price_size_list(self):
        current = [[27, 0.95], [13, 28.01], [1.02, 1157.21]]
        book_update = [[27, 6.9]]

        price_size_list = PriceSizeList(current)
        price_size_list.update(book_update)

        assert price_size_list.entries == [
            PriceSize(1.02, 1157.21),
            PriceSize(13, 28.01),
            PriceSize(27, 6.9),
        ]

        # reverse
        current = [[27, 0.95], [13, 28.01], [1.02, 1157.21]]
        book_update = [[27, 6.9]]

        price_size_list = PriceSizeList(current, reverse=True)
        price_size_list.update(book_update)

        assert price_size_list.entries == [
            PriceSize(27, 6.9),
            PriceSize(13, 28.01),
            PriceSize(1.02, 1157.21),
        ]

        # tests handling of betfair bug, http://forum.bdp.betfair.com/showthread.php?t=3351
        current = [[1.01, 9835.74], [1.02, 1126.22]]
        book_update = [
            [0, 0],
            [1.01, 9835.74],
            [1.02, 1126.22],
        ]

        price_size_list = PriceSizeList(current)
        price_size_list.update(book_update)

        assert price_size_list.entries == [
            PriceSize(1.01, 9835.74),
            PriceSize(1.02, 1126.22),
        ]
            def runner_vals(r):
                (pre_ltp, pre_traded), (post_ltp, post_traded, sp_traded) = r

                inplay_only = list(
                    filter(lambda ps: ps.size > 0, [
                        PriceSize(price=post_ps.price,
                                  size=post_ps.size - next(
                                      (pre_ps.size for pre_ps in pre_traded
                                       if pre_ps.price == post_ps.price), 0))
                        for post_ps in post_traded
                    ]))

                (ip_wavg, ip_matched, ip_min,
                 ip_max) = parse_traded(inplay_only)
                (pre_wavg, pre_matched, pre_min,
                 pre_max) = parse_traded(pre_traded)

                return {
                    'preplay_ltp':
                    as_str(pre_ltp),
                    'preplay_min':
                    as_str(pre_min),
                    'preplay_max':
                    as_str(pre_max),
                    'preplay_wavg':
                    as_str(pre_wavg),
                    'preplay_matched':
                    as_str((pre_matched or 0) + (sp_traded or 0)),
                    'inplay_ltp':
                    as_str(post_ltp),
                    'inplay_min':
                    as_str(ip_min),
                    'inplay_max':
                    as_str(ip_max),
                    'inplay_wavg':
                    as_str(ip_wavg),
                    'inplay_matched':
                    as_str(ip_matched),
                }
Example #6
0
    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_price_size(self):
     price_size = PriceSize(**{'price': 1.01, 'size': 2048})
     self.assertEqual(price_size.price, 1.01)
     self.assertEqual(price_size.size, 2048)
     self.assertEqual(str(price_size), 'Price: 1.01 Size: 2048')
                    as_str((pre_matched or 0) + (sp_traded or 0)),
                    'inplay_ltp':
                    as_str(post_ltp),
                    'inplay_min':
                    as_str(ip_min),
                    'inplay_max':
                    as_str(ip_max),
                    'inplay_wavg':
                    as_str(ip_wavg),
                    'inplay_matched':
                    as_str(ip_matched),
                }

            runner_traded = [
                runner_vals(r) for r in zip_longest(
                    preplay_traded, postplay_traded, fillvalue=PriceSize(0, 0))
            ]

        # runner price data for markets that don't go in play
        else:

            def runner_vals(r):
                (ltp, traded, sp_traded) = r
                (wavg, matched, min_price, max_price) = parse_traded(traded)

                return {
                    'preplay_ltp': as_str(ltp),
                    'preplay_min': as_str(min_price),
                    'preplay_max': as_str(max_price),
                    'preplay_wavg': as_str(wavg),
                    'preplay_matched':
Example #9
0
 def test_price_size(self):
     price_size = PriceSize(**{"price": 1.01, "size": 2048})
     self.assertEqual(price_size.price, 1.01)
     self.assertEqual(price_size.size, 2048)
     self.assertEqual(str(price_size), "Price: 1.01 Size: 2048")