Beispiel #1
0
def test_retrieving_intermittently_cached_trades(tmpdir, provider):
    retriever = HistoricalRetriever(provider=provider, hist_data_dir=tmpdir,)

    data = pd.DataFrame()
    dates = generate_trading_days(
        start_date=date(2020, 7, 21), end_date=date(2020, 7, 23),
    )
    date_ranges = [
        dates[:1],
        dates[-1:],
        dates,
    ]
    for date_range in date_ranges:
        start_date = date_range[0]
        end_date = date_range[-1]

        contract = StockContract(symbol="SPY")

        try:
            data = retriever.retrieve_trades_data(
                contract=contract, start_date=start_date, end_date=end_date,
            )
        except NotImplementedError:
            return

    validate_data_range(data=data, start_date=dates[0], end_date=dates[-1])
Beispiel #2
0
def test_retrieve_non_cached_trades_data(tmpdir, provider):
    start_date = date(2020, 7, 22)
    end_date = date(2020, 7, 23)

    retriever = HistoricalRetriever(provider=provider, hist_data_dir=tmpdir)
    contract = StockContract(symbol="SPY")

    try:
        data = retriever.retrieve_trades_data(
            contract=contract, start_date=start_date, end_date=end_date,
        )
    except NotImplementedError:
        return

    validate_data_range(data=data, start_date=start_date, end_date=end_date)
Beispiel #3
0
def test_retrieve_cached_trades():
    start_date = date(2020, 6, 17)
    end_date = date(2020, 6, 19)

    retriever = HistoricalRetriever(hist_data_dir=TEST_DATA_DIR)

    contract = StockContract(symbol="SPY")
    data = retriever.retrieve_trades_data(
        contract=contract,
        start_date=start_date,
        end_date=end_date,
        cache_only=True,
    )

    assert len(data) != 0

    validate_data_range(data=data, start_date=start_date, end_date=end_date)
Beispiel #4
0
def test_retrieve_non_cached_trades_data_today_partial(tmpdir, provider):
    end_date = date.today()
    start_date = end_date - timedelta(days=1)

    retriever = HistoricalRetriever(provider=provider, hist_data_dir=tmpdir)
    contract = StockContract(symbol="SPY")

    try:
        data = retriever.retrieve_trades_data(
            contract=contract,
            start_date=start_date,
            end_date=end_date,
            allow_partial=True,
            rth=False,
        )
    except NotImplementedError:
        return

    validate_data_range(data=data, start_date=start_date, end_date=end_date)
    assert data.iloc[-1].name.date() == date.today()