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,217 @@
|
|
|
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.baostock.session.session import Session
|
|
15
|
+
from xfintech.fabric.table.info import TableInfo
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class BaostockJob(Job):
|
|
19
|
+
"""
|
|
20
|
+
描述:
|
|
21
|
+
- Baostock 数据源作业类,继承自 Job 基类。
|
|
22
|
+
- 专门用于从 Baostock API 获取金融数据。
|
|
23
|
+
- 自动处理连接管理、数据获取、重试和缓存等功能。
|
|
24
|
+
- 支持 Direct 模式(直接连接)和 Relay 模式(中继服务器)。
|
|
25
|
+
- 自动检测 Direct/Relay 模式并处理 ResultSet 或 DataFrame。
|
|
26
|
+
- 支持日期格式自动转换(YYYYMMDD → YYYY-MM-DD)。
|
|
27
|
+
|
|
28
|
+
属性:
|
|
29
|
+
- connection: Any, Baostock API 连接对象,从 session 中获取。
|
|
30
|
+
- 继承 Job 类的所有属性(name, key, params, coolant, paginate, retry, cache, metric)。
|
|
31
|
+
|
|
32
|
+
方法:
|
|
33
|
+
- _resolve_connection(session): 从 session 解析并验证连接对象。
|
|
34
|
+
- _fetchall(api, **params): 获取所有数据并自动处理 Direct/Relay 模式。
|
|
35
|
+
- _parse_date_params(payload, keys): 解析日期参数,支持多种格式。
|
|
36
|
+
- _parse_string_params(payload, keys): 解析字符串参数。
|
|
37
|
+
|
|
38
|
+
例子:
|
|
39
|
+
```python
|
|
40
|
+
from xfintech.data.source.baostock.job import BaostockJob
|
|
41
|
+
from xfintech.data.source.baostock.session import Session
|
|
42
|
+
|
|
43
|
+
# 创建 session
|
|
44
|
+
session = Session()
|
|
45
|
+
|
|
46
|
+
# 创建作业
|
|
47
|
+
job = BaostockJob(
|
|
48
|
+
name="minuteline",
|
|
49
|
+
key="/baostock/minuteline",
|
|
50
|
+
session=session,
|
|
51
|
+
params={"code": "sh.600000", "start_date": "20240101"},
|
|
52
|
+
paginate={"pagesize": 100, "pagelimit": 1000},
|
|
53
|
+
retry={"retry": 3, "wait": 1},
|
|
54
|
+
cache=True
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# 在子类中实现 _run 方法来调用 _fetchall
|
|
58
|
+
class MinutelineJob(BaostockJob):
|
|
59
|
+
def _run(self):
|
|
60
|
+
params = self.get_params()
|
|
61
|
+
params = self._parse_date_params(params, ["start_date", "end_date"])
|
|
62
|
+
return self._fetchall(
|
|
63
|
+
api=self.connection.query_history_k_data_plus,
|
|
64
|
+
**params
|
|
65
|
+
)
|
|
66
|
+
```
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
def __init__(
|
|
70
|
+
self,
|
|
71
|
+
name: str,
|
|
72
|
+
key: str,
|
|
73
|
+
session: Session,
|
|
74
|
+
source: Optional[TableInfo] = None,
|
|
75
|
+
target: Optional[TableInfo] = None,
|
|
76
|
+
params: Optional[Params | Dict[str, Any]] = None,
|
|
77
|
+
coolant: Optional[Coolant | Dict[str, Any]] = None,
|
|
78
|
+
paginate: Optional[Paginate | Dict[str, Any]] = None,
|
|
79
|
+
retry: Optional[Retry | Dict[str, Any]] = None,
|
|
80
|
+
cache: Optional[Cache | Dict[str, str] | bool] = None,
|
|
81
|
+
) -> None:
|
|
82
|
+
super().__init__(
|
|
83
|
+
name=name,
|
|
84
|
+
key=key,
|
|
85
|
+
source=source,
|
|
86
|
+
target=target,
|
|
87
|
+
params=params,
|
|
88
|
+
coolant=coolant,
|
|
89
|
+
paginate=paginate,
|
|
90
|
+
retry=retry,
|
|
91
|
+
cache=cache,
|
|
92
|
+
)
|
|
93
|
+
self.connection = self._resolve_connection(
|
|
94
|
+
session,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
def _resolve_connection(
|
|
98
|
+
self,
|
|
99
|
+
session: Session,
|
|
100
|
+
) -> Any:
|
|
101
|
+
connection = getattr(session, "connection", None)
|
|
102
|
+
if connection is None:
|
|
103
|
+
msg = "No active connection found in session."
|
|
104
|
+
raise ConnectionError(msg)
|
|
105
|
+
self.markpoint("_resolve_connection[OK]")
|
|
106
|
+
return connection
|
|
107
|
+
|
|
108
|
+
def _parse_string_params(
|
|
109
|
+
self,
|
|
110
|
+
payload: Dict[str, Any],
|
|
111
|
+
keys: List[str],
|
|
112
|
+
) -> Dict[str, Any]:
|
|
113
|
+
payload = payload.copy()
|
|
114
|
+
for key in keys:
|
|
115
|
+
if key in payload:
|
|
116
|
+
value = payload.get(key)
|
|
117
|
+
if isinstance(value, str):
|
|
118
|
+
payload[key] = value
|
|
119
|
+
return payload
|
|
120
|
+
|
|
121
|
+
def _parse_date_params(
|
|
122
|
+
self,
|
|
123
|
+
payload: Dict[str, Any],
|
|
124
|
+
keys: List[str],
|
|
125
|
+
) -> Dict[str, Any]:
|
|
126
|
+
payload = payload.copy()
|
|
127
|
+
for key in keys:
|
|
128
|
+
if key in payload:
|
|
129
|
+
value = payload.get(key)
|
|
130
|
+
if isinstance(value, (date, datetime)):
|
|
131
|
+
payload[key] = value.strftime("%Y-%m-%d")
|
|
132
|
+
if isinstance(value, date):
|
|
133
|
+
payload[key] = value.strftime("%Y-%m-%d")
|
|
134
|
+
if isinstance(value, str):
|
|
135
|
+
if "-" in value: # YYYY-MM-DD
|
|
136
|
+
payload[key] = value
|
|
137
|
+
else: # YYYYMMDD
|
|
138
|
+
dt = datetime.strptime(value, "%Y%m%d")
|
|
139
|
+
payload[key] = dt.strftime("%Y-%m-%d")
|
|
140
|
+
return payload
|
|
141
|
+
|
|
142
|
+
def _parse_year_params(
|
|
143
|
+
self,
|
|
144
|
+
payload: Dict[str, Any],
|
|
145
|
+
key: str,
|
|
146
|
+
) -> Dict[str, Any]:
|
|
147
|
+
payload = payload.copy()
|
|
148
|
+
if key not in payload:
|
|
149
|
+
return payload
|
|
150
|
+
else:
|
|
151
|
+
year = str(payload.pop(key))
|
|
152
|
+
if year.isdigit() and len(year) == 4:
|
|
153
|
+
payload["start_date"] = f"{year}-01-01"
|
|
154
|
+
payload["end_date"] = f"{year}-12-31"
|
|
155
|
+
return payload
|
|
156
|
+
|
|
157
|
+
def _fetchall(
|
|
158
|
+
self,
|
|
159
|
+
api: Callable,
|
|
160
|
+
**params: Any,
|
|
161
|
+
) -> pd.DataFrame:
|
|
162
|
+
"""
|
|
163
|
+
描述:
|
|
164
|
+
- 使用迭代器获取所有数据并合并为单个 DataFrame。
|
|
165
|
+
|
|
166
|
+
参数:
|
|
167
|
+
- api: Callable, Baostock API 方法(如 connection.query_history_k_data_plus)
|
|
168
|
+
- **params: Any, 传递给 API 方法的参数
|
|
169
|
+
|
|
170
|
+
返回:
|
|
171
|
+
- pd.DataFrame: 合并后的完整数据,如果没有数据或出错则返回空 DataFrame。
|
|
172
|
+
|
|
173
|
+
说明:
|
|
174
|
+
- Direct 模式:调用 api(**params) 返回 ResultSet,使用 get_data() 获取所有数据
|
|
175
|
+
- Relay 模式:relay 在服务端执行完整的 get_data(),直接返回 DataFrame
|
|
176
|
+
- 自动检测返回类型并处理
|
|
177
|
+
- Baostock 默认每页 10,000 行 (BAOSTOCK_PER_PAGE_COUNT)
|
|
178
|
+
- API 调用数 = ceil(总行数 / 10,000)
|
|
179
|
+
|
|
180
|
+
"""
|
|
181
|
+
self.paginate.reset()
|
|
182
|
+
result = api(**params)
|
|
183
|
+
self.markpoint("_fetchall[api_called]")
|
|
184
|
+
|
|
185
|
+
# Relay mode will return DataFrame directly
|
|
186
|
+
if isinstance(result, pd.DataFrame):
|
|
187
|
+
self.markpoint(f"_fetchall[relay_mode, rows={len(result)}]")
|
|
188
|
+
return result
|
|
189
|
+
|
|
190
|
+
# Direct mode will return ResultSet
|
|
191
|
+
else:
|
|
192
|
+
if result.error_code != "0":
|
|
193
|
+
errcode = result.error_code
|
|
194
|
+
errmsg = result.error_msg
|
|
195
|
+
self.markpoint(f"_fetchall[ERROR: code={errcode}, msg={errmsg}]")
|
|
196
|
+
return pd.DataFrame()
|
|
197
|
+
data = result.get_data()
|
|
198
|
+
self.markpoint(f"_fetchall[direct_mode, rows={len(data)}]")
|
|
199
|
+
return data
|
|
200
|
+
|
|
201
|
+
def _load_cache(
|
|
202
|
+
self,
|
|
203
|
+
) -> Optional[pd.DataFrame]:
|
|
204
|
+
if self.cache:
|
|
205
|
+
cached = self.cache.get(self.params.identifier)
|
|
206
|
+
if cached is not None:
|
|
207
|
+
self.markpoint("load_cache[OK]")
|
|
208
|
+
return cached
|
|
209
|
+
return None
|
|
210
|
+
|
|
211
|
+
def _save_cache(
|
|
212
|
+
self,
|
|
213
|
+
data: pd.DataFrame,
|
|
214
|
+
) -> None:
|
|
215
|
+
if self.cache:
|
|
216
|
+
self.markpoint("_save_cache[OK]")
|
|
217
|
+
self.cache.set(self.params.identifier, data)
|
|
File without changes
|