-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CommitmentsOfTraders class and refactor code structure
- Loading branch information
Showing
12 changed files
with
479 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
from functools import lru_cache | ||
from pathlib import Path | ||
|
||
from pydantic_settings import BaseSettings | ||
|
||
|
||
def open_json(path: Path) -> dict: | ||
""" | ||
Opens a json file. | ||
Returns: | ||
The content as a dictionary. | ||
""" | ||
with open(path, "r") as f: | ||
data = json.load(f) | ||
return data | ||
|
||
|
||
class Settings(BaseSettings): | ||
""" | ||
Settings for the pycot package. | ||
""" | ||
|
||
BASE_PATH: Path = Path(__file__).parent.parent | ||
FORMAT_COLUMNS_PATH: Path = BASE_PATH / "pycot" / "store" / "format_columns.json" | ||
COT_REPORTS_DATA_PATH: Path = BASE_PATH / "pycot" / "store" / "cot_reports_data.json" | ||
CONTRACT_NAMES_PATH: Path = BASE_PATH / "pycot" / "store" / "contract_names.json" | ||
|
||
FORMAT_COLUMNS: dict = open_json(FORMAT_COLUMNS_PATH) | ||
COT_REPORTS_DATA: dict = open_json(COT_REPORTS_DATA_PATH) | ||
CONTRACT_NAMES: dict = open_json(CONTRACT_NAMES_PATH) | ||
|
||
|
||
@lru_cache() | ||
def get_settings() -> Settings: | ||
""" | ||
Cache the settings object to avoid reading the environment variables | ||
""" | ||
return Settings() | ||
|
||
|
||
settings = get_settings() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.