Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make small adjustments in FINRA #5694

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions openbb_platform/providers/finra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# OpenBB FINRA Provider

This extension integrates the [FINRA](https://finra.org/) data provider into the OpenBB Platform.

## Installation

To install the extension:

```bash
pip install openbb-finra
```

For development please check [Contribution Guidelines](https://github.com/OpenBB-finance/OpenBBTerminal/blob/feature/openbb-sdk-v4/openbb_platform/CONTRIBUTING.md).

Documentation available [here](https://docs.openbb.co/sdk).
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@


class FinraShortInterestQueryParams(ShortInterestQueryParams):
"""Finra Company Filings Query Params."""
"""FINRA Company Filings Query Params."""


class FinraShortInterestData(ShortInterestData):
"""Finra Short Interest Data."""
"""FINRA Short Interest Data."""

__alias_dict__ = {
"symbol": "symbolCode",
Expand All @@ -35,7 +35,7 @@ class FinraShortInterestData(ShortInterestData):
class FinraShortInterestFetcher(
Fetcher[FinraShortInterestQueryParams, List[FinraShortInterestData]]
):
"""Finra Short Interest Fetcher."""
"""FINRA Short Interest Fetcher."""

@staticmethod
def transform_query(params: Dict[str, Any]) -> FinraShortInterestQueryParams:
Expand All @@ -48,8 +48,7 @@ def extract_data(
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[Dict]:
"""Extracts the data from the Finra endpoint."""

"""Extract the data from the Finra endpoint."""
# Put the data in the cache
prepare_data()
# Get the data from the cache
Expand Down Expand Up @@ -81,6 +80,8 @@ def extract_data(
]

@staticmethod
def transform_data(data: List[Dict], **kwargs: Any) -> List[FinraShortInterestData]:
"""Transforms the data."""
def transform_data(
query: FinraShortInterestQueryParams, data: List[Dict], **kwargs: Any
) -> List[FinraShortInterestData]:
"""Transform the data."""
return [FinraShortInterestData.model_validate(d) for d in data]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Finra OTC Aggregates fetcher."""
"""FINRA OTC Aggregates fetcher."""

from typing import Any, Dict, List, Literal, Optional

Expand All @@ -16,19 +16,16 @@ class FinraOTCAggregateQueryParams(OTCAggregateQueryParams):

tier: Literal["T1", "T2", "OTCE"] = Field(
default="T1",
description=(
"T1 - Securities included in the S&P 500, Russell 1000 and selected "
"exchange-traded products; T2 - All other NMS stocks;"
"OTC - Over-the-Counter equity securities",
),
description=""""T1 - Securities included in the S&P 500, Russell 1000 and selected exchange-traded products;
T2 - All other NMS stocks; OTC - Over-the-Counter equity securities""",
)
is_ats: bool = Field(
default=True, description="ATS data if true, NON-ATS otherwise"
)


class FinraOTCAggregateData(OTCAggregateData):
"""Finra OTC Aggregate Data."""
"""FINRA OTC Aggregate Data."""

__alias_dict__ = {
"share_quantity": "totalWeeklyShareQuantity",
Expand All @@ -53,10 +50,12 @@ def extract_data(
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[Dict]:
"""Extracts the data from the FINRA endpoint."""
"""Extract the data from the FINRA endpoint."""
return get_full_data(query.symbol, query.tier, query.is_ats)

@staticmethod
def transform_data(data: List[Dict], **kwargs: Any) -> List[FinraOTCAggregateData]:
"""Transforms the data."""
def transform_data(
query: FinraOTCAggregateQueryParams, data: List[Dict], **kwargs: Any
) -> List[FinraOTCAggregateData]:
"""Transform the data."""
return [FinraOTCAggregateData.model_validate(d) for d in data if d]
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
"""Utility for SEC data storage."""
# This was created as a way to handle short interest data from the SEC.
# The files do not change, so there is no need to download them every time.
"""Utility for FINRA data storage.

This was created as a way to handle short interest data from the FINRA.
The files do not change, so there is no need to download them every time.
"""
import random
import sqlite3
from io import StringIO
from pathlib import Path
from typing import List

import requests
from openbb_core.app.utils import get_user_cache_directory
from openbb_finra.utils.helpers import get_short_interest_dates
from pandas import read_csv

DB_PATH = Path(get_user_cache_directory()) / "caches/sec_short_volume.db"
DB_PATH = Path(get_user_cache_directory()) / "caches/finra_short_volume.db"
DB_PATH.parent.mkdir(parents=True, exist_ok=True)


def get_cached_dates():
def get_cached_dates() -> List:
"""Return the dates that are cached in the DB file."""
cnx = sqlite3.connect(DB_PATH)
cursor = cnx.cursor()

Expand Down
Loading
Loading