コード例 #1
0
def test_get_ipo_calendar_400(mocker):
    mock_response = requests.Response()
    mock_response.status_code = 400
    mocker.patch(target="requests.get",
                 new=mocker.Mock(return_value=mock_response))
    ipo_df = finnhub_model.get_ipo_calendar(
        from_date="2021-12-01",
        to_date="2021-12-02",
    )
    assert ipo_df.empty
コード例 #2
0
def past_ipo(
    num_days_behind: int,
    limit: int,
    export: str,
    start_date: datetime = None,
) -> pd.DataFrame:
    """Past IPOs dates. [Source: Finnhub]

    Parameters
    ----------
    num_days_behind: int
        Number of days to look behind for IPOs dates
    starting_day: str
        The starting date (format YYYY-MM-DD) to look for IPOs
    export : str
        Export dataframe data to csv,json,xlsx file
    limit: int
        Limit number of IPOs to display. Default is 20


    Returns
    -------
    df_past_ipo : pd.DataFrame
        Past IPOs dates
    """
    today = datetime.now()

    if start_date is None:

        start_date = today - timedelta(days=num_days_behind)

    df_past_ipo = (finnhub_model.get_ipo_calendar(
        start_date, today.strftime("%Y-%m-%d")).rename(columns={
            "Date": "Past"
        }).fillna(""))

    if df_past_ipo.empty:
        console.print(f"No IPOs found since the last {num_days_behind} days")
    else:
        df_past_ipo = df_past_ipo.sort_values("Past", ascending=False)
        print_rich_table(
            df_past_ipo.head(limit),
            headers=list(df_past_ipo.columns),
            show_index=False,
            title="IPO Dates",
        )
    console.print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "pipo",
        df_past_ipo,
    )
コード例 #3
0
def test_past_ipo(func, mocker):
    ipo_df = finnhub_model.get_ipo_calendar(
        from_date="2021-12-01",
        to_date="2021-12-02",
    )

    mocker.patch(
        "gamestonk_terminal.stocks.discovery.finnhub_view.finnhub_model.get_ipo_calendar",
        return_value=ipo_df,
    )

    getattr(finnhub_view, func)(2, 20, "", None)
コード例 #4
0
def future_ipo(num_days_ahead: int,
               limit: int,
               export: str,
               end_date: datetime = None) -> pd.DataFrame:
    """Future IPOs dates. [Source: Finnhub]

    Parameters
    ----------
    num_days_ahead: int
        Number of days to look ahead for IPOs dates
    end_date: datetime
        The end date (format YYYY-MM-DD) to look for IPOs from today onwards
    export : str
        Export dataframe data to csv,json,xlsx file
    limit: int
        Limit number of IPOs to display. Default is 20

    Returns
    -------
    df_future_ipo : pd.DataFrame
        Future IPOs dates
    """
    today = datetime.now()

    if end_date is None:
        end_date = today + timedelta(days=num_days_ahead)

    df_future_ipo = (finnhub_model.get_ipo_calendar(
        today.strftime("%Y-%m-%d"),
        end_date.strftime("%Y-%m-%d")).rename(columns={
            "Date": "Future"
        }).fillna(""))

    if df_future_ipo.empty:
        console.print(f"No IPOs found for the next {num_days_ahead} days")
    else:
        df_future_ipo = df_future_ipo.sort_values("Future", ascending=False)
        print_rich_table(
            df_future_ipo.head(limit),
            headers=list(df_future_ipo.columns),
            show_index=False,
            title="Future IPO Dates",
        )
    console.print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "fipo",
        df_future_ipo,
    )
コード例 #5
0
def test_get_ipo_calendar_400(mocker):

    attrs = {
        "status_code": 400,
        "json.return_value": {
            "error": "mock error message"
        },
    }

    mock_response = mocker.Mock(**attrs)

    mocker.patch(target="requests.get",
                 new=mocker.Mock(return_value=mock_response))
    ipo_df = finnhub_model.get_ipo_calendar(
        from_date="2021-12-01",
        to_date="2021-12-02",
    )
    assert ipo_df.empty
コード例 #6
0
def past_ipo(num_days_behind: int, export: str) -> pd.DataFrame:
    """Past IPOs dates. [Source: Finnhub]

    Parameters
    ----------
    num_days_behind: int
        Number of days to look behind for IPOs dates
    export : str
        Export dataframe data to csv,json,xlsx file

    Returns
    -------
    df_past_ipo : pd.DataFrame
        Past IPOs dates
    """
    today = datetime.now()
    past_date = today - timedelta(days=num_days_behind)

    df_past_ipo = (
        finnhub_model.get_ipo_calendar(
            past_date.strftime("%Y-%m-%d"), today.strftime("%Y-%m-%d")
        )
        .rename(columns={"Date": "Past"})
        .fillna("")
    )

    if df_past_ipo.empty:
        console.print(f"No IPOs found since the last {num_days_behind} days")
    else:
        print_rich_table(
            df_past_ipo,
            headers=list(df_past_ipo.columns),
            show_index=False,
            title="IPO Dates",
        )
    console.print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "pipo",
        df_past_ipo,
    )
コード例 #7
0
def future_ipo(num_days_ahead: int, export: str) -> pd.DataFrame:
    """Future IPOs dates. [Source: Finnhub]

    Parameters
    ----------
    num_days_ahead: int
        Number of days to look ahead for IPOs dates
    export : str
        Export dataframe data to csv,json,xlsx file

    Returns
    -------
    df_future_ipo : pd.DataFrame
        Future IPOs dates
    """
    today = datetime.now()
    future_date = today + timedelta(days=num_days_ahead)

    df_future_ipo = (finnhub_model.get_ipo_calendar(
        today.strftime("%Y-%m-%d"),
        future_date.strftime("%Y-%m-%d")).rename(columns={
            "Date": "Future"
        }).fillna(""))

    if df_future_ipo.empty:
        print(f"No IPOs found for the next {num_days_ahead} days")
    else:
        print(
            tabulate(
                df_future_ipo,
                headers=df_future_ipo.columns,
                floatfmt=".2f",
                showindex=False,
                tablefmt="fancy_grid",
            ))
    print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "fipo",
        df_future_ipo,
    )
コード例 #8
0
def test_get_ipo_calendar(recorder):
    ipo_df = finnhub_model.get_ipo_calendar(
        from_date="2021-12-01",
        to_date="2021-12-02",
    )
    recorder.capture(ipo_df)