Пример #1
0
    def test_time_range(self):
        dt1 = datetime.datetime.now()
        dt2 = datetime.datetime.now() + datetime.timedelta(days=1)

        cases = ((dt1.date(), None), (None, dt1.date()), (123, None), (None,
                                                                       456))

        for case in cases:
            from_ = case[0]
            to = case[1]
            with self.assertRaises(TypeError):
                time_range(from_=from_, to=to)

        response = time_range()
        assert response == {"from": None, "to": None}

        response = time_range(from_=dt1, to=dt2)
        assert response == {"from": dt1.isoformat(), "to": dt2.isoformat()}

        response = time_range(from_="123", to="456")
        assert response == {"from": "123", "to": "456"}
Пример #2
0
def list_market_catalogue():
    trading = get_betfair_client()

    mfilter = market_filter(event_type_ids=[ET_TENNIS],
                            market_start_time=time_range())
    m = trading.betting.list_competitions(mfilter())
    print(m)
    res = trading.betting.list_market_catalogue(mfilter,
                                                market_projection=[
                                                    'EVENT',
                                                    'MARKET_START_TIME',
                                                    'RUNNER_METADATA',
                                                    'COMPETITION',
                                                ],
                                                sort='FIRST_TO_START',
                                                max_results=100,
                                                lightweight=True)
Пример #3
0
def list_market_cat(event_id=None, market_id=None):
    trading = get_betfair_client()
    time_ago = timezone.now() - datetime.timedelta(minutes=10)
    time_fwd = timezone.now() + datetime.timedelta(minutes=30)
    mfilter = market_filter(
        event_type_ids=[ET_HORSE_RACING, ET_GREYHOUND_RACING],
        market_start_time=time_range(
            from_=time_ago.strftime('%Y-%m-%dT%H:%I:%S.000Z'),
            to=time_fwd.strftime('%Y-%m-%dT%H:%I:%S.000Z')))
    res = trading.betting.list_market_catalogue(mfilter,
                                                market_projection=[
                                                    'EVENT',
                                                    'MARKET_START_TIME',
                                                    'MARKET_DESCRIPTION',
                                                    'RUNNER_METADATA',
                                                ],
                                                sort='FIRST_TO_START',
                                                max_results=1,
                                                lightweight=True)
    print(json.dumps(res, indent=4, default=str, sort_keys=True))
    print(len(res))
Пример #4
0
def list_market_catalogue(self):
    logger.warning('+' * 80)
    trading = get_betfair_client()
    time_ago = timezone.now() + datetime.timedelta(minutes=1)
    time_fwd = timezone.now() + datetime.timedelta(minutes=60)
    mfilter = market_filter(
        event_type_ids=[ET_HORSE_RACING, ET_GREYHOUND_RACING],
        market_start_time=time_range(
            from_=time_ago.strftime('%Y-%m-%dT%H:%I:%S.000Z'),
            to=time_fwd.strftime('%Y-%m-%dT%H:%I:%S.000Z')))
    res = trading.betting.list_market_catalogue(mfilter,
                                                market_projection=[
                                                    'EVENT',
                                                    'MARKET_START_TIME',
                                                    'MARKET_DESCRIPTION',
                                                    'RUNNER_METADATA',
                                                ],
                                                sort='FIRST_TO_START',
                                                max_results=100,
                                                lightweight=True)
    if not len(res):
        logger.error('Market catalogue listing is empty')
        trading.session_token = None
        raise self.retry(countdown=5, max_retries=12)

    for cat in res:
        if 'venue' not in cat['event']:
            logger.error(f'No event venue in {cat}')
            continue
        try:
            event = parse_event(cat['event'])
            market = parse_market(event, cat)
            runners = parse_runners(market, cat['runners'])
        except:
            logger.warning(cat)
            raise
    logger.warning(f'BETFAIR: Scraped {len(res)} from market catalogue')
Пример #5
0
    def test_time_range(self):
        response = time_range()
        assert response == {'from': None, 'to': None}

        response = time_range(from_='123', to='456')
        assert response == {'from': '123', 'to': '456'}