financegy 1.3__tar.gz → 2.0__tar.gz

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-2.0/PKG-INFO ADDED
@@ -0,0 +1,201 @@
1
+ Metadata-Version: 2.4
2
+ Name: financegy
3
+ Version: 2.0
4
+ Summary: Unofficial Python library for accessing GSE (Guyana Stock Exchange) financial data
5
+ Author-email: Ezra Minty <ezranminty@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/xbze3/financegy
8
+ Project-URL: Issues, https://github.com/xbze3/financegy/issues
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: requests
12
+ Requires-Dist: beautifulsoup4
13
+ Requires-Dist: pandas
14
+ Requires-Dist: openpyxl
15
+ Dynamic: license-file
16
+
17
+ # 🏦 FinanceGY
18
+
19
+ **FinanceGY** is an unofficial Python library for accessing financial data from the **Guyana Stock Exchange (GSE)**. It provides a simple and consistent interface for retrieving information on traded securities, recent trade data, and session details, all programmatically.
20
+
21
+ ---
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install financegy
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Quick Start
32
+
33
+ ```python
34
+ import financegy
35
+
36
+ # --------------------------
37
+ # Core Data Retrieval
38
+ # --------------------------
39
+
40
+ # Get a list of all traded securities
41
+ securities = financegy.get_securities()
42
+
43
+ # Get the full name of a security by its ticker symbol
44
+ security_name = financegy.get_security_by_symbol("DDL")
45
+
46
+ # Get the most recent trade data for a security
47
+ recent_trade = financegy.get_recent_trade("DDL")
48
+
49
+ # Get the most recent closing/last trade price (same most-recent session)
50
+ previous_close = financegy.get_previous_close("DDL")
51
+
52
+ # Get absolute price change vs previous session close
53
+ price_change = financegy.get_price_change("DDL")
54
+
55
+ # Get percent price change vs previous session close
56
+ price_change_percent = financegy.get_price_change_percent("DDL")
57
+
58
+ # Get all trade data for the most recent year (for the security)
59
+ recent_year_trades = financegy.get_security_recent_year("DDL")
60
+
61
+ # Get trade data for a specific trading session (all securities)
62
+ session_trades = financegy.get_session_trades("1136")
63
+
64
+ # Get trade data for a specific security in a session
65
+ security_session_trade = financegy.get_security_session_trade("DDL", "1136")
66
+
67
+ # Search for securities by name or symbol
68
+ search_results = financegy.search_securities("DDL")
69
+
70
+ # Get all trades for a specific year
71
+ year_trades = financegy.get_trades_for_year("DDL", "2019")
72
+
73
+ # Get historical trades within a date range — supports: yyyy / mm/yyyy / dd/mm/yyyy
74
+ historical_trades = financegy.get_historical_trades(
75
+ symbol="DDL",
76
+ start_date="01/06/2020",
77
+ end_date="01/2022"
78
+ )
79
+
80
+ # --------------------------
81
+ # Analytics / Calculations
82
+ # --------------------------
83
+
84
+ # Get the latest session info (dict returned from most recent trade)
85
+ latest_session = financegy.get_latest_session_for_symbol("DDL")
86
+
87
+ # Average last traded price over a session range (inclusive)
88
+ avg_price_range = financegy.get_sessions_average_price("DDL", "1100", "1136")
89
+
90
+ # Average last traded price over the last N sessions (ending at latest session)
91
+ avg_price_latest = financegy.get_average_price("DDL", 30)
92
+
93
+ # Volatility over the last N sessions (weekly log-return volatility + annualized)
94
+ volatility = financegy.get_sessions_volatility("DDL", 30)
95
+
96
+ # Year-to-date high and low traded prices
97
+ ytd_high_low = financegy.get_ytd_high_low("DDL")
98
+
99
+ # --------------------------
100
+ # Utilities
101
+ # --------------------------
102
+
103
+ # Convert results to a DataFrame
104
+ df = financegy.to_dataframe(securities)
105
+
106
+ # Export to CSV / Excel
107
+ financegy.save_to_csv(securities, filename="securities.csv", silent=True)
108
+ financegy.save_to_excel(securities, filename="securities.xlsx", silent=True)
109
+
110
+ # Clear FinanceGY cache directory
111
+ financegy.clear_cache(silent=True)
112
+ ```
113
+
114
+ ---
115
+
116
+ ## API Reference
117
+
118
+ ### Core Data Retrieval
119
+
120
+ | Function | Description |
121
+ | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
122
+ | `get_securities()` | Returns all currently traded securities on the GSE. |
123
+ | `get_security_by_symbol(symbol)` | Returns the full security name for a ticker symbol (e.g., `"DDL"` → `"Demerara Distillers Limited"`). |
124
+ | `get_recent_trade(symbol)` | Returns the most recent trade information for the given security. |
125
+ | `get_security_recent_year(symbol)` | Returns all trade data for the most recent year available for the selected security. |
126
+ | `get_session_trades(session)` | Returns trade data for **all** securities during a specific trading session. |
127
+ | `get_security_session_trade(symbol, session)` | Returns trade data for a **specific** security during a specific session. |
128
+ | `search_securities(query)` | Searches securities whose names or ticker symbols match the given query (partial match). |
129
+ | `get_trades_for_year(symbol, year)` | Returns all trade records for a specific security during a given year. |
130
+ | `get_historical_trades(symbol, start_date, end_date)` | Returns historical trades within the specified date range (`dd/mm/yyyy`, `mm/yyyy`, or `yyyy`). |
131
+
132
+ ### Analytics / Calculation Functions
133
+
134
+ | Function | Description |
135
+ | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
136
+ | `get_previous_close(symbol)` | Returns the most recent closing/last trade price for the security. |
137
+ | `get_price_change(symbol)` | Returns absolute price difference between the most recent trade and the previous session close. |
138
+ | `get_price_change_percent(symbol)` | Returns percent price change between the most recent trade and the previous session close. |
139
+ | `get_latest_session_for_symbol(symbol)` | Returns the latest trade dict for the symbol (includes the latest `session`). |
140
+ | `get_sessions_average_price(symbol, session_start, session_end)` | Returns the average last traded price over a session range (inclusive). |
141
+ | `get_average_price(symbol, session_number)` | Returns the average last traded price over the last **N** sessions ending at the latest session. |
142
+ | `get_sessions_volatility(symbol, session_number)` | Returns volatility over the last **N** sessions using log returns (weekly + annualized). |
143
+ | `get_ytd_high_low(symbol)` | Returns year-to-date highest and lowest traded prices for the security. |
144
+
145
+ ### Utilities
146
+
147
+ | Function | Description |
148
+ | ---------------------------------------------------------------------- | --------------------------------------------------------------- |
149
+ | `to_dataframe(data)` | Converts FinanceGY list/dict results into a `pandas.DataFrame`. |
150
+ | `save_to_csv(data, filename="output.csv", path=None, silent=False)` | Saves data to a CSV file. |
151
+ | `save_to_excel(data, filename="output.xlsx", path=None, silent=False)` | Saves data to an Excel file. |
152
+ | `clear_cache(silent=False)` | Completely clears the FinanceGY cache directory. |
153
+
154
+ ---
155
+
156
+ ## Caching System
157
+
158
+ FinanceGY includes a lightweight local caching system designed to speed up repeated requests and reduce unnecessary calls.
159
+
160
+ Whenever you call a data retrieval function (such as `get_securities()` or `get_recent_trade()`), FinanceGY automatically checks whether a cached response already exists for that specific query:
161
+
162
+ - If a valid cache file (less than 7 days old since sessions are held once per week) is found, the result is returned instantly from the cache.
163
+ - If the cache is missing, disabled, or older than one week, FinanceGY fetches fresh data from the GSE and updates the cache automatically.
164
+
165
+ All cache files are stored in a local `cache/` directory as small JSON files containing the retrieved data and a timestamp.
166
+
167
+ You can manually clear all cached data at any time:
168
+
169
+ ```python
170
+ import financegy
171
+
172
+ financegy.clear_cache()
173
+ ```
174
+
175
+ This will delete all cached files and force the next data request to fetch fresh data directly from the source.
176
+
177
+ If you prefer to bypass the cache for a specific call, simply pass `use_cache=False` to any function. For example:
178
+
179
+ ```python
180
+ # Force a fresh fetch from the GSE, ignoring cached data
181
+ recent_trade = financegy.get_recent_trade("DDL", use_cache=False)
182
+ ```
183
+
184
+ By default, caching is enabled for all supported functions unless explicitly turned off.
185
+
186
+ ---
187
+
188
+ ## License
189
+
190
+ This project is licensed under the **MIT License**
191
+
192
+ ---
193
+
194
+ ## Example Use Case
195
+
196
+ ```python
197
+ import financegy
198
+
199
+ ddl_recent = financegy.get_security_recent("DDL")
200
+ print(ddl_recent)
201
+ ```
@@ -0,0 +1,185 @@
1
+ # 🏦 FinanceGY
2
+
3
+ **FinanceGY** is an unofficial Python library for accessing financial data from the **Guyana Stock Exchange (GSE)**. It provides a simple and consistent interface for retrieving information on traded securities, recent trade data, and session details, all programmatically.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install financegy
11
+ ```
12
+
13
+ ---
14
+
15
+ ## Quick Start
16
+
17
+ ```python
18
+ import financegy
19
+
20
+ # --------------------------
21
+ # Core Data Retrieval
22
+ # --------------------------
23
+
24
+ # Get a list of all traded securities
25
+ securities = financegy.get_securities()
26
+
27
+ # Get the full name of a security by its ticker symbol
28
+ security_name = financegy.get_security_by_symbol("DDL")
29
+
30
+ # Get the most recent trade data for a security
31
+ recent_trade = financegy.get_recent_trade("DDL")
32
+
33
+ # Get the most recent closing/last trade price (same most-recent session)
34
+ previous_close = financegy.get_previous_close("DDL")
35
+
36
+ # Get absolute price change vs previous session close
37
+ price_change = financegy.get_price_change("DDL")
38
+
39
+ # Get percent price change vs previous session close
40
+ price_change_percent = financegy.get_price_change_percent("DDL")
41
+
42
+ # Get all trade data for the most recent year (for the security)
43
+ recent_year_trades = financegy.get_security_recent_year("DDL")
44
+
45
+ # Get trade data for a specific trading session (all securities)
46
+ session_trades = financegy.get_session_trades("1136")
47
+
48
+ # Get trade data for a specific security in a session
49
+ security_session_trade = financegy.get_security_session_trade("DDL", "1136")
50
+
51
+ # Search for securities by name or symbol
52
+ search_results = financegy.search_securities("DDL")
53
+
54
+ # Get all trades for a specific year
55
+ year_trades = financegy.get_trades_for_year("DDL", "2019")
56
+
57
+ # Get historical trades within a date range — supports: yyyy / mm/yyyy / dd/mm/yyyy
58
+ historical_trades = financegy.get_historical_trades(
59
+ symbol="DDL",
60
+ start_date="01/06/2020",
61
+ end_date="01/2022"
62
+ )
63
+
64
+ # --------------------------
65
+ # Analytics / Calculations
66
+ # --------------------------
67
+
68
+ # Get the latest session info (dict returned from most recent trade)
69
+ latest_session = financegy.get_latest_session_for_symbol("DDL")
70
+
71
+ # Average last traded price over a session range (inclusive)
72
+ avg_price_range = financegy.get_sessions_average_price("DDL", "1100", "1136")
73
+
74
+ # Average last traded price over the last N sessions (ending at latest session)
75
+ avg_price_latest = financegy.get_average_price("DDL", 30)
76
+
77
+ # Volatility over the last N sessions (weekly log-return volatility + annualized)
78
+ volatility = financegy.get_sessions_volatility("DDL", 30)
79
+
80
+ # Year-to-date high and low traded prices
81
+ ytd_high_low = financegy.get_ytd_high_low("DDL")
82
+
83
+ # --------------------------
84
+ # Utilities
85
+ # --------------------------
86
+
87
+ # Convert results to a DataFrame
88
+ df = financegy.to_dataframe(securities)
89
+
90
+ # Export to CSV / Excel
91
+ financegy.save_to_csv(securities, filename="securities.csv", silent=True)
92
+ financegy.save_to_excel(securities, filename="securities.xlsx", silent=True)
93
+
94
+ # Clear FinanceGY cache directory
95
+ financegy.clear_cache(silent=True)
96
+ ```
97
+
98
+ ---
99
+
100
+ ## API Reference
101
+
102
+ ### Core Data Retrieval
103
+
104
+ | Function | Description |
105
+ | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
106
+ | `get_securities()` | Returns all currently traded securities on the GSE. |
107
+ | `get_security_by_symbol(symbol)` | Returns the full security name for a ticker symbol (e.g., `"DDL"` → `"Demerara Distillers Limited"`). |
108
+ | `get_recent_trade(symbol)` | Returns the most recent trade information for the given security. |
109
+ | `get_security_recent_year(symbol)` | Returns all trade data for the most recent year available for the selected security. |
110
+ | `get_session_trades(session)` | Returns trade data for **all** securities during a specific trading session. |
111
+ | `get_security_session_trade(symbol, session)` | Returns trade data for a **specific** security during a specific session. |
112
+ | `search_securities(query)` | Searches securities whose names or ticker symbols match the given query (partial match). |
113
+ | `get_trades_for_year(symbol, year)` | Returns all trade records for a specific security during a given year. |
114
+ | `get_historical_trades(symbol, start_date, end_date)` | Returns historical trades within the specified date range (`dd/mm/yyyy`, `mm/yyyy`, or `yyyy`). |
115
+
116
+ ### Analytics / Calculation Functions
117
+
118
+ | Function | Description |
119
+ | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
120
+ | `get_previous_close(symbol)` | Returns the most recent closing/last trade price for the security. |
121
+ | `get_price_change(symbol)` | Returns absolute price difference between the most recent trade and the previous session close. |
122
+ | `get_price_change_percent(symbol)` | Returns percent price change between the most recent trade and the previous session close. |
123
+ | `get_latest_session_for_symbol(symbol)` | Returns the latest trade dict for the symbol (includes the latest `session`). |
124
+ | `get_sessions_average_price(symbol, session_start, session_end)` | Returns the average last traded price over a session range (inclusive). |
125
+ | `get_average_price(symbol, session_number)` | Returns the average last traded price over the last **N** sessions ending at the latest session. |
126
+ | `get_sessions_volatility(symbol, session_number)` | Returns volatility over the last **N** sessions using log returns (weekly + annualized). |
127
+ | `get_ytd_high_low(symbol)` | Returns year-to-date highest and lowest traded prices for the security. |
128
+
129
+ ### Utilities
130
+
131
+ | Function | Description |
132
+ | ---------------------------------------------------------------------- | --------------------------------------------------------------- |
133
+ | `to_dataframe(data)` | Converts FinanceGY list/dict results into a `pandas.DataFrame`. |
134
+ | `save_to_csv(data, filename="output.csv", path=None, silent=False)` | Saves data to a CSV file. |
135
+ | `save_to_excel(data, filename="output.xlsx", path=None, silent=False)` | Saves data to an Excel file. |
136
+ | `clear_cache(silent=False)` | Completely clears the FinanceGY cache directory. |
137
+
138
+ ---
139
+
140
+ ## Caching System
141
+
142
+ FinanceGY includes a lightweight local caching system designed to speed up repeated requests and reduce unnecessary calls.
143
+
144
+ Whenever you call a data retrieval function (such as `get_securities()` or `get_recent_trade()`), FinanceGY automatically checks whether a cached response already exists for that specific query:
145
+
146
+ - If a valid cache file (less than 7 days old since sessions are held once per week) is found, the result is returned instantly from the cache.
147
+ - If the cache is missing, disabled, or older than one week, FinanceGY fetches fresh data from the GSE and updates the cache automatically.
148
+
149
+ All cache files are stored in a local `cache/` directory as small JSON files containing the retrieved data and a timestamp.
150
+
151
+ You can manually clear all cached data at any time:
152
+
153
+ ```python
154
+ import financegy
155
+
156
+ financegy.clear_cache()
157
+ ```
158
+
159
+ This will delete all cached files and force the next data request to fetch fresh data directly from the source.
160
+
161
+ If you prefer to bypass the cache for a specific call, simply pass `use_cache=False` to any function. For example:
162
+
163
+ ```python
164
+ # Force a fresh fetch from the GSE, ignoring cached data
165
+ recent_trade = financegy.get_recent_trade("DDL", use_cache=False)
166
+ ```
167
+
168
+ By default, caching is enabled for all supported functions unless explicitly turned off.
169
+
170
+ ---
171
+
172
+ ## License
173
+
174
+ This project is licensed under the **MIT License**
175
+
176
+ ---
177
+
178
+ ## Example Use Case
179
+
180
+ ```python
181
+ import financegy
182
+
183
+ ddl_recent = financegy.get_security_recent("DDL")
184
+ print(ddl_recent)
185
+ ```
@@ -0,0 +1,48 @@
1
+ """FinanceGY - a Python library for accessing data from the Guyana Stock Exchange."""
2
+
3
+ from financegy.cache.cache_manager import clear_cache
4
+ from financegy.utils.utils import save_to_csv, to_dataframe, save_to_excel
5
+
6
+ from financegy.modules.securities import (
7
+ get_securities,
8
+ get_security_by_symbol,
9
+ get_recent_trade,
10
+ get_previous_close,
11
+ get_price_change,
12
+ get_price_change_percent,
13
+ get_security_recent_year,
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,
20
+ get_security_session_trade,
21
+ search_securities,
22
+ get_trades_for_year,
23
+ get_historical_trades,
24
+ )
25
+
26
+ __all__ = [
27
+ "get_securities",
28
+ "get_security_by_symbol",
29
+ "get_recent_trade",
30
+ "get_previous_close",
31
+ "get_price_change",
32
+ "get_price_change_percent",
33
+ "get_security_recent_year",
34
+ "get_session_trades",
35
+ "get_sessions_average_price",
36
+ "get_average_price",
37
+ "get_security_session_trade",
38
+ "get_latest_session_for_symbol",
39
+ "get_sessions_volatility",
40
+ "get_ytd_high_low",
41
+ "search_securities",
42
+ "get_trades_for_year",
43
+ "get_historical_trades",
44
+ "clear_cache",
45
+ "save_to_csv",
46
+ "to_dataframe",
47
+ "save_to_excel",
48
+ ]
@@ -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
- def clear_cache():
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
- print("Cache cleared successfully.")
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}")
@@ -1,7 +1,7 @@
1
- __version__ = "0.1.0"
1
+ __version__ = "2.0"
2
2
 
3
3
  BASE_URL = "https://guyanastockexchangeinc.com"
4
4
  HEADERS = {
5
5
  "User-Agent": f"FinanceGY/{__version__} (https://github.com/xbze3/financegy)"
6
6
  }
7
- REQUEST_TIMEOUT = 10
7
+ REQUEST_TIMEOUT = 10