neurostats-API 0.0.16__tar.gz → 0.0.17__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/PKG-INFO +1 -1
  2. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/base.py +17 -0
  3. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/tech.py +54 -25
  4. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API.egg-info/PKG-INFO +1 -1
  5. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/setup.py +1 -1
  6. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/MANIFEST.in +0 -0
  7. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/README.md +0 -0
  8. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/__init__.py +0 -0
  9. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/cli.py +0 -0
  10. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/__init__.py +0 -0
  11. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/balance_sheet.py +0 -0
  12. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/cash_flow.py +0 -0
  13. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/finance_overview.py +0 -0
  14. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/institution.py +0 -0
  15. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/margin_trading.py +0 -0
  16. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/month_revenue.py +0 -0
  17. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/profit_lose.py +0 -0
  18. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/tej_finance_report.py +0 -0
  19. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/fetchers/value_invest.py +0 -0
  20. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/main.py +0 -0
  21. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/tools/balance_sheet.yaml +0 -0
  22. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/tools/cash_flow_percentage.yaml +0 -0
  23. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/tools/finance_overview_dict.yaml +0 -0
  24. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/tools/profit_lose.yaml +0 -0
  25. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/tools/seasonal_data_field_dict.txt +0 -0
  26. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/utils/__init__.py +0 -0
  27. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/utils/calculate_value.py +0 -0
  28. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/utils/data_process.py +0 -0
  29. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/utils/datetime.py +0 -0
  30. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/utils/db_client.py +0 -0
  31. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API/utils/fetcher.py +0 -0
  32. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API.egg-info/SOURCES.txt +0 -0
  33. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API.egg-info/dependency_links.txt +0 -0
  34. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API.egg-info/requires.txt +0 -0
  35. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/neurostats_API.egg-info/top_level.txt +0 -0
  36. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/setup.cfg +0 -0
  37. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/test/test_fetchers.py +0 -0
  38. {neurostats_api-0.0.16 → neurostats_api-0.0.17}/test/test_tej.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neurostats_API
3
- Version: 0.0.16
3
+ Version: 0.0.17
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -53,6 +53,23 @@ class StatsFetcher:
53
53
  season = (month - 1) // 3 + 1
54
54
 
55
55
  return StatsDateTime(date, year, month, day, season)
56
+
57
+ def has_required_columns(self, df:pd.DataFrame, required_cols=None):
58
+ """
59
+ Check if the required columns are present in the DataFrame.
60
+
61
+ Args:
62
+ df (pd.DataFrame): The DataFrame to check.
63
+ required_cols (list, optional): List of required column names.
64
+ Defaults to ['date', 'open', 'high', 'low', 'close', 'volume'].
65
+
66
+ Returns:
67
+ bool: True if all required columns are present, False otherwise.
68
+ """
69
+ if required_cols is None:
70
+ required_cols = ['date', 'open', 'high', 'low', 'close', 'volume']
71
+
72
+ return all(col in df.columns for col in required_cols)
56
73
 
57
74
 
58
75
  class BaseTEJFetcher(abc.ABC):
@@ -47,40 +47,46 @@ class TechFetcher(StatsFetcher):
47
47
  )
48
48
 
49
49
  def _get_ohlcv(self):
50
-
51
- if self.ticker in ['GSPC', 'IXIC', 'DJI', 'TWII']:
52
-
53
- full_tick = f'^{self.ticker}'
54
- yf_ticker = yf.Ticker(full_tick)
55
- origin_df = yf_ticker.history(period="10y")
56
- origin_df = origin_df.reset_index()
57
- origin_df["Date"] = pd.to_datetime(origin_df["Date"]).dt.date
58
- df = origin_df.rename(
59
- columns={
60
- "Date": "date",
61
- "Open": "open",
62
- "High": "high",
63
- "Low": "low",
64
- "Close": "close",
65
- "Volume": "volume"
66
- }
67
- )
68
- else:
69
50
 
51
+ required_cols = ['date', 'open', 'high', 'low', 'close', 'volume']
52
+
53
+ try:
70
54
  query = {'ticker': self.ticker}
71
- ticker_full = list(self.collection.find(query))
55
+ ticker_full = self.collection.find_one(query)
72
56
 
73
57
  if not ticker_full:
74
58
  raise ValueError(f"No data found for ticker: {self.ticker}")
75
59
 
76
- if 'daily_data' not in ticker_full[0] or ticker_full[0]['daily_data'] is None:
77
- raise KeyError("Missing 'daily_data' in the retrieved data")
60
+ daily_data = ticker_full.get("daily_data", [])
61
+ if not isinstance(daily_data, list):
62
+ raise TypeError("Expected 'daily_data' to be a list.")
63
+
64
+ df = pd.DataFrame(daily_data)
78
65
 
79
- df = pd.DataFrame(ticker_full[0]['daily_data'])
66
+ if not self.has_required_columns(df, required_cols):
67
+ raise KeyError(f"Missing required columns")
80
68
 
81
- selected_cols = ['date','open','high','low','close','volume']
69
+ except (KeyError, ValueError, TypeError) as e:
70
+
71
+ print(f"Conduct yf searching")
72
+
73
+ if self.ticker in ['GSPC', 'IXIC', 'DJI', 'TWII']:
74
+ full_tick = f'^{self.ticker}'
75
+ else:
76
+ full_tick = f'{self.ticker}.tw'
77
+
78
+ df = self.conduct_yf_search(full_tick)
79
+
80
+ if not self.has_required_columns(df, required_cols):
81
+
82
+ print(f".tw failed, try .two")
83
+
84
+ full_tick = f'{self.ticker}.two'
85
+
86
+ df = self.conduct_yf_search(full_tick)
87
+
88
+ return df[required_cols]
82
89
 
83
- return df[selected_cols]
84
90
 
85
91
  def get_daily(self):
86
92
 
@@ -101,6 +107,29 @@ class TechFetcher(StatsFetcher):
101
107
  def get_yearly(self):
102
108
 
103
109
  return self.yearly_index
110
+
111
+ def conduct_yf_search(self, ticker:str):
112
+
113
+ yf_ticker = yf.Ticker(ticker)
114
+ origin_df = yf_ticker.history(period="10y")
115
+
116
+ if origin_df.empty:
117
+ return origin_df
118
+
119
+ origin_df = origin_df.reset_index()
120
+ origin_df["Date"] = pd.to_datetime(origin_df["Date"])
121
+ df = origin_df.rename(
122
+ columns={
123
+ "Date": "date",
124
+ "Open": "open",
125
+ "High": "high",
126
+ "Low": "low",
127
+ "Close": "close",
128
+ "Volume": "volume"
129
+ }
130
+ )
131
+
132
+ return df
104
133
 
105
134
  class TechProcessor:
106
135
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neurostats_API
3
- Version: 0.0.16
3
+ Version: 0.0.17
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='neurostats_API',
5
- version='0.0.16',
5
+ version='0.0.17',
6
6
  long_description=open('README.md', 'r', encoding='utf-8').read(),
7
7
  long_description_content_type='text/markdown',
8
8
  install_requires=[