financegy 1.5__py3-none-any.whl → 3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- financegy/__init__.py +31 -6
- financegy/cache/cache_manager.py +11 -13
- financegy/config.py +2 -2
- financegy/core/parser.py +324 -104
- financegy/helpers/safe_text.py +3 -0
- financegy/helpers/to_float.py +7 -0
- financegy/modules/portfolio.py +157 -0
- financegy/modules/securities.py +318 -6
- financegy/utils/utils.py +20 -11
- financegy-3.0.dist-info/METADATA +201 -0
- financegy-3.0.dist-info/RECORD +15 -0
- {financegy-1.5.dist-info → financegy-3.0.dist-info}/WHEEL +1 -1
- financegy-1.5.dist-info/METADATA +0 -141
- financegy-1.5.dist-info/RECORD +0 -12
- {financegy-1.5.dist-info → financegy-3.0.dist-info}/licenses/LICENSE +0 -0
- {financegy-1.5.dist-info → financegy-3.0.dist-info}/top_level.txt +0 -0
financegy/__init__.py
CHANGED
|
@@ -1,34 +1,59 @@
|
|
|
1
1
|
"""FinanceGY - a Python library for accessing data from the Guyana Stock Exchange."""
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from financegy.cache.cache_manager import clear_cache
|
|
4
|
+
from financegy.utils.utils import save_to_csv, to_dataframe, save_to_excel
|
|
4
5
|
|
|
5
|
-
from financegy.modules.securities import(
|
|
6
|
+
from financegy.modules.securities import (
|
|
6
7
|
get_securities,
|
|
7
8
|
get_security_by_symbol,
|
|
8
9
|
get_recent_trade,
|
|
10
|
+
get_previous_close,
|
|
11
|
+
get_price_change,
|
|
12
|
+
get_price_change_percent,
|
|
9
13
|
get_security_recent_year,
|
|
10
14
|
get_session_trades,
|
|
15
|
+
get_sessions_average_price,
|
|
16
|
+
get_average_price,
|
|
17
|
+
get_sessions_volatility,
|
|
18
|
+
get_ytd_high_low,
|
|
19
|
+
get_latest_session_for_symbol,
|
|
11
20
|
get_security_session_trade,
|
|
12
21
|
search_securities,
|
|
13
22
|
get_trades_for_year,
|
|
14
|
-
get_historical_trades
|
|
23
|
+
get_historical_trades,
|
|
15
24
|
)
|
|
16
25
|
|
|
17
|
-
from financegy.
|
|
18
|
-
|
|
26
|
+
from financegy.modules.portfolio import (
|
|
27
|
+
calculate_position_value,
|
|
28
|
+
calculate_position_return,
|
|
29
|
+
calculate_position_return_percent,
|
|
30
|
+
calculate_portfolio_summary,
|
|
31
|
+
)
|
|
19
32
|
|
|
20
33
|
__all__ = [
|
|
21
34
|
"get_securities",
|
|
22
35
|
"get_security_by_symbol",
|
|
23
36
|
"get_recent_trade",
|
|
37
|
+
"get_previous_close",
|
|
38
|
+
"get_price_change",
|
|
39
|
+
"get_price_change_percent",
|
|
24
40
|
"get_security_recent_year",
|
|
25
41
|
"get_session_trades",
|
|
42
|
+
"get_sessions_average_price",
|
|
43
|
+
"get_average_price",
|
|
26
44
|
"get_security_session_trade",
|
|
45
|
+
"get_latest_session_for_symbol",
|
|
46
|
+
"get_sessions_volatility",
|
|
47
|
+
"get_ytd_high_low",
|
|
27
48
|
"search_securities",
|
|
28
49
|
"get_trades_for_year",
|
|
29
50
|
"get_historical_trades",
|
|
51
|
+
"calculate_position_value",
|
|
52
|
+
"calculate_position_return",
|
|
53
|
+
"calculate_position_return_percent",
|
|
54
|
+
"calculate_portfolio_summary",
|
|
30
55
|
"clear_cache",
|
|
31
56
|
"save_to_csv",
|
|
32
57
|
"to_dataframe",
|
|
33
|
-
"save_to_excel"
|
|
58
|
+
"save_to_excel",
|
|
34
59
|
]
|
financegy/cache/cache_manager.py
CHANGED
|
@@ -5,20 +5,18 @@ import shutil
|
|
|
5
5
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
6
6
|
CACHE_DIR = os.path.join(SCRIPT_DIR, "cache")
|
|
7
7
|
|
|
8
|
+
|
|
8
9
|
def make_cache_key(func_name, *args, **kwargs):
|
|
9
10
|
"""Create a unique hash for the given function call."""
|
|
10
11
|
|
|
11
|
-
key_data = {
|
|
12
|
-
"func": func_name,
|
|
13
|
-
"args": args,
|
|
14
|
-
"kwargs": kwargs
|
|
15
|
-
}
|
|
12
|
+
key_data = {"func": func_name, "args": args, "kwargs": kwargs}
|
|
16
13
|
|
|
17
14
|
key_string = json.dumps(key_data, sort_keys=True, default=str)
|
|
18
15
|
hashed = hashlib.md5(key_string.encode()).hexdigest()
|
|
19
16
|
|
|
20
17
|
return f"{func_name}_{hashed}.json"
|
|
21
18
|
|
|
19
|
+
|
|
22
20
|
def load_cache(func_name, *args, max_age_days=7, **kwargs):
|
|
23
21
|
os.makedirs(CACHE_DIR, exist_ok=True)
|
|
24
22
|
cache_file = make_cache_key(func_name, *args, **kwargs)
|
|
@@ -36,18 +34,17 @@ def load_cache(func_name, *args, max_age_days=7, **kwargs):
|
|
|
36
34
|
|
|
37
35
|
return data["value"]
|
|
38
36
|
|
|
37
|
+
|
|
39
38
|
def save_cache(func_name, value, *args, **kwargs):
|
|
40
39
|
os.makedirs(CACHE_DIR, exist_ok=True)
|
|
41
40
|
cache_file = make_cache_key(func_name, *args, **kwargs)
|
|
42
41
|
cache_path = os.path.join(CACHE_DIR, cache_file)
|
|
43
42
|
|
|
44
43
|
with open(cache_path, "w") as f:
|
|
45
|
-
json.dump({
|
|
46
|
-
"timestamp": datetime.now().isoformat(),
|
|
47
|
-
"value": value
|
|
48
|
-
}, f)
|
|
44
|
+
json.dump({"timestamp": datetime.now().isoformat(), "value": value}, f)
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
|
|
47
|
+
def clear_cache(silent: bool = False):
|
|
51
48
|
"""Completely clears the FinanceGY cache directory."""
|
|
52
49
|
if not os.path.exists(CACHE_DIR):
|
|
53
50
|
print("No cache directory found.")
|
|
@@ -55,8 +52,9 @@ def clear_cache():
|
|
|
55
52
|
|
|
56
53
|
try:
|
|
57
54
|
shutil.rmtree(CACHE_DIR)
|
|
58
|
-
|
|
55
|
+
if not silent:
|
|
56
|
+
print("\nCache cleared successfully.")
|
|
59
57
|
return True
|
|
60
|
-
|
|
58
|
+
|
|
61
59
|
except Exception as e:
|
|
62
|
-
print(f"Failed to clear cache: {e}")
|
|
60
|
+
print(f"Failed to clear cache: {e}")
|
financegy/config.py
CHANGED