Files
OpenBB/openbb_platform/extensions/stocks/integration/test_stocks_python.py
Igor Radovanovic a5d2e833c4 Passing tests (#5560)
* Passing tests

* fix options

* Fix most tests and bugs

* fix forex missing params

* make symbol upper in polygon fx pairs

* fix fixedincome integration tests (#5564)

* Fixing charting api integration tests (#5562)

* fixing charting api integration tests

* black

* fix stocks less five API fails

* fix the 5 failing stocks integration tests

* recapture fmp stock news unit test

* fix fmp forex api test

* couple more forex integration fixes

* changing the request to always use the legacy session. @jmaslek this is was broken for 3.8 and 3.9; with this change apparently all versions work - lemme know if you see any issue with this change

* ruff

* fix ta

* add missing param

* fix testers for the api

* fix globalnews to use images instead of image

* remove unncessary pandas import

* econcal int tests

* update gitignore

* fix get_querystring to support lists

* add missing parameters

---------

Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt>
2023-10-16 12:57:27 +02:00

898 lines
22 KiB
Python

"""Test stocks extension."""
from datetime import time
import pytest
from openbb_core.app.model.obbject import OBBject
@pytest.fixture(scope="session")
def obb(pytestconfig):
"""Fixture to setup obb."""
if pytestconfig.getoption("markexpr") != "not integration":
import openbb
return openbb.obb
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "period": "annual", "limit": 12}),
(
{
"type": "reported",
"year": 2022,
"provider": "intrinio",
"symbol": "AAPL",
"period": "annual",
"limit": 12,
}
),
(
{
"company_name": "Apple Inc.",
"company_name_search": "Apple Inc.",
"sic": "3571",
"include_sources": True,
"order": "asc",
"sort": "filing_date",
"provider": "polygon",
"symbol": "AAPL",
"period": "annual",
"limit": 12,
"filing_date": "2022-10-27",
"filing_date_lt": "2022-11-01",
"filing_date_lte": "2022-11-01",
"filing_date_gt": "2022-10-10",
"filing_date_gte": "2022-10-10",
"period_of_report_date": "2022-09-24",
"period_of_report_date_lt": "2022-11-01",
"period_of_report_date_lte": "2022-11-01",
"period_of_report_date_gt": "2022-10-10",
"period_of_report_date_gte": "2022-10-10",
}
),
(
{
"symbol": "AAPL",
"period": "annual",
"limit": 12,
"provider": "fmp",
"cik": "0000320193",
}
),
(
{
"symbol": "AAPL",
"period": "annual",
"limit": 12,
"provider": "yfinance",
}
),
],
)
@pytest.mark.integration
def test_stocks_fa_balance(params, obb):
result = obb.stocks.fa.balance(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "limit": 10}),
],
)
@pytest.mark.integration
def test_stocks_fa_balance_growth(params, obb):
result = obb.stocks.fa.balance_growth(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
(
{
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
],
)
@pytest.mark.integration
def test_stocks_fa_cal(params, obb):
result = obb.stocks.fa.cal(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "period": "annual", "limit": 12}),
(
{
"type": "reported",
"year": 2022,
"provider": "intrinio",
"symbol": "AAPL",
"period": "annual",
"limit": 12,
}
),
(
{
"company_name": "Apple Inc.",
"company_name_search": "Apple Inc.",
"sic": "3571",
"include_sources": True,
"order": "asc",
"sort": "filing_date",
"provider": "polygon",
"symbol": "AAPL",
"period": "annual",
"limit": 12,
"filing_date": "2022-10-27",
"filing_date_lt": "2022-11-01",
"filing_date_lte": "2022-11-01",
"filing_date_gt": "2022-10-10",
"filing_date_gte": "2022-10-10",
"period_of_report_date": "2022-09-24",
"period_of_report_date_lt": "2022-11-01",
"period_of_report_date_lte": "2022-11-01",
"period_of_report_date_gt": "2022-10-10",
"period_of_report_date_gte": "2022-10-10",
}
),
(
{
"symbol": "AAPL",
"period": "annual",
"limit": 12,
"provider": "fmp",
"cik": "0000320193",
}
),
(
{
"symbol": "AAPL",
"period": "annual",
"limit": 12,
"provider": "yfinance",
}
),
],
)
@pytest.mark.integration
def test_stocks_fa_cash(params, obb):
result = obb.stocks.fa.cash(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "limit": 10}),
],
)
@pytest.mark.integration
def test_stocks_fa_cash_growth(params, obb):
result = obb.stocks.fa.cash_growth(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_fa_comp(params, obb):
result = obb.stocks.fa.comp(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
(
{
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
],
)
@pytest.mark.integration
def test_stocks_fa_comsplit(params, obb):
result = obb.stocks.fa.comsplit(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_fa_divs(params, obb):
result = obb.stocks.fa.divs(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "limit": 50}),
],
)
@pytest.mark.integration
def test_stocks_fa_earning(params, obb):
result = obb.stocks.fa.earning(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_fa_emp(params, obb):
result = obb.stocks.fa.emp(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "period": "annual", "limit": 30}),
],
)
@pytest.mark.integration
def test_stocks_fa_est(params, obb):
result = obb.stocks.fa.est(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "period": "annual", "limit": 12}),
(
{
"type": "reported",
"year": 2022,
"provider": "intrinio",
"symbol": "AAPL",
"period": "annual",
"limit": 12,
}
),
(
{
"company_name": "Apple Inc.",
"company_name_search": "Apple Inc.",
"sic": "3571",
"include_sources": True,
"order": "asc",
"sort": "filing_date",
"provider": "polygon",
"symbol": "AAPL",
"period": "annual",
"limit": 12,
"filing_date": "2022-10-27",
"filing_date_lt": "2022-11-01",
"filing_date_lte": "2022-11-01",
"filing_date_gt": "2022-10-10",
"filing_date_gte": "2022-10-10",
"period_of_report_date": "2022-09-24",
"period_of_report_date_lt": "2022-11-01",
"period_of_report_date_lte": "2022-11-01",
"period_of_report_date_gt": "2022-10-10",
"period_of_report_date_gte": "2022-10-10",
}
),
(
{
"provider": "fmp",
"symbol": "AAPL",
"limit": 12,
"period": "annual",
"cik": "0000320193",
}
),
(
{
"provider": "yfinance",
"symbol": "AAPL",
"limit": 12,
"period": "annual",
}
),
],
)
@pytest.mark.integration
def test_stocks_fa_income(params, obb):
result = obb.stocks.fa.income(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[({"symbol": "AAPL", "limit": 10, "period": "annual"})],
)
@pytest.mark.integration
def test_stocks_fa_income_growth(params, obb):
result = obb.stocks.fa.income_growth(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
(
{
"symbol": "AAPL",
"transactionType": ["P-Purchase"],
"reportingCik": 1,
"companyCik": 1,
"page": 1,
}
),
],
)
@pytest.mark.integration
def test_stocks_fa_ins(params, obb):
result = obb.stocks.fa.ins(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
(
{
"symbol": "AAPL",
"include_current_quarter": True,
"date": "2021-09-30",
}
),
],
)
@pytest.mark.integration
def test_stocks_fa_ins_own(params, obb):
result = obb.stocks.fa.ins_own(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "period": "annual", "limit": 100}),
],
)
@pytest.mark.integration
def test_stocks_fa_metrics(params, obb):
result = obb.stocks.fa.metrics(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_fa_mgmt(params, obb):
result = obb.stocks.fa.mgmt(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_fa_overview(params, obb):
result = obb.stocks.fa.overview(**params)
assert result
assert isinstance(result, OBBject)
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "date": "2023-01-01", "page": 1}),
],
)
@pytest.mark.integration
def test_stocks_fa_own(params, obb):
result = obb.stocks.fa.own(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_fa_pt(params, obb):
result = obb.stocks.fa.pt(**params)
assert result
assert isinstance(result, OBBject)
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
({"with_grade": True, "provider": "fmp", "symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_fa_pta(params, obb):
result = obb.stocks.fa.pta(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "period": "annual", "limit": 12}),
],
)
@pytest.mark.integration
def test_stocks_fa_ratios(params, obb):
result = obb.stocks.fa.ratios(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "period": "annual", "structure": "flat"}),
],
)
@pytest.mark.integration
def test_stocks_fa_revgeo(params, obb):
result = obb.stocks.fa.revgeo(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "period": "annual", "structure": "flat"}),
],
)
@pytest.mark.integration
def test_stocks_fa_revseg(params, obb):
result = obb.stocks.fa.revseg(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "type": "1", "page": 1, "limit": 100, "provider": "fmp"}),
],
)
@pytest.mark.integration
def test_stocks_fa_filings(params, obb):
result = obb.stocks.fa.filings(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_fa_shrs(params, obb):
result = obb.stocks.fa.shrs(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_fa_split(params, obb):
result = obb.stocks.fa.split(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "year": 2023, "quarter": 1}),
],
)
@pytest.mark.integration
def test_stocks_fa_transcript(params, obb):
result = obb.stocks.fa.transcript(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_ca_peers(params, obb):
result = obb.stocks.ca.peers(**params)
assert result
assert isinstance(result, OBBject)
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
({"date": "2023-01-25", "provider": "intrinio", "symbol": "AAPL"}),
({"provider": "cboe", "symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_options_chains(params, obb):
result = obb.stocks.options.chains(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
(
{
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
(
{
"period": "intraday",
"interval": "60min",
"adjusted": True,
"extended_hours": True,
"month": "2023-03",
"outputsize": "full",
"provider": "alpha_vantage",
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"function_": "TIME_SERIES_INTRADAY",
}
),
(
{
"interval": "1m",
"provider": "cboe",
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-01-02",
}
),
(
{
"interval": "1d",
"provider": "cboe",
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
(
{
"interval": "1min",
"provider": "fmp",
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-01-02",
"timeseries": 1,
}
),
(
{
"interval": "1day",
"provider": "fmp",
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"timeseries": 1,
}
),
(
{
"timezone": "UTC",
"source": "realtime",
"interval_size": "30m",
"provider": "intrinio",
"symbol": "AAPL",
"start_date": "2023-10-10",
"end_date": "2023-10-12",
"start_time": time(5, 30, 0),
"end_time": time(12, 0, 0),
}
),
(
{
"timezone": "UTC",
"source": "realtime",
"interval_size": "60m",
"provider": "intrinio",
"symbol": "AAPL",
"start_date": "2023-10-10",
"end_date": "2023-10-12",
"start_time": time(5, 30, 0),
"end_time": time(12, 0, 0),
}
),
(
{
"multiplier": 1,
"timespan": "minute",
"sort": "desc",
"limit": 49999,
"adjusted": True,
"provider": "polygon",
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-01-04",
}
),
(
{
"multiplier": 1,
"timespan": "day",
"sort": "desc",
"limit": 49999,
"adjusted": True,
"provider": "polygon",
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
(
{
"interval": "1d",
"period": "max",
"prepost": True,
"actions": True,
"auto_adjust": True,
"back_adjust": True,
"progress": True,
"ignore_tz": True,
"rounding": True,
"repair": True,
"keepna": True,
"group_by": "column",
"provider": "yfinance",
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-01-08",
}
),
(
{
"interval": "1d",
"period": "max",
"prepost": True,
"actions": True,
"auto_adjust": True,
"back_adjust": True,
"progress": True,
"ignore_tz": True,
"rounding": True,
"repair": True,
"keepna": True,
"group_by": "column",
"provider": "yfinance",
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
],
)
@pytest.mark.integration
def test_stocks_load(params, obb):
result = obb.stocks.load(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbols": "AAPL,MSFT", "limit": 20}),
(
{
"display": "full",
"date": "2023-01-01",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"updated_since": 1,
"published_since": 1,
"sort": "created",
"order": "desc",
"isin": "US0378331005",
"cusip": "037833100",
"channels": "General",
"topics": "AAPL",
"authors": "Benzinga Insights",
"content_types": "headline",
"provider": "benzinga",
"symbols": "AAPL,MSFT",
"limit": 20,
}
),
(
{
"published_utc": "2023-01-01",
"order": "desc",
"provider": "polygon",
"symbols": "AAPL",
"limit": 20,
}
),
(
{
"provider": "fmp",
"symbols": "AAPL",
"limit": 20,
"page": 1,
}
),
(
{
"provider": "yfinance",
"symbols": "AAPL",
"limit": 20,
}
),
(
{
"provider": "intrinio",
"symbols": "AAPL",
"limit": 20,
}
),
],
)
@pytest.mark.integration
def test_stocks_news(params, obb):
result = obb.stocks.news(**params)
assert result
assert isinstance(result, OBBject)
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "limit": 100}),
],
)
@pytest.mark.integration
def test_stocks_multiples(params, obb):
result = obb.stocks.multiples(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"query": "AAPL", "is_symbol": True}),
],
)
@pytest.mark.integration
def test_stocks_search(params, obb):
result = obb.stocks.search(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
({"source": "iex", "provider": "intrinio", "symbol": "AAPL"}),
({"symbol": "AAPL", "provider": "fmp"}),
],
)
@pytest.mark.integration
def test_stocks_quote(params, obb):
result = obb.stocks.quote(**params)
assert result
assert isinstance(result, OBBject)
@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
],
)
@pytest.mark.integration
def test_stocks_info(params, obb):
result = obb.stocks.info(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0