neurostats-API 0.0.22__py3-none-any.whl → 0.0.23b0__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.
@@ -1,4 +1,4 @@
1
- __version__='0.0.22'
1
+ __version__='0.0.23b'
2
2
 
3
3
  from .fetchers import (
4
4
  BalanceSheetFetcher,
@@ -13,7 +13,8 @@ class TechFetcher(StatsFetcher):
13
13
 
14
14
  super().__init__(ticker, db_client)
15
15
  if (ticker in self.tw_company_list.keys()):
16
- self.collection = self.db["TWN/APIPRCD"]
16
+ self.twse_collection = self.db['twse_stats']
17
+ self.tej_collection = self.db["TWN/APIPRCD"]
17
18
 
18
19
  self.full_ohlcv = self._get_ohlcv()
19
20
  self.basic_indexes = [
@@ -53,35 +54,47 @@ class TechFetcher(StatsFetcher):
53
54
 
54
55
  required_cols = ['date', 'open', 'high', 'low', 'close', 'volume']
55
56
 
56
- try:
57
- # 先對yf search
58
- if self.ticker in ['GSPC', 'IXIC', 'DJI', 'TWII']:
59
- full_tick = f'^{self.ticker}'
60
- elif(self.ticker in self.tw_company_list.keys()):
61
- full_tick = f'{self.ticker}.tw'
62
- else:
63
- full_tick = f"{self.ticker}"
64
-
57
+ if self.ticker in ['GSPC', 'IXIC', 'DJI', 'TWII']:
58
+ full_tick = f'^{self.ticker}'
65
59
  df = self.conduct_yf_search(full_tick)
66
60
 
67
- if (
68
- self.ticker in self.tw_company_list.keys() and
69
- not self.has_required_columns(df, required_cols)
70
- ):
71
- full_tick = f'{self.ticker}.two'
61
+ return df[required_cols]
72
62
 
73
- df = self.conduct_yf_search(full_tick)
63
+ elif(self.ticker in self.tw_company_list.keys()):
64
+ search_fns = [
65
+ self.conduct_db_search_twse,
66
+ self.conduct_db_search_tej,
67
+ lambda: self.conduct_yf_search(f'{self.ticker}.tw'),
68
+ lambda: self.conduct_yf_search(f'{self.ticker}.two')
69
+ ]
70
+
71
+ for search_method in search_fns:
72
+ try:
73
+ df = search_method()
74
+ break
75
+ except (KeyError, ValueError, TypeError):
76
+ continue
77
+ else:
78
+ return pd.DataFrame(columns=required_cols)
74
79
 
75
- if (df.empty):
76
- raise ValueError(f"No data found for ticker: {self.ticker}")\
77
-
80
+ # break跳出後
78
81
  return df[required_cols]
82
+ else: # 美股
83
+ search_fns = [
84
+ self.conduct_db_search_us,
85
+ lambda : self.conduct_yf_search(f"{self.ticker}")
86
+ ]
87
+ for search_method in search_fns:
88
+ try:
89
+ df = search_method()
90
+ break
91
+ except (KeyError, ValueError, TypeError):
92
+ continue
93
+ else:
94
+ df = pd.DataFrame()
79
95
 
80
- except (KeyError, ValueError, TypeError) as e:
81
- if (self.collection_name in ['TWN/APIPRCD']):
82
- return self.conduct_db_search_tej()
83
- elif (self.collection_name == 'us_stats'):
84
- return self.conduct_db_search_us()
96
+ return df
97
+
85
98
 
86
99
  def get_daily(self):
87
100
 
@@ -182,6 +195,86 @@ class TechFetcher(StatsFetcher):
182
195
 
183
196
  return df[required_cols]
184
197
 
198
+
199
+ def conduct_db_search_twse(self):
200
+ required_cols = ['date', 'open', 'high', 'low', 'close', 'volume']
201
+ match_query = {"ticker" : self.ticker}
202
+ proj_query = {"_id": 0, "daily_data": 1}
203
+
204
+ full_data = self.twse_collection.find_one(match_query, proj_query)
205
+
206
+ if (not full_data):
207
+ raise ValueError("No ticker found in database twse_stats")
208
+
209
+ daily_data = full_data.get("daily_data", [])
210
+
211
+ if (not isinstance(daily_data, list)):
212
+ raise ValueError("No ticker found in database twse_stats")
213
+
214
+ df = pd.DataFrame(daily_data)
215
+ if not self.has_required_columns(df, required_cols):
216
+ raise KeyError(f"Missing required columns")
217
+
218
+ df = df[required_cols]
219
+ df = df.sort_values(by = 'date').drop_duplicates(subset=['date'])
220
+
221
+ return df
222
+
223
+ def conduct_db_search_tej(self):
224
+ # 再對TEJ search
225
+ tej_required_cols = [
226
+ "mdate", "open_d", 'high_d', 'low_d', 'close_d', 'vol'
227
+ ]
228
+
229
+ required_cols = ['date', 'open', 'high', 'low', 'close', 'volume']
230
+ tej_name_proj = {
231
+ tej_name: org_name
232
+ for tej_name, org_name in zip(tej_required_cols, required_cols)
233
+ }
234
+
235
+ query = {'ticker': self.ticker}
236
+ ticker_full = self.tej_collection.find_one(query)
237
+
238
+ if not ticker_full:
239
+ raise ValueError("No ticker found in database")
240
+
241
+ daily_data = ticker_full.get("data", [])
242
+ if not isinstance(daily_data, list):
243
+ raise TypeError("Expected 'daily_data' to be a list.")
244
+
245
+ df = pd.DataFrame(daily_data)
246
+
247
+ if not self.has_required_columns(df, tej_required_cols):
248
+ raise KeyError(f"Missing required columns")
249
+ df = df.rename(columns=tej_name_proj)
250
+
251
+ return df[required_cols]
252
+
253
+ def conduct_db_search_us(self):
254
+ required_cols = ['date', 'open', 'high', 'low', 'close', 'volume']
255
+
256
+ query = {'ticker': self.ticker}
257
+ filter_query = {"daily_data" : 1, "_id": 0}
258
+ ticker_full = self.collection.find_one(query, filter_query)
259
+
260
+ if not ticker_full:
261
+ raise ValueError("No ticker found in database")
262
+
263
+ daily_data = ticker_full.get("daily_data", [])
264
+ if not isinstance(daily_data, list):
265
+ raise TypeError("Expected 'daily_data' to be a list.")
266
+
267
+ df = pd.DataFrame(daily_data)
268
+
269
+ if not self.has_required_columns(df, required_cols):
270
+ missing_cols = [col for col in required_cols if col not in df.columns]
271
+ missing_cols = ",".join(missing_cols)
272
+ for col in missing_cols:
273
+ df[col] = pd.NA
274
+ # raise KeyError(f"Missing required columns")
275
+
276
+ return df[required_cols]
277
+
185
278
 
186
279
  class TechProcessor:
187
280
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neurostats_API
3
- Version: 0.0.22
3
+ Version: 0.0.23b0
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -89,7 +89,7 @@ pip install neurostats-API
89
89
  ```Python
90
90
  >>> import neurostats_API
91
91
  >>> print(neurostats_API.__version__)
92
- 0.0.22
92
+ 0.0.23b
93
93
  ```
94
94
 
95
95
  ### 得到最新一期的評價資料與歷年評價
@@ -1,4 +1,4 @@
1
- neurostats_API/__init__.py,sha256=bOEodI1kq0xK8AR_160U9DasXGcjCEZHi7BQGh6Ib-4,288
1
+ neurostats_API/__init__.py,sha256=ItIYqBMTp2EHBeBahEWCKKGa-JIzQO2ykdQy3A-LNZY,289
2
2
  neurostats_API/cli.py,sha256=UJSWLIw03P24p-gkBb6JSEI5dW5U12UvLf1L8HjQD-o,873
3
3
  neurostats_API/main.py,sha256=QcsfmWivg2Dnqw3MTJWiI0QvEiRs0VuH-BjwQHFCv00,677
4
4
  neurostats_API/fetchers/__init__.py,sha256=KCw-yRSDFa3fw83u73LJ9OVop7gRl_YQYlQq-cITxuo,511
@@ -10,7 +10,7 @@ neurostats_API/fetchers/institution.py,sha256=UrcBc6t7u7CnEwUsf6YmLbbJ8VncdWpq8b
10
10
  neurostats_API/fetchers/margin_trading.py,sha256=lQImtNdvaBoSlKhJvQ3DkH3HjSSgKRJz4ZZpyR5-Z4I,10433
11
11
  neurostats_API/fetchers/month_revenue.py,sha256=DZeOblfSz7NhQXVvL5xfMHZ1rv2B8pgqu-U-o_gcAuc,6323
12
12
  neurostats_API/fetchers/profit_lose.py,sha256=ZvSG4vx4gBrWMKmcyuSaoNyW6JGiOtIpFxRIeyCAeDY,7705
13
- neurostats_API/fetchers/tech.py,sha256=AyxdOjStVJIPFTVcofVOJknXPpv_D9dqkFPjEFXo6iY,14937
13
+ neurostats_API/fetchers/tech.py,sha256=LvgWhcHdruTGJE_1_z8rrArJs3s7X5AbE3LtuR4zwIM,18051
14
14
  neurostats_API/fetchers/tej_finance_report.py,sha256=5ERpg1kq2wSPdLMBYXX5MUWRxOrwwFHSBXNidSKeuRo,11233
15
15
  neurostats_API/fetchers/value_invest.py,sha256=b_x2Dpgs8VBU5HdG8ocKtfIEkqhU-Q0S5n6RxuFuM2g,7467
16
16
  neurostats_API/tools/company_list/tw.json,sha256=VWaDFvd0ACCVSWItcHHpmVuM_RzP71jLZl9RBHztu-0,51332
@@ -28,7 +28,7 @@ neurostats_API/utils/calculate_value.py,sha256=Zc5DG_qXnHZLkCjUYdoMWka3KVXu2o9Am
28
28
  neurostats_API/utils/data_process.py,sha256=LdDmhQMGBg1UI6cIWCdsj9YTkixtf1cyrN1xq2JZmPo,9971
29
29
  neurostats_API/utils/datetime.py,sha256=XJya4G8b_-ZOaBbMXgQjWh2MC4wc-o6goQ7EQJQMWrQ,773
30
30
  neurostats_API/utils/db_client.py,sha256=OYe6yazcR4Aa6jYmy47JrryUeh2NnKGqY2K_lSZe6i8,455
31
- neurostats_API-0.0.22.dist-info/METADATA,sha256=yLp6sTftp5SaxhXZxtLfE7Fvd7OmtZYd3XjwyR4yoG4,31618
32
- neurostats_API-0.0.22.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
33
- neurostats_API-0.0.22.dist-info/top_level.txt,sha256=nSlQPMG0VtXivJyedp4Bkf86EOy2TpW10VGxolXrqnU,15
34
- neurostats_API-0.0.22.dist-info/RECORD,,
31
+ neurostats_API-0.0.23b0.dist-info/METADATA,sha256=433KG3-zXJJeDPaZcmxBBIsamFrZziYqmGNoNG-Oz5E,31621
32
+ neurostats_API-0.0.23b0.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
33
+ neurostats_API-0.0.23b0.dist-info/top_level.txt,sha256=nSlQPMG0VtXivJyedp4Bkf86EOy2TpW10VGxolXrqnU,15
34
+ neurostats_API-0.0.23b0.dist-info/RECORD,,