lib-x17-fintech 2.1.3__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.
- lib_x17_fintech-2.1.3.dist-info/METADATA +633 -0
- lib_x17_fintech-2.1.3.dist-info/RECORD +282 -0
- lib_x17_fintech-2.1.3.dist-info/WHEEL +5 -0
- lib_x17_fintech-2.1.3.dist-info/licenses/LICENSE +1 -0
- lib_x17_fintech-2.1.3.dist-info/top_level.txt +1 -0
- xfintech/__init__.py +0 -0
- xfintech/connect/__init__.py +18 -0
- xfintech/connect/artifact/__init__.py +5 -0
- xfintech/connect/artifact/artifact.py +168 -0
- xfintech/connect/artifact/tests/__init__.py +3 -0
- xfintech/connect/artifact/tests/test_class_artifact_all.py +564 -0
- xfintech/connect/common/__init__.py +12 -0
- xfintech/connect/common/connect.py +49 -0
- xfintech/connect/common/connectref.py +119 -0
- xfintech/connect/common/error.py +62 -0
- xfintech/connect/common/tests/__init__.py +1 -0
- xfintech/connect/common/tests/test_class_connectlike_all.py +544 -0
- xfintech/connect/common/tests/test_class_connectref_all.py +586 -0
- xfintech/connect/common/tests/test_class_errors_all.py +524 -0
- xfintech/connect/instance/__init__.py +7 -0
- xfintech/connect/instance/macos.py +121 -0
- xfintech/connect/instance/s3.py +176 -0
- xfintech/connect/instance/tests/__init__.py +1 -0
- xfintech/connect/instance/tests/test_class_macosconnect_all.py +692 -0
- xfintech/connect/instance/tests/test_class_s3connect_all.py +603 -0
- xfintech/data/__init__.py +20 -0
- xfintech/data/common/__init__.py +15 -0
- xfintech/data/common/cache.py +186 -0
- xfintech/data/common/coolant.py +171 -0
- xfintech/data/common/metric.py +138 -0
- xfintech/data/common/paginate.py +132 -0
- xfintech/data/common/params.py +162 -0
- xfintech/data/common/retry.py +201 -0
- xfintech/data/common/tests/__init__.py +1 -0
- xfintech/data/common/tests/test_class_cache_all.py +681 -0
- xfintech/data/common/tests/test_class_coolant_all.py +534 -0
- xfintech/data/common/tests/test_class_metric_all.py +705 -0
- xfintech/data/common/tests/test_class_paginate_all.py +508 -0
- xfintech/data/common/tests/test_class_params_all.py +891 -0
- xfintech/data/common/tests/test_class_retry_all.py +714 -0
- xfintech/data/job/__init__.py +17 -0
- xfintech/data/job/errors.py +112 -0
- xfintech/data/job/house.py +156 -0
- xfintech/data/job/job.py +247 -0
- xfintech/data/job/joblike.py +47 -0
- xfintech/data/job/tests/__init__.py +1 -0
- xfintech/data/job/tests/test_class_errors_all.py +275 -0
- xfintech/data/job/tests/test_class_house_all.py +801 -0
- xfintech/data/job/tests/test_class_job_all.py +684 -0
- xfintech/data/job/tests/test_class_joblike_all.py +482 -0
- xfintech/data/relay/__init__.py +7 -0
- xfintech/data/relay/client.py +114 -0
- xfintech/data/relay/clientlike.py +45 -0
- xfintech/data/relay/tests/test_class_relayclient_all.py +484 -0
- xfintech/data/relay/tests/test_class_relayclientlike_all.py +500 -0
- xfintech/data/source/__init__.py +7 -0
- xfintech/data/source/baostock/__init__.py +21 -0
- xfintech/data/source/baostock/job/__init__.py +5 -0
- xfintech/data/source/baostock/job/job.py +217 -0
- xfintech/data/source/baostock/job/tests/__init__.py +0 -0
- xfintech/data/source/baostock/job/tests/test_class_baostockjob_all.py +547 -0
- xfintech/data/source/baostock/session/__init__.py +8 -0
- xfintech/data/source/baostock/session/relay.py +223 -0
- xfintech/data/source/baostock/session/session.py +241 -0
- xfintech/data/source/baostock/session/tests/__init__.py +0 -0
- xfintech/data/source/baostock/session/tests/test_class_relay_all.py +694 -0
- xfintech/data/source/baostock/session/tests/test_class_session_all.py +505 -0
- xfintech/data/source/baostock/stock/__init__.py +0 -0
- xfintech/data/source/baostock/stock/hs300stock/__init__.py +3 -0
- xfintech/data/source/baostock/stock/hs300stock/constant.py +49 -0
- xfintech/data/source/baostock/stock/hs300stock/hs300stock.py +133 -0
- xfintech/data/source/baostock/stock/hs300stock/tests/__init__.py +1 -0
- xfintech/data/source/baostock/stock/hs300stock/tests/test_class_hs300index_all.py +413 -0
- xfintech/data/source/baostock/stock/minuteline/__init__.py +19 -0
- xfintech/data/source/baostock/stock/minuteline/constant.py +89 -0
- xfintech/data/source/baostock/stock/minuteline/minuteline.py +163 -0
- xfintech/data/source/baostock/stock/minuteline/tests/__init__.py +0 -0
- xfintech/data/source/baostock/stock/minuteline/tests/test_class_minuteline_all.py +582 -0
- xfintech/data/source/baostock/stock/stock/__init__.py +19 -0
- xfintech/data/source/baostock/stock/stock/constant.py +55 -0
- xfintech/data/source/baostock/stock/stock/stock.py +149 -0
- xfintech/data/source/baostock/stock/stock/tests/__init__.py +0 -0
- xfintech/data/source/baostock/stock/stock/tests/test_class_stock_all.py +508 -0
- xfintech/data/source/baostock/stock/stockinfo/__init__.py +5 -0
- xfintech/data/source/baostock/stock/stockinfo/constant.py +66 -0
- xfintech/data/source/baostock/stock/stockinfo/stockinfo.py +176 -0
- xfintech/data/source/baostock/stock/stockinfo/tests/__init__.py +1 -0
- xfintech/data/source/baostock/stock/stockinfo/tests/test_class_stockinfo_all.py +617 -0
- xfintech/data/source/baostock/stock/sz50stock/__init__.py +3 -0
- xfintech/data/source/baostock/stock/sz50stock/constant.py +49 -0
- xfintech/data/source/baostock/stock/sz50stock/sz50stock.py +133 -0
- xfintech/data/source/baostock/stock/sz50stock/tests/__init__.py +1 -0
- xfintech/data/source/baostock/stock/sz50stock/tests/test_class_sz50stock_all.py +397 -0
- xfintech/data/source/baostock/stock/tradedate/__init__.py +19 -0
- xfintech/data/source/baostock/stock/tradedate/constant.py +72 -0
- xfintech/data/source/baostock/stock/tradedate/tests/__init__.py +0 -0
- xfintech/data/source/baostock/stock/tradedate/tests/test_class_tradedate_all.py +695 -0
- xfintech/data/source/baostock/stock/tradedate/tradedate.py +208 -0
- xfintech/data/source/baostock/stock/zz500stock/__init__.py +3 -0
- xfintech/data/source/baostock/stock/zz500stock/constant.py +55 -0
- xfintech/data/source/baostock/stock/zz500stock/tests/__init__.py +1 -0
- xfintech/data/source/baostock/stock/zz500stock/tests/test_class_zz500stock_all.py +421 -0
- xfintech/data/source/baostock/stock/zz500stock/zz500stock.py +133 -0
- xfintech/data/source/tushare/__init__.py +61 -0
- xfintech/data/source/tushare/job/__init__.py +5 -0
- xfintech/data/source/tushare/job/job.py +257 -0
- xfintech/data/source/tushare/job/tests/test_class_tusharejob_all.py +589 -0
- xfintech/data/source/tushare/session/__init__.py +5 -0
- xfintech/data/source/tushare/session/relay.py +231 -0
- xfintech/data/source/tushare/session/session.py +239 -0
- xfintech/data/source/tushare/session/tests/test_class_relay_all.py +719 -0
- xfintech/data/source/tushare/session/tests/test_class_session_all.py +705 -0
- xfintech/data/source/tushare/stock/__init__.py +55 -0
- xfintech/data/source/tushare/stock/adjfactor/__init__.py +19 -0
- xfintech/data/source/tushare/stock/adjfactor/adjfactor.py +150 -0
- xfintech/data/source/tushare/stock/adjfactor/constant.py +71 -0
- xfintech/data/source/tushare/stock/adjfactor/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/adjfactor/tests/test_class_adjfactor_all.py +372 -0
- xfintech/data/source/tushare/stock/capflow/__init__.py +19 -0
- xfintech/data/source/tushare/stock/capflow/capflow.py +171 -0
- xfintech/data/source/tushare/stock/capflow/constant.py +105 -0
- xfintech/data/source/tushare/stock/capflow/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/capflow/tests/test_class_capflow_all.py +589 -0
- xfintech/data/source/tushare/stock/capflowdc/__init__.py +19 -0
- xfintech/data/source/tushare/stock/capflowdc/capflowdc.py +167 -0
- xfintech/data/source/tushare/stock/capflowdc/constant.py +95 -0
- xfintech/data/source/tushare/stock/capflowdc/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/capflowdc/tests/test_class_capflowdc_all.py +814 -0
- xfintech/data/source/tushare/stock/capflowths/__init__.py +19 -0
- xfintech/data/source/tushare/stock/capflowths/capflowths.py +173 -0
- xfintech/data/source/tushare/stock/capflowths/constant.py +92 -0
- xfintech/data/source/tushare/stock/capflowths/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/capflowths/tests/test_class_capflowths_all.py +551 -0
- xfintech/data/source/tushare/stock/company/__init__.py +19 -0
- xfintech/data/source/tushare/stock/company/company.py +188 -0
- xfintech/data/source/tushare/stock/company/constant.py +92 -0
- xfintech/data/source/tushare/stock/company/tests/__init__.py +1 -0
- xfintech/data/source/tushare/stock/company/tests/test_class_company_all.py +829 -0
- xfintech/data/source/tushare/stock/companybusiness/__init__.py +21 -0
- xfintech/data/source/tushare/stock/companybusiness/companybusiness.py +183 -0
- xfintech/data/source/tushare/stock/companybusiness/constant.py +91 -0
- xfintech/data/source/tushare/stock/companybusiness/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/companybusiness/tests/test_class_companybusiness_all.py +633 -0
- xfintech/data/source/tushare/stock/companycashflow/__init__.py +21 -0
- xfintech/data/source/tushare/stock/companycashflow/companycashflow.py +277 -0
- xfintech/data/source/tushare/stock/companycashflow/constant.py +293 -0
- xfintech/data/source/tushare/stock/companycashflow/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/companycashflow/tests/test_class_companycashflow_all.py +619 -0
- xfintech/data/source/tushare/stock/companydebt/__init__.py +19 -0
- xfintech/data/source/tushare/stock/companydebt/companydebt.py +339 -0
- xfintech/data/source/tushare/stock/companydebt/constant.py +403 -0
- xfintech/data/source/tushare/stock/companydebt/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/companydebt/tests/test_class_companydebt_all.py +655 -0
- xfintech/data/source/tushare/stock/companyoverview/__init__.py +21 -0
- xfintech/data/source/tushare/stock/companyoverview/companyoverview.py +214 -0
- xfintech/data/source/tushare/stock/companyoverview/constant.py +152 -0
- xfintech/data/source/tushare/stock/companyoverview/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/companyoverview/tests/test_class_companyoverview_all.py +647 -0
- xfintech/data/source/tushare/stock/companyprofit/__init__.py +21 -0
- xfintech/data/source/tushare/stock/companyprofit/companyprofit.py +272 -0
- xfintech/data/source/tushare/stock/companyprofit/constant.py +259 -0
- xfintech/data/source/tushare/stock/companyprofit/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/companyprofit/tests/test_class_companyprofit_all.py +635 -0
- xfintech/data/source/tushare/stock/conceptcapflowdc/__init__.py +21 -0
- xfintech/data/source/tushare/stock/conceptcapflowdc/conceptcapflowdc.py +175 -0
- xfintech/data/source/tushare/stock/conceptcapflowdc/constant.py +106 -0
- xfintech/data/source/tushare/stock/conceptcapflowdc/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/conceptcapflowdc/tests/test_class_conceptcapflowdc_all.py +568 -0
- xfintech/data/source/tushare/stock/conceptcapflowths/__init__.py +21 -0
- xfintech/data/source/tushare/stock/conceptcapflowths/conceptcapflowths.py +188 -0
- xfintech/data/source/tushare/stock/conceptcapflowths/constant.py +89 -0
- xfintech/data/source/tushare/stock/conceptcapflowths/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/conceptcapflowths/tests/test_class_conceptcapflowths_all.py +516 -0
- xfintech/data/source/tushare/stock/dayline/__init__.py +19 -0
- xfintech/data/source/tushare/stock/dayline/constant.py +87 -0
- xfintech/data/source/tushare/stock/dayline/dayline.py +177 -0
- xfintech/data/source/tushare/stock/dayline/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/dayline/tests/test_class_dayline_all.py +585 -0
- xfintech/data/source/tushare/stock/industrycapflowths/__init__.py +21 -0
- xfintech/data/source/tushare/stock/industrycapflowths/constant.py +89 -0
- xfintech/data/source/tushare/stock/industrycapflowths/industrycapflowths.py +192 -0
- xfintech/data/source/tushare/stock/industrycapflowths/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/industrycapflowths/tests/test_class_industrycapflowths_all.py +683 -0
- xfintech/data/source/tushare/stock/marketindexcapflowdc/__init__.py +21 -0
- xfintech/data/source/tushare/stock/marketindexcapflowdc/constant.py +90 -0
- xfintech/data/source/tushare/stock/marketindexcapflowdc/marketindexcapflowdc.py +173 -0
- xfintech/data/source/tushare/stock/marketindexcapflowdc/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/marketindexcapflowdc/tests/test_class_marketindexcapflowdc_all.py +793 -0
- xfintech/data/source/tushare/stock/monthline/__init__.py +19 -0
- xfintech/data/source/tushare/stock/monthline/constant.py +87 -0
- xfintech/data/source/tushare/stock/monthline/monthline.py +180 -0
- xfintech/data/source/tushare/stock/monthline/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/monthline/tests/test_class_monthline_all.py +574 -0
- xfintech/data/source/tushare/stock/stock/__init__.py +19 -0
- xfintech/data/source/tushare/stock/stock/constant.py +105 -0
- xfintech/data/source/tushare/stock/stock/stock.py +193 -0
- xfintech/data/source/tushare/stock/stock/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stock/tests/test_class_stock_all.py +788 -0
- xfintech/data/source/tushare/stock/stockdividend/__init__.py +21 -0
- xfintech/data/source/tushare/stock/stockdividend/constant.py +111 -0
- xfintech/data/source/tushare/stock/stockdividend/stockdividend.py +180 -0
- xfintech/data/source/tushare/stock/stockdividend/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stockdividend/tests/test_class_stockdividend_all.py +725 -0
- xfintech/data/source/tushare/stock/stockinfo/__init__.py +19 -0
- xfintech/data/source/tushare/stock/stockinfo/constant.py +104 -0
- xfintech/data/source/tushare/stock/stockinfo/stockinfo.py +208 -0
- xfintech/data/source/tushare/stock/stockinfo/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stockinfo/tests/test_class_stockinfo_all.py +881 -0
- xfintech/data/source/tushare/stock/stockipo/__init__.py +19 -0
- xfintech/data/source/tushare/stock/stockipo/constant.py +90 -0
- xfintech/data/source/tushare/stock/stockipo/stockipo.py +234 -0
- xfintech/data/source/tushare/stock/stockipo/tests/__init__.py +1 -0
- xfintech/data/source/tushare/stock/stockipo/tests/test_class_stockipo_all.py +750 -0
- xfintech/data/source/tushare/stock/stockpledge/__init__.py +19 -0
- xfintech/data/source/tushare/stock/stockpledge/constant.py +72 -0
- xfintech/data/source/tushare/stock/stockpledge/stockpledge.py +158 -0
- xfintech/data/source/tushare/stock/stockpledge/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stockpledge/tests/test_class_stockpledge_all.py +664 -0
- xfintech/data/source/tushare/stock/stockpledgedetail/__init__.py +21 -0
- xfintech/data/source/tushare/stock/stockpledgedetail/constant.py +85 -0
- xfintech/data/source/tushare/stock/stockpledgedetail/stockpledgedetail.py +171 -0
- xfintech/data/source/tushare/stock/stockpledgedetail/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stockpledgedetail/tests/test_class_stockpledgedetail_all.py +112 -0
- xfintech/data/source/tushare/stock/stockst/__init__.py +19 -0
- xfintech/data/source/tushare/stock/stockst/constant.py +80 -0
- xfintech/data/source/tushare/stock/stockst/stockst.py +189 -0
- xfintech/data/source/tushare/stock/stockst/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stockst/tests/test_class_stockst_all.py +693 -0
- xfintech/data/source/tushare/stock/stocksuspend/__init__.py +21 -0
- xfintech/data/source/tushare/stock/stocksuspend/constant.py +75 -0
- xfintech/data/source/tushare/stock/stocksuspend/stocksuspend.py +151 -0
- xfintech/data/source/tushare/stock/stocksuspend/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stocksuspend/tests/test_class_stocksuspend_all.py +626 -0
- xfintech/data/source/tushare/stock/techindex/__init__.py +19 -0
- xfintech/data/source/tushare/stock/techindex/constant.py +600 -0
- xfintech/data/source/tushare/stock/techindex/techindex.py +314 -0
- xfintech/data/source/tushare/stock/techindex/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/techindex/tests/test_class_techindex_all.py +576 -0
- xfintech/data/source/tushare/stock/tradedate/__init__.py +19 -0
- xfintech/data/source/tushare/stock/tradedate/constant.py +93 -0
- xfintech/data/source/tushare/stock/tradedate/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/tradedate/tests/test_class_tradedate_all.py +947 -0
- xfintech/data/source/tushare/stock/tradedate/tradedate.py +234 -0
- xfintech/data/source/tushare/stock/weekline/__init__.py +19 -0
- xfintech/data/source/tushare/stock/weekline/constant.py +87 -0
- xfintech/data/source/tushare/stock/weekline/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/weekline/tests/test_class_weekline_all.py +575 -0
- xfintech/data/source/tushare/stock/weekline/weekline.py +182 -0
- xfintech/fabric/__init__.py +18 -0
- xfintech/fabric/column/__init__.py +7 -0
- xfintech/fabric/column/info.py +202 -0
- xfintech/fabric/column/kind.py +102 -0
- xfintech/fabric/column/tests/__init__.py +0 -0
- xfintech/fabric/column/tests/test_class_info_all.py +207 -0
- xfintech/fabric/column/tests/test_class_kind_all.py +80 -0
- xfintech/fabric/table/__init__.py +5 -0
- xfintech/fabric/table/info.py +263 -0
- xfintech/fabric/table/tests/__init__.py +0 -0
- xfintech/fabric/table/tests/test_class_info_all.py +547 -0
- xfintech/serde/__init__.py +35 -0
- xfintech/serde/common/__init__.py +9 -0
- xfintech/serde/common/dataformat.py +78 -0
- xfintech/serde/common/deserialiserlike.py +38 -0
- xfintech/serde/common/error.py +182 -0
- xfintech/serde/common/serialiserlike.py +38 -0
- xfintech/serde/common/tests/__init__.py +1 -0
- xfintech/serde/common/tests/test_class_dataformat_all.py +694 -0
- xfintech/serde/common/tests/test_class_deserialiserlike_all.py +500 -0
- xfintech/serde/common/tests/test_class_errors_all.py +518 -0
- xfintech/serde/common/tests/test_class_serialiserlike_all.py +401 -0
- xfintech/serde/deserialiser/__init__.py +7 -0
- xfintech/serde/deserialiser/pandas.py +113 -0
- xfintech/serde/deserialiser/python.py +68 -0
- xfintech/serde/deserialiser/tests/__init__.py +1 -0
- xfintech/serde/deserialiser/tests/test_class_pandasdeserialiser_all.py +503 -0
- xfintech/serde/deserialiser/tests/test_class_pythondeserialiser_all.py +570 -0
- xfintech/serde/serialiser/__init__.py +7 -0
- xfintech/serde/serialiser/pandas.py +116 -0
- xfintech/serde/serialiser/python.py +71 -0
- xfintech/serde/serialiser/tests/__init__.py +1 -0
- xfintech/serde/serialiser/tests/test_class_pandasserialiser_all.py +474 -0
- xfintech/serde/serialiser/tests/test_class_pythonserialiser_all.py +508 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from xfintech.data.common.cache import Cache
|
|
8
|
+
from xfintech.data.common.coolant import Coolant
|
|
9
|
+
from xfintech.data.common.params import Params
|
|
10
|
+
from xfintech.data.common.retry import Retry
|
|
11
|
+
from xfintech.data.job import JobHouse
|
|
12
|
+
from xfintech.data.source.baostock.job import BaostockJob
|
|
13
|
+
from xfintech.data.source.baostock.session.session import Session
|
|
14
|
+
from xfintech.data.source.baostock.stock.zz500stock.constant import (
|
|
15
|
+
KEY,
|
|
16
|
+
NAME,
|
|
17
|
+
PAGINATE,
|
|
18
|
+
SOURCE,
|
|
19
|
+
TARGET,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@JobHouse.register(KEY, alias=KEY)
|
|
24
|
+
class ZZ500Stock(BaostockJob):
|
|
25
|
+
"""
|
|
26
|
+
描述:
|
|
27
|
+
- 获取中证500成分股
|
|
28
|
+
- 返回中证500指数的500只成份股信息
|
|
29
|
+
- 每周一更新
|
|
30
|
+
- API文档: http://www.baostock.com/mainContent?file=zz500Stock.md
|
|
31
|
+
- SCALE: CrossSection
|
|
32
|
+
- TYPE: Static
|
|
33
|
+
- PAGINATE: 10000 rows / 100 pages
|
|
34
|
+
|
|
35
|
+
属性:
|
|
36
|
+
- name: str, 作业名称 'zz500stock'。
|
|
37
|
+
- key: str, 作业键 '/baostock/zz500stock'。
|
|
38
|
+
- session: Session, Baostock会话对象。
|
|
39
|
+
- source: TableInfo, 源表信息(BaoStock原始格式)。
|
|
40
|
+
- target: TableInfo, 目标表信息(xfintech格式)。
|
|
41
|
+
- params: Params, 查询参数(此API无需参数)。
|
|
42
|
+
- coolant: Coolant, 请求冷却控制。
|
|
43
|
+
- paginate: Paginate, 分页控制(pagesize=10000, pagelimit=100)。
|
|
44
|
+
- retry: Retry, 重试策略。
|
|
45
|
+
- cache: Cache, 缓存管理。
|
|
46
|
+
|
|
47
|
+
方法:
|
|
48
|
+
- run(): 执行作业,返回中证500成分股DataFrame。
|
|
49
|
+
- _run(): 内部执行逻辑,处理参数并调用API。
|
|
50
|
+
- transform(data): 转换数据格式,将源格式转为目标格式。
|
|
51
|
+
- list_codes(): 返回所有股票代码列表。
|
|
52
|
+
- list_names(): 返回所有股票名称列表。
|
|
53
|
+
|
|
54
|
+
例子:
|
|
55
|
+
```python
|
|
56
|
+
from xfintech.data.source.baostock.session import Session
|
|
57
|
+
from xfintech.data.source.baostock.stock.zz500stock import ZZ500Stock
|
|
58
|
+
|
|
59
|
+
session = Session()
|
|
60
|
+
|
|
61
|
+
# 获取中证500成分股
|
|
62
|
+
job = ZZ500Stock(session=session)
|
|
63
|
+
df = job.run()
|
|
64
|
+
|
|
65
|
+
# 获取代码列表
|
|
66
|
+
codes = job.list_codes()
|
|
67
|
+
```
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
def __init__(
|
|
71
|
+
self,
|
|
72
|
+
session: Session,
|
|
73
|
+
params: Optional[Params | Dict[str, Any]] = None,
|
|
74
|
+
coolant: Optional[Coolant | Dict[str, Any]] = None,
|
|
75
|
+
retry: Optional[Retry | Dict[str, Any]] = None,
|
|
76
|
+
cache: Optional[Cache | Dict[str, str] | bool] = None,
|
|
77
|
+
) -> None:
|
|
78
|
+
super().__init__(
|
|
79
|
+
name=NAME,
|
|
80
|
+
key=KEY,
|
|
81
|
+
session=session,
|
|
82
|
+
source=SOURCE,
|
|
83
|
+
target=TARGET,
|
|
84
|
+
params=params,
|
|
85
|
+
coolant=coolant,
|
|
86
|
+
paginate=PAGINATE,
|
|
87
|
+
retry=retry,
|
|
88
|
+
cache=cache,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def _run(self) -> pd.DataFrame:
|
|
92
|
+
cached = self._load_cache()
|
|
93
|
+
if cached is not None:
|
|
94
|
+
return cached
|
|
95
|
+
|
|
96
|
+
payload = self.params.to_dict()
|
|
97
|
+
payload = self._parse_date_params(payload, keys=["date"])
|
|
98
|
+
# Fetch data from API
|
|
99
|
+
data = self._fetchall(
|
|
100
|
+
api=self.connection.query_zz500_stocks,
|
|
101
|
+
**payload,
|
|
102
|
+
)
|
|
103
|
+
result = self.transform(data)
|
|
104
|
+
self._save_cache(result)
|
|
105
|
+
return result
|
|
106
|
+
|
|
107
|
+
def transform(
|
|
108
|
+
self,
|
|
109
|
+
data: pd.DataFrame,
|
|
110
|
+
) -> pd.DataFrame:
|
|
111
|
+
cols = self.target.list_column_names()
|
|
112
|
+
if data is None or data.empty:
|
|
113
|
+
return pd.DataFrame(columns=cols)
|
|
114
|
+
|
|
115
|
+
out = data.copy()
|
|
116
|
+
out["update_date"] = out["updateDate"].astype(str)
|
|
117
|
+
out["code"] = out["code"].astype(str)
|
|
118
|
+
out["name"] = out["code_name"].astype(str)
|
|
119
|
+
|
|
120
|
+
# Finalize output
|
|
121
|
+
out = out[cols].drop_duplicates()
|
|
122
|
+
out = out.sort_values(by=["code"])
|
|
123
|
+
out = out.reset_index(drop=True)
|
|
124
|
+
self.markpoint("transform[OK]")
|
|
125
|
+
return out
|
|
126
|
+
|
|
127
|
+
def list_codes(self) -> List[str]:
|
|
128
|
+
df = self.run()
|
|
129
|
+
return sorted(df["code"].unique().tolist())
|
|
130
|
+
|
|
131
|
+
def list_names(self) -> List[str]:
|
|
132
|
+
df = self.run()
|
|
133
|
+
return sorted(df["name"].unique().tolist())
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .session.session import Session
|
|
4
|
+
from .stock.adjfactor.adjfactor import AdjFactor
|
|
5
|
+
from .stock.capflow.capflow import Capflow
|
|
6
|
+
from .stock.capflowdc.capflowdc import CapflowDC
|
|
7
|
+
from .stock.capflowths.capflowths import CapflowTHS
|
|
8
|
+
from .stock.company.company import Company
|
|
9
|
+
from .stock.companybusiness.companybusiness import CompanyBusiness
|
|
10
|
+
from .stock.companycashflow.companycashflow import CompanyCashflow
|
|
11
|
+
from .stock.companydebt.companydebt import CompanyDebt
|
|
12
|
+
from .stock.companyoverview.companyoverview import CompanyOverview
|
|
13
|
+
from .stock.companyprofit.companyprofit import CompanyProfit
|
|
14
|
+
from .stock.conceptcapflowdc.conceptcapflowdc import ConceptCapflowDC
|
|
15
|
+
from .stock.conceptcapflowths.conceptcapflowths import ConceptCapflowTHS
|
|
16
|
+
from .stock.dayline.dayline import Dayline
|
|
17
|
+
from .stock.industrycapflowths.industrycapflowths import IndustryCapflowTHS
|
|
18
|
+
from .stock.marketindexcapflowdc.marketindexcapflowdc import MarketIndexCapflowDC
|
|
19
|
+
from .stock.monthline.monthline import Monthline
|
|
20
|
+
from .stock.stock.stock import Stock
|
|
21
|
+
from .stock.stockdividend.stockdividend import StockDividend
|
|
22
|
+
from .stock.stockinfo.stockinfo import StockInfo
|
|
23
|
+
from .stock.stockipo.stockipo import StockIpo
|
|
24
|
+
from .stock.stockpledge.stockpledge import StockPledge
|
|
25
|
+
from .stock.stockpledgedetail.stockpledgedetail import StockPledgeDetail
|
|
26
|
+
from .stock.stockst.stockst import StockSt
|
|
27
|
+
from .stock.stocksuspend.stocksuspend import StockSuspend
|
|
28
|
+
from .stock.techindex.techindex import TechIndex
|
|
29
|
+
from .stock.tradedate.tradedate import TradeDate
|
|
30
|
+
from .stock.weekline.weekline import Weekline
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"Session",
|
|
34
|
+
"AdjFactor",
|
|
35
|
+
"Capflow",
|
|
36
|
+
"CapflowDC",
|
|
37
|
+
"CapflowTHS",
|
|
38
|
+
"Company",
|
|
39
|
+
"CompanyBusiness",
|
|
40
|
+
"CompanyCashflow",
|
|
41
|
+
"CompanyDebt",
|
|
42
|
+
"CompanyOverview",
|
|
43
|
+
"CompanyProfit",
|
|
44
|
+
"MarketIndexCapflowDC",
|
|
45
|
+
"ConceptCapflowDC",
|
|
46
|
+
"Dayline",
|
|
47
|
+
"Weekline",
|
|
48
|
+
"Monthline",
|
|
49
|
+
"TradeDate",
|
|
50
|
+
"TechIndex",
|
|
51
|
+
"ConceptCapflowTHS",
|
|
52
|
+
"IndustryCapflowTHS",
|
|
53
|
+
"Stock",
|
|
54
|
+
"StockSuspend",
|
|
55
|
+
"StockPledge",
|
|
56
|
+
"StockPledgeDetail",
|
|
57
|
+
"StockSt",
|
|
58
|
+
"StockIpo",
|
|
59
|
+
"StockInfo",
|
|
60
|
+
"StockDividend",
|
|
61
|
+
]
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import date, datetime
|
|
4
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
5
|
+
|
|
6
|
+
import pandas as pd
|
|
7
|
+
|
|
8
|
+
from xfintech.data.common.cache import Cache
|
|
9
|
+
from xfintech.data.common.coolant import Coolant
|
|
10
|
+
from xfintech.data.common.paginate import Paginate
|
|
11
|
+
from xfintech.data.common.params import Params
|
|
12
|
+
from xfintech.data.common.retry import Retry
|
|
13
|
+
from xfintech.data.job.job import Job
|
|
14
|
+
from xfintech.data.source.tushare.session.session import Session
|
|
15
|
+
from xfintech.fabric.table.info import TableInfo
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TushareJob(Job):
|
|
19
|
+
"""
|
|
20
|
+
描述:
|
|
21
|
+
- Tushare 数据源作业类,继承自 Job 基类。
|
|
22
|
+
- 专门用于从 Tushare API 获取金融数据。
|
|
23
|
+
- 自动处理连接管理、分页获取、重试和缓存等功能。
|
|
24
|
+
- 支持批量数据获取并自动合并为 DataFrame。
|
|
25
|
+
|
|
26
|
+
属性:
|
|
27
|
+
- connection: Any, Tushare API 连接对象,从 session 中获取。
|
|
28
|
+
- 继承 Job 类的所有属性(name, key, params, coolant, paginate, retry, cache, metric)。
|
|
29
|
+
|
|
30
|
+
方法:
|
|
31
|
+
- _resolve_connection(session): 从 session 解析并验证连接对象。
|
|
32
|
+
- _fetchall(api, **params): 分页获取所有数据并合并为 DataFrame。
|
|
33
|
+
|
|
34
|
+
例子:
|
|
35
|
+
```python
|
|
36
|
+
from xfintech.data.source.tushare.job import TushareJob
|
|
37
|
+
from xfintech.data.source.tushare.session import Session
|
|
38
|
+
|
|
39
|
+
# 创建 session
|
|
40
|
+
session = Session(credential="your_token")
|
|
41
|
+
|
|
42
|
+
# 创建作业
|
|
43
|
+
job = TushareJob(
|
|
44
|
+
name="stock_basic",
|
|
45
|
+
key="stock_basic_001",
|
|
46
|
+
session=session,
|
|
47
|
+
params={"exchange": "SSE"},
|
|
48
|
+
paginate={"pagesize": 1000, "pagelimit": 10},
|
|
49
|
+
retry={"retry": 3, "wait": 1},
|
|
50
|
+
cache=True
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# 在子类中实现 _run 方法来调用 _fetchall
|
|
54
|
+
class StockBasicJob(TushareJob):
|
|
55
|
+
def _run(self):
|
|
56
|
+
return self._fetchall(
|
|
57
|
+
api=self.connection.stock_basic,
|
|
58
|
+
**self.get_params()
|
|
59
|
+
)
|
|
60
|
+
```
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def __init__(
|
|
64
|
+
self,
|
|
65
|
+
name: str,
|
|
66
|
+
key: str,
|
|
67
|
+
session: Session,
|
|
68
|
+
source: Optional[TableInfo] = None,
|
|
69
|
+
target: Optional[TableInfo] = None,
|
|
70
|
+
params: Optional[Params | Dict[str, Any]] = None,
|
|
71
|
+
coolant: Optional[Coolant | Dict[str, Any]] = None,
|
|
72
|
+
paginate: Optional[Paginate | Dict[str, Any]] = None,
|
|
73
|
+
retry: Optional[Retry | Dict[str, Any]] = None,
|
|
74
|
+
cache: Optional[Cache | Dict[str, str] | bool] = None,
|
|
75
|
+
) -> None:
|
|
76
|
+
super().__init__(
|
|
77
|
+
name=name,
|
|
78
|
+
key=key,
|
|
79
|
+
source=source,
|
|
80
|
+
target=target,
|
|
81
|
+
params=params,
|
|
82
|
+
coolant=coolant,
|
|
83
|
+
paginate=paginate,
|
|
84
|
+
retry=retry,
|
|
85
|
+
cache=cache,
|
|
86
|
+
)
|
|
87
|
+
self.connection = self._resolve_connection(
|
|
88
|
+
session,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def _resolve_connection(
|
|
92
|
+
self,
|
|
93
|
+
session: Session,
|
|
94
|
+
) -> Any:
|
|
95
|
+
connection = getattr(session, "connection", None)
|
|
96
|
+
if connection is None:
|
|
97
|
+
msg = "No active connection found in session."
|
|
98
|
+
raise ConnectionError(msg)
|
|
99
|
+
self.markpoint("_resolve_connection[OK]")
|
|
100
|
+
return connection
|
|
101
|
+
|
|
102
|
+
def _parse_date_params(
|
|
103
|
+
self,
|
|
104
|
+
payload: Dict[str, Any],
|
|
105
|
+
keys: List[str],
|
|
106
|
+
) -> Dict[str, Any]:
|
|
107
|
+
payload = payload.copy()
|
|
108
|
+
for key in keys:
|
|
109
|
+
if key in payload:
|
|
110
|
+
value = payload.get(key)
|
|
111
|
+
if isinstance(value, datetime):
|
|
112
|
+
payload[key] = value.strftime("%Y%m%d")
|
|
113
|
+
elif isinstance(value, date):
|
|
114
|
+
payload[key] = value.strftime("%Y%m%d")
|
|
115
|
+
elif isinstance(value, str):
|
|
116
|
+
if "-" in value:
|
|
117
|
+
dt = datetime.strptime(value, "%Y-%m-%d")
|
|
118
|
+
payload[key] = dt.strftime("%Y%m%d")
|
|
119
|
+
else:
|
|
120
|
+
payload[key] = value
|
|
121
|
+
return payload
|
|
122
|
+
|
|
123
|
+
def _parse_string_params(
|
|
124
|
+
self,
|
|
125
|
+
payload: Dict[str, Any],
|
|
126
|
+
keys: List[str],
|
|
127
|
+
) -> Dict[str, Any]:
|
|
128
|
+
payload = payload.copy()
|
|
129
|
+
for key in keys:
|
|
130
|
+
if key in payload:
|
|
131
|
+
value = payload.get(key)
|
|
132
|
+
if isinstance(value, str):
|
|
133
|
+
payload[key] = value
|
|
134
|
+
return payload
|
|
135
|
+
|
|
136
|
+
def _parse_year_params(
|
|
137
|
+
self,
|
|
138
|
+
payload: Dict[str, Any],
|
|
139
|
+
key: List[str],
|
|
140
|
+
) -> Dict[str, Any]:
|
|
141
|
+
payload = payload.copy()
|
|
142
|
+
if key not in payload:
|
|
143
|
+
return payload
|
|
144
|
+
else:
|
|
145
|
+
year = str(payload.pop(key))
|
|
146
|
+
if year.isdigit() and len(year) == 4:
|
|
147
|
+
payload["start_date"] = f"{year}0101"
|
|
148
|
+
payload["end_date"] = f"{year}1231"
|
|
149
|
+
return payload
|
|
150
|
+
|
|
151
|
+
def _parse_period_params(
|
|
152
|
+
self,
|
|
153
|
+
payload: Dict[str, Any],
|
|
154
|
+
key: int | str, # example "2023-1"
|
|
155
|
+
) -> Dict[str, Any]:
|
|
156
|
+
payload = payload.copy()
|
|
157
|
+
if key not in payload:
|
|
158
|
+
return payload
|
|
159
|
+
else:
|
|
160
|
+
period = str(payload.pop(key))
|
|
161
|
+
|
|
162
|
+
# If already in YYYYMMDD format, just set it
|
|
163
|
+
if len(period) == 8 and period.isdigit():
|
|
164
|
+
payload["period"] = period
|
|
165
|
+
return payload
|
|
166
|
+
|
|
167
|
+
# Parse YYYY-Q format
|
|
168
|
+
parts = period.split("-")
|
|
169
|
+
if len(parts) != 2:
|
|
170
|
+
# Invalid format, skip conversion
|
|
171
|
+
return payload
|
|
172
|
+
|
|
173
|
+
year = parts[0]
|
|
174
|
+
quarter = parts[1]
|
|
175
|
+
valid_year = len(year) == 4 and year.isdigit()
|
|
176
|
+
valid_quarter = quarter in ["1", "2", "3", "4"]
|
|
177
|
+
if valid_year and valid_quarter:
|
|
178
|
+
if quarter == "1":
|
|
179
|
+
payload["period"] = f"{year}0331"
|
|
180
|
+
elif quarter == "2":
|
|
181
|
+
payload["period"] = f"{year}0630"
|
|
182
|
+
elif quarter == "3":
|
|
183
|
+
payload["period"] = f"{year}0930"
|
|
184
|
+
elif quarter == "4":
|
|
185
|
+
payload["period"] = f"{year}1231"
|
|
186
|
+
return payload
|
|
187
|
+
|
|
188
|
+
def _fetchall(
|
|
189
|
+
self,
|
|
190
|
+
api: Callable,
|
|
191
|
+
**params: Any,
|
|
192
|
+
) -> pd.DataFrame:
|
|
193
|
+
"""
|
|
194
|
+
分页获取所有数据并合并为单个 DataFrame。
|
|
195
|
+
|
|
196
|
+
参数:
|
|
197
|
+
- api: Callable, Tushare API 方法,必须接受 limit 和 offset 参数。
|
|
198
|
+
- **params: Any, 传递给 API 方法的其他参数。
|
|
199
|
+
|
|
200
|
+
返回:
|
|
201
|
+
- pd.DataFrame: 合并后的完整数据,如果没有数据则返回空 DataFrame。
|
|
202
|
+
|
|
203
|
+
说明:
|
|
204
|
+
- 自动处理分页逻辑,直到获取所有数据或达到 pagelimit。
|
|
205
|
+
- 每页之间会执行冷却等待(coolant.cool())。
|
|
206
|
+
- 使用 metric 记录每页的获取进度。
|
|
207
|
+
"""
|
|
208
|
+
# self.paginate.reset() # Removed since
|
|
209
|
+
batch: List[pd.DataFrame] = []
|
|
210
|
+
for pagenum in range(self.paginate.pagelimit):
|
|
211
|
+
try:
|
|
212
|
+
result = api(
|
|
213
|
+
limit=self.paginate.pagesize,
|
|
214
|
+
offset=self.paginate.offset,
|
|
215
|
+
**params,
|
|
216
|
+
)
|
|
217
|
+
except Exception as e:
|
|
218
|
+
self.markpoint(f"_fetchall[pagenum={pagenum}, ERROR]")
|
|
219
|
+
raise e
|
|
220
|
+
|
|
221
|
+
# Check for empty result
|
|
222
|
+
if result is None or len(result) == 0:
|
|
223
|
+
break
|
|
224
|
+
|
|
225
|
+
batch.append(result)
|
|
226
|
+
self.markpoint(f"_fetchall[pagenum={pagenum}, OK]")
|
|
227
|
+
|
|
228
|
+
# Check if have fetched all data
|
|
229
|
+
if len(result) < self.paginate.pagesize:
|
|
230
|
+
break
|
|
231
|
+
|
|
232
|
+
self.paginate.next()
|
|
233
|
+
self.coolant.cool()
|
|
234
|
+
|
|
235
|
+
if batch:
|
|
236
|
+
self.markpoint("_fetchall[OK]")
|
|
237
|
+
return pd.concat(batch, ignore_index=True)
|
|
238
|
+
else:
|
|
239
|
+
return pd.DataFrame()
|
|
240
|
+
|
|
241
|
+
def _load_cache(
|
|
242
|
+
self,
|
|
243
|
+
) -> Optional[pd.DataFrame]:
|
|
244
|
+
if self.cache:
|
|
245
|
+
cached = self.cache.get(self.params.identifier)
|
|
246
|
+
if cached is not None:
|
|
247
|
+
self.markpoint("load_cache[OK]")
|
|
248
|
+
return cached
|
|
249
|
+
return None
|
|
250
|
+
|
|
251
|
+
def _save_cache(
|
|
252
|
+
self,
|
|
253
|
+
data: pd.DataFrame,
|
|
254
|
+
) -> None:
|
|
255
|
+
if self.cache:
|
|
256
|
+
self.markpoint("_save_cache[OK]")
|
|
257
|
+
self.cache.set(self.params.identifier, data)
|