@v587d/capital-generation 2.28.0 → 2.30.0
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.
- package/CHANGELOG.md +59 -0
- package/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +16 -0
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/collector-runtime.js +56 -1
- package/lib/data-collector/catalog-taxonomy.d.ts +1 -1
- package/lib/data-collector/catalog-taxonomy.js +33 -0
- package/lib/data-collector/tools.js +7 -7
- package/lib/host-version.d.ts +9 -0
- package/lib/host-version.js +57 -0
- package/lib/python-runtime/errors.d.ts +1 -1
- package/lib/python-runtime/errors.js +2 -0
- package/lib/python-runtime/manager.d.ts +28 -1
- package/lib/python-runtime/manager.js +141 -5
- package/lib/python-runtime/probe.d.ts +24 -0
- package/lib/python-runtime/probe.js +66 -50
- package/lib/runtime-entry.js +8 -0
- package/lib/sources/csindex-http.d.ts +4 -0
- package/lib/sources/csindex-http.js +233 -0
- package/lib/sources/eastmoney-http.js +1504 -1
- package/lib/sources/fuyao-rest.js +168 -8
- package/lib/sources/official-http.d.ts +4 -0
- package/lib/sources/official-http.js +477 -0
- package/lib/sources/python-remote.d.ts +25 -0
- package/lib/sources/python-remote.js +461 -0
- package/lib/sources/sina-http.d.ts +2 -0
- package/lib/sources/sina-http.js +484 -0
- package/lib/sources/tencent-http.js +23 -8
- package/lib/sources/ths-http.d.ts +2 -0
- package/lib/sources/ths-http.js +514 -0
- package/lib/time/tools.js +19 -0
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/sources.d.ts +7 -0
- package/lib/web-retriever/sources.js +46 -21
- package/lib/web-retriever/throttle.d.ts +8 -0
- package/lib/web-retriever/throttle.js +13 -0
- package/lib/web-retriever/tools.js +1 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +6 -3
- package/preset/capital-generation/agent.patch.yml +7 -5
- package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +16 -16
- package/python/scripts/baostock_stock_basic.py +129 -0
- package/python/scripts/baostock_valuation_history.py +141 -0
- package/python/scripts/pbc_social_financing.py +291 -0
- package/python/vendor/baostock/LICENSE +19 -0
- package/python/vendor/baostock/__init__.py +42 -0
- package/python/vendor/baostock/common/__init__.py +0 -0
- package/python/vendor/baostock/common/contants.py +189 -0
- package/python/vendor/baostock/common/context.py +4 -0
- package/python/vendor/baostock/corpreport/__init__.py +0 -0
- package/python/vendor/baostock/corpreport/corp_performance.py +202 -0
- package/python/vendor/baostock/data/__init__.py +0 -0
- package/python/vendor/baostock/data/messageheader.py +17 -0
- package/python/vendor/baostock/data/msg.py +21 -0
- package/python/vendor/baostock/data/resultset.py +200 -0
- package/python/vendor/baostock/demo/__init__.py +0 -0
- package/python/vendor/baostock/demo/demo_A_stock_5mk-data.py +34 -0
- package/python/vendor/baostock/demo/demo_A_stock_k_data.py +36 -0
- package/python/vendor/baostock/demo/demo_AllStock.py +27 -0
- package/python/vendor/baostock/demo/demo_Balance_data.py +22 -0
- package/python/vendor/baostock/demo/demo_CashFlow_data.py +22 -0
- package/python/vendor/baostock/demo/demo_Dividend_data.py +35 -0
- package/python/vendor/baostock/demo/demo_Dupont_data.py +25 -0
- package/python/vendor/baostock/demo/demo_Forecast_report.py +24 -0
- package/python/vendor/baostock/demo/demo_Growth_data.py +22 -0
- package/python/vendor/baostock/demo/demo_Index_k_data.py +39 -0
- package/python/vendor/baostock/demo/demo_Operation_data.py +22 -0
- package/python/vendor/baostock/demo/demo_PerformanceExpress_report.py +25 -0
- package/python/vendor/baostock/demo/demo_Profit_data.py +22 -0
- package/python/vendor/baostock/demo/demo_TradeDates.py +27 -0
- package/python/vendor/baostock/demo/demo_adjust_factor_data.py +23 -0
- package/python/vendor/baostock/demo/demo_assignDayData.py +23 -0
- package/python/vendor/baostock/demo/demo_daily_adjust_factor_data.py +28 -0
- package/python/vendor/baostock/demo/demo_daily_k_4_AStock.py +28 -0
- package/python/vendor/baostock/demo/demo_daily_k_4_ETF.py +28 -0
- package/python/vendor/baostock/demo/demo_depositRate_data.py +26 -0
- package/python/vendor/baostock/demo/demo_hs300_stocks.py +26 -0
- package/python/vendor/baostock/demo/demo_loanRate_data.py +26 -0
- package/python/vendor/baostock/demo/demo_moneySupplyDataMonth_data.py +26 -0
- package/python/vendor/baostock/demo/demo_moneySupplyDataYear_data.py +26 -0
- package/python/vendor/baostock/demo/demo_requiredReserveRatio_data.py +26 -0
- package/python/vendor/baostock/demo/demo_set_API_key.py +37 -0
- package/python/vendor/baostock/demo/demo_stockBasic_data.py +27 -0
- package/python/vendor/baostock/demo/demo_stock_Valuation_indicator_data.py +34 -0
- package/python/vendor/baostock/demo/demo_stock_industry.py +26 -0
- package/python/vendor/baostock/demo/demo_sz50stocks.py +26 -0
- package/python/vendor/baostock/demo/demo_zz500_stock.py +26 -0
- package/python/vendor/baostock/evaluation/__init__.py +0 -0
- package/python/vendor/baostock/evaluation/season_index.py +758 -0
- package/python/vendor/baostock/login/__init__.py +0 -0
- package/python/vendor/baostock/login/loginout.py +230 -0
- package/python/vendor/baostock/macroscopic/__init__.py +0 -0
- package/python/vendor/baostock/macroscopic/economic_data.py +723 -0
- package/python/vendor/baostock/metadata/__init__.py +0 -0
- package/python/vendor/baostock/metadata/stock_metadata.py +207 -0
- package/python/vendor/baostock/security/__init__.py +0 -0
- package/python/vendor/baostock/security/history.py +265 -0
- package/python/vendor/baostock/security/sectorinfo.py +1024 -0
- package/python/vendor/baostock/util/__init__.py +0 -0
- package/python/vendor/baostock/util/socketutil.py +97 -0
- package/python/vendor/baostock/util/stringutil.py +83 -0
- package/python/vendor/et_xmlfile/LICENSE +23 -0
- package/python/vendor/et_xmlfile/LICENSE.python +298 -0
- package/python/vendor/et_xmlfile/__init__.py +8 -0
- package/python/vendor/et_xmlfile/incremental_tree.py +917 -0
- package/python/vendor/et_xmlfile/xmlfile.py +158 -0
- package/python/vendor/openpyxl/LICENSE +23 -0
- package/python/vendor/openpyxl/__init__.py +19 -0
- package/python/vendor/openpyxl/_constants.py +13 -0
- package/python/vendor/openpyxl/cell/__init__.py +4 -0
- package/python/vendor/openpyxl/cell/_writer.py +136 -0
- package/python/vendor/openpyxl/cell/cell.py +332 -0
- package/python/vendor/openpyxl/cell/read_only.py +136 -0
- package/python/vendor/openpyxl/cell/rich_text.py +202 -0
- package/python/vendor/openpyxl/cell/text.py +184 -0
- package/python/vendor/openpyxl/chart/_3d.py +105 -0
- package/python/vendor/openpyxl/chart/__init__.py +19 -0
- package/python/vendor/openpyxl/chart/_chart.py +199 -0
- package/python/vendor/openpyxl/chart/area_chart.py +106 -0
- package/python/vendor/openpyxl/chart/axis.py +401 -0
- package/python/vendor/openpyxl/chart/bar_chart.py +144 -0
- package/python/vendor/openpyxl/chart/bubble_chart.py +67 -0
- package/python/vendor/openpyxl/chart/chartspace.py +195 -0
- package/python/vendor/openpyxl/chart/data_source.py +246 -0
- package/python/vendor/openpyxl/chart/descriptors.py +43 -0
- package/python/vendor/openpyxl/chart/error_bar.py +62 -0
- package/python/vendor/openpyxl/chart/label.py +127 -0
- package/python/vendor/openpyxl/chart/layout.py +74 -0
- package/python/vendor/openpyxl/chart/legend.py +75 -0
- package/python/vendor/openpyxl/chart/line_chart.py +129 -0
- package/python/vendor/openpyxl/chart/marker.py +90 -0
- package/python/vendor/openpyxl/chart/picture.py +35 -0
- package/python/vendor/openpyxl/chart/pie_chart.py +177 -0
- package/python/vendor/openpyxl/chart/pivot.py +65 -0
- package/python/vendor/openpyxl/chart/plotarea.py +162 -0
- package/python/vendor/openpyxl/chart/print_settings.py +57 -0
- package/python/vendor/openpyxl/chart/radar_chart.py +55 -0
- package/python/vendor/openpyxl/chart/reader.py +32 -0
- package/python/vendor/openpyxl/chart/reference.py +124 -0
- package/python/vendor/openpyxl/chart/scatter_chart.py +53 -0
- package/python/vendor/openpyxl/chart/series.py +197 -0
- package/python/vendor/openpyxl/chart/series_factory.py +41 -0
- package/python/vendor/openpyxl/chart/shapes.py +89 -0
- package/python/vendor/openpyxl/chart/stock_chart.py +54 -0
- package/python/vendor/openpyxl/chart/surface_chart.py +119 -0
- package/python/vendor/openpyxl/chart/text.py +78 -0
- package/python/vendor/openpyxl/chart/title.py +76 -0
- package/python/vendor/openpyxl/chart/trendline.py +98 -0
- package/python/vendor/openpyxl/chart/updown_bars.py +31 -0
- package/python/vendor/openpyxl/chartsheet/__init__.py +3 -0
- package/python/vendor/openpyxl/chartsheet/chartsheet.py +107 -0
- package/python/vendor/openpyxl/chartsheet/custom.py +61 -0
- package/python/vendor/openpyxl/chartsheet/properties.py +28 -0
- package/python/vendor/openpyxl/chartsheet/protection.py +41 -0
- package/python/vendor/openpyxl/chartsheet/publish.py +58 -0
- package/python/vendor/openpyxl/chartsheet/relation.py +97 -0
- package/python/vendor/openpyxl/chartsheet/views.py +51 -0
- package/python/vendor/openpyxl/comments/__init__.py +4 -0
- package/python/vendor/openpyxl/comments/author.py +21 -0
- package/python/vendor/openpyxl/comments/comment_sheet.py +211 -0
- package/python/vendor/openpyxl/comments/comments.py +62 -0
- package/python/vendor/openpyxl/comments/shape_writer.py +112 -0
- package/python/vendor/openpyxl/compat/__init__.py +54 -0
- package/python/vendor/openpyxl/compat/abc.py +8 -0
- package/python/vendor/openpyxl/compat/numbers.py +43 -0
- package/python/vendor/openpyxl/compat/product.py +17 -0
- package/python/vendor/openpyxl/compat/singleton.py +40 -0
- package/python/vendor/openpyxl/compat/strings.py +25 -0
- package/python/vendor/openpyxl/descriptors/__init__.py +58 -0
- package/python/vendor/openpyxl/descriptors/base.py +272 -0
- package/python/vendor/openpyxl/descriptors/container.py +41 -0
- package/python/vendor/openpyxl/descriptors/excel.py +112 -0
- package/python/vendor/openpyxl/descriptors/namespace.py +12 -0
- package/python/vendor/openpyxl/descriptors/nested.py +129 -0
- package/python/vendor/openpyxl/descriptors/sequence.py +136 -0
- package/python/vendor/openpyxl/descriptors/serialisable.py +240 -0
- package/python/vendor/openpyxl/descriptors/slots.py +18 -0
- package/python/vendor/openpyxl/drawing/__init__.py +4 -0
- package/python/vendor/openpyxl/drawing/colors.py +435 -0
- package/python/vendor/openpyxl/drawing/connector.py +144 -0
- package/python/vendor/openpyxl/drawing/drawing.py +92 -0
- package/python/vendor/openpyxl/drawing/effect.py +407 -0
- package/python/vendor/openpyxl/drawing/fill.py +425 -0
- package/python/vendor/openpyxl/drawing/geometry.py +584 -0
- package/python/vendor/openpyxl/drawing/graphic.py +177 -0
- package/python/vendor/openpyxl/drawing/image.py +65 -0
- package/python/vendor/openpyxl/drawing/line.py +144 -0
- package/python/vendor/openpyxl/drawing/picture.py +144 -0
- package/python/vendor/openpyxl/drawing/properties.py +174 -0
- package/python/vendor/openpyxl/drawing/relation.py +17 -0
- package/python/vendor/openpyxl/drawing/spreadsheet_drawing.py +382 -0
- package/python/vendor/openpyxl/drawing/text.py +717 -0
- package/python/vendor/openpyxl/drawing/xdr.py +33 -0
- package/python/vendor/openpyxl/formatting/__init__.py +3 -0
- package/python/vendor/openpyxl/formatting/formatting.py +114 -0
- package/python/vendor/openpyxl/formatting/rule.py +291 -0
- package/python/vendor/openpyxl/formula/__init__.py +3 -0
- package/python/vendor/openpyxl/formula/tokenizer.py +446 -0
- package/python/vendor/openpyxl/formula/translate.py +166 -0
- package/python/vendor/openpyxl/packaging/__init__.py +3 -0
- package/python/vendor/openpyxl/packaging/core.py +115 -0
- package/python/vendor/openpyxl/packaging/custom.py +289 -0
- package/python/vendor/openpyxl/packaging/extended.py +137 -0
- package/python/vendor/openpyxl/packaging/interface.py +56 -0
- package/python/vendor/openpyxl/packaging/manifest.py +194 -0
- package/python/vendor/openpyxl/packaging/relationship.py +158 -0
- package/python/vendor/openpyxl/packaging/workbook.py +185 -0
- package/python/vendor/openpyxl/pivot/__init__.py +1 -0
- package/python/vendor/openpyxl/pivot/cache.py +965 -0
- package/python/vendor/openpyxl/pivot/fields.py +326 -0
- package/python/vendor/openpyxl/pivot/record.py +111 -0
- package/python/vendor/openpyxl/pivot/table.py +1261 -0
- package/python/vendor/openpyxl/reader/__init__.py +1 -0
- package/python/vendor/openpyxl/reader/drawings.py +71 -0
- package/python/vendor/openpyxl/reader/excel.py +349 -0
- package/python/vendor/openpyxl/reader/strings.py +44 -0
- package/python/vendor/openpyxl/reader/workbook.py +133 -0
- package/python/vendor/openpyxl/styles/__init__.py +11 -0
- package/python/vendor/openpyxl/styles/alignment.py +62 -0
- package/python/vendor/openpyxl/styles/borders.py +103 -0
- package/python/vendor/openpyxl/styles/builtins.py +1397 -0
- package/python/vendor/openpyxl/styles/cell_style.py +206 -0
- package/python/vendor/openpyxl/styles/colors.py +172 -0
- package/python/vendor/openpyxl/styles/differential.py +95 -0
- package/python/vendor/openpyxl/styles/fills.py +224 -0
- package/python/vendor/openpyxl/styles/fonts.py +113 -0
- package/python/vendor/openpyxl/styles/named_styles.py +282 -0
- package/python/vendor/openpyxl/styles/numbers.py +200 -0
- package/python/vendor/openpyxl/styles/protection.py +17 -0
- package/python/vendor/openpyxl/styles/proxy.py +62 -0
- package/python/vendor/openpyxl/styles/styleable.py +151 -0
- package/python/vendor/openpyxl/styles/stylesheet.py +274 -0
- package/python/vendor/openpyxl/styles/table.py +94 -0
- package/python/vendor/openpyxl/utils/__init__.py +17 -0
- package/python/vendor/openpyxl/utils/bound_dictionary.py +26 -0
- package/python/vendor/openpyxl/utils/cell.py +240 -0
- package/python/vendor/openpyxl/utils/dataframe.py +87 -0
- package/python/vendor/openpyxl/utils/datetime.py +140 -0
- package/python/vendor/openpyxl/utils/escape.py +43 -0
- package/python/vendor/openpyxl/utils/exceptions.py +34 -0
- package/python/vendor/openpyxl/utils/formulas.py +24 -0
- package/python/vendor/openpyxl/utils/indexed_list.py +49 -0
- package/python/vendor/openpyxl/utils/inference.py +60 -0
- package/python/vendor/openpyxl/utils/protection.py +22 -0
- package/python/vendor/openpyxl/utils/units.py +108 -0
- package/python/vendor/openpyxl/workbook/__init__.py +4 -0
- package/python/vendor/openpyxl/workbook/_writer.py +197 -0
- package/python/vendor/openpyxl/workbook/child.py +166 -0
- package/python/vendor/openpyxl/workbook/defined_name.py +189 -0
- package/python/vendor/openpyxl/workbook/external_link/__init__.py +3 -0
- package/python/vendor/openpyxl/workbook/external_link/external.py +190 -0
- package/python/vendor/openpyxl/workbook/external_reference.py +18 -0
- package/python/vendor/openpyxl/workbook/function_group.py +36 -0
- package/python/vendor/openpyxl/workbook/properties.py +151 -0
- package/python/vendor/openpyxl/workbook/protection.py +163 -0
- package/python/vendor/openpyxl/workbook/smart_tags.py +56 -0
- package/python/vendor/openpyxl/workbook/views.py +155 -0
- package/python/vendor/openpyxl/workbook/web.py +98 -0
- package/python/vendor/openpyxl/workbook/workbook.py +438 -0
- package/python/vendor/openpyxl/worksheet/__init__.py +1 -0
- package/python/vendor/openpyxl/worksheet/_read_only.py +190 -0
- package/python/vendor/openpyxl/worksheet/_reader.py +472 -0
- package/python/vendor/openpyxl/worksheet/_write_only.py +160 -0
- package/python/vendor/openpyxl/worksheet/_writer.py +390 -0
- package/python/vendor/openpyxl/worksheet/cell_range.py +512 -0
- package/python/vendor/openpyxl/worksheet/cell_watch.py +34 -0
- package/python/vendor/openpyxl/worksheet/controls.py +107 -0
- package/python/vendor/openpyxl/worksheet/copier.py +70 -0
- package/python/vendor/openpyxl/worksheet/custom.py +35 -0
- package/python/vendor/openpyxl/worksheet/datavalidation.py +202 -0
- package/python/vendor/openpyxl/worksheet/dimensions.py +306 -0
- package/python/vendor/openpyxl/worksheet/drawing.py +14 -0
- package/python/vendor/openpyxl/worksheet/errors.py +93 -0
- package/python/vendor/openpyxl/worksheet/filters.py +486 -0
- package/python/vendor/openpyxl/worksheet/formula.py +51 -0
- package/python/vendor/openpyxl/worksheet/header_footer.py +270 -0
- package/python/vendor/openpyxl/worksheet/hyperlink.py +46 -0
- package/python/vendor/openpyxl/worksheet/merge.py +141 -0
- package/python/vendor/openpyxl/worksheet/ole.py +133 -0
- package/python/vendor/openpyxl/worksheet/page.py +174 -0
- package/python/vendor/openpyxl/worksheet/pagebreak.py +94 -0
- package/python/vendor/openpyxl/worksheet/picture.py +8 -0
- package/python/vendor/openpyxl/worksheet/print_settings.py +184 -0
- package/python/vendor/openpyxl/worksheet/properties.py +97 -0
- package/python/vendor/openpyxl/worksheet/protection.py +120 -0
- package/python/vendor/openpyxl/worksheet/related.py +17 -0
- package/python/vendor/openpyxl/worksheet/scenario.py +105 -0
- package/python/vendor/openpyxl/worksheet/smart_tag.py +78 -0
- package/python/vendor/openpyxl/worksheet/table.py +385 -0
- package/python/vendor/openpyxl/worksheet/views.py +155 -0
- package/python/vendor/openpyxl/worksheet/worksheet.py +907 -0
- package/python/vendor/openpyxl/writer/__init__.py +1 -0
- package/python/vendor/openpyxl/writer/excel.py +295 -0
- package/python/vendor/openpyxl/writer/theme.py +291 -0
- package/python/vendor/openpyxl/xml/__init__.py +42 -0
- package/python/vendor/openpyxl/xml/constants.py +129 -0
- package/python/vendor/openpyxl/xml/functions.py +87 -0
- package/watchlist/package.json +1 -1
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# -*- coding:utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
大类:公司公告,小类:公司业绩报告
|
|
4
|
+
@author: baostock.com
|
|
5
|
+
@group : baostock.com
|
|
6
|
+
@contact: baostock@163.com
|
|
7
|
+
@copyright: baostock System & alpha.All Rights Reserved.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import datetime
|
|
11
|
+
import time
|
|
12
|
+
import zlib
|
|
13
|
+
|
|
14
|
+
import baostock.data.resultset as rs
|
|
15
|
+
import baostock.common.contants as cons
|
|
16
|
+
import baostock.util.stringutil as strUtil
|
|
17
|
+
import baostock.common.context as conx
|
|
18
|
+
import baostock.util.socketutil as sock
|
|
19
|
+
import baostock.data.messageheader as msgheader
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def query_performance_express_report(code, start_date=None, end_date=None):
|
|
23
|
+
"""公司业绩快报。
|
|
24
|
+
@param code: 证券代码,不可为空
|
|
25
|
+
@param start_date: 开始日期,默认2015-01-01;发布日期或更新日期在这个范围内。
|
|
26
|
+
@param end_date: 结束日期,默认系统当前日期;发布日期或更新日期在这个范围内。
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
data = rs.ResultData()
|
|
30
|
+
if code is None or code == "":
|
|
31
|
+
print("股票代码不能为空,请检查。")
|
|
32
|
+
data.error_msg = "股票代码不能为空,请检查。"
|
|
33
|
+
data.error_code = cons.BSERR_PARAM_ERR
|
|
34
|
+
return data
|
|
35
|
+
if len(code) != cons.STOCK_CODE_LENGTH:
|
|
36
|
+
print("股票代码应为" + str(cons.STOCK_CODE_LENGTH) + "位,请检查。格式示例:sh.600000。")
|
|
37
|
+
data.error_msg = "股票代码应为" + str(cons.STOCK_CODE_LENGTH) + "位,请检查。格式示例:sh.600000。"
|
|
38
|
+
data.error_code = cons.BSERR_PARAM_ERR
|
|
39
|
+
return data
|
|
40
|
+
code = code.lower()
|
|
41
|
+
if (code.endswith("sh") or code.endswith("sz")):
|
|
42
|
+
code = code[7:9].lower() + "." + code[0:6]
|
|
43
|
+
|
|
44
|
+
if start_date is None or start_date == "":
|
|
45
|
+
start_date = cons.DEFAULT_START_DATE
|
|
46
|
+
if end_date is None or end_date == "":
|
|
47
|
+
end_date = time.strftime("%Y-%m-%d", time.localtime())
|
|
48
|
+
|
|
49
|
+
if start_date != "" and start_date is not None and end_date != "" and end_date is not None:
|
|
50
|
+
if strUtil.is_valid_date(start_date) and strUtil.is_valid_date(end_date):
|
|
51
|
+
start_date_time = datetime.datetime.strptime(
|
|
52
|
+
start_date, '%Y-%m-%d')
|
|
53
|
+
end_date_time = datetime.datetime.strptime(end_date, '%Y-%m-%d')
|
|
54
|
+
if end_date_time < start_date_time:
|
|
55
|
+
print("起始日期大于终止日期,请修改。")
|
|
56
|
+
data.error_code = cons.BSERR_START_BIGTHAN_END
|
|
57
|
+
data.error_msg = "起始日期大于终止日期,请修改。"
|
|
58
|
+
return data
|
|
59
|
+
else:
|
|
60
|
+
print("日期格式不正确,请修改。")
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
user_id = ""
|
|
64
|
+
try:
|
|
65
|
+
user_id = getattr(conx, "user_id")
|
|
66
|
+
except Exception:
|
|
67
|
+
print("you don't login.")
|
|
68
|
+
data.error_code = cons.BSERR_NO_LOGIN
|
|
69
|
+
data.error_msg = "you don't login."
|
|
70
|
+
return data
|
|
71
|
+
|
|
72
|
+
param = "%s,%s,%s,%s,%s,%s,%s" % (
|
|
73
|
+
"query_performance_express_report", user_id, "1",
|
|
74
|
+
cons.BAOSTOCK_PER_PAGE_COUNT, code, start_date, end_date)
|
|
75
|
+
|
|
76
|
+
msg_body = strUtil.organize_msg_body(param)
|
|
77
|
+
msg_header = msgheader.to_message_header(
|
|
78
|
+
cons.MESSAGE_TYPE_QUERYPERFORMANCEEXPRESSREPORT_REQUEST, len(msg_body))
|
|
79
|
+
|
|
80
|
+
data.msg_type = cons.MESSAGE_TYPE_QUERYPERFORMANCEEXPRESSREPORT_REQUEST
|
|
81
|
+
data.msg_body = msg_body
|
|
82
|
+
|
|
83
|
+
head_body = msg_header + msg_body
|
|
84
|
+
crc32str = zlib.crc32(bytes(head_body, encoding='utf-8'))
|
|
85
|
+
receive_data = sock.send_msg(head_body + cons.MESSAGE_SPLIT + str(crc32str))
|
|
86
|
+
|
|
87
|
+
if receive_data is None or receive_data.strip() == "":
|
|
88
|
+
data.error_code = cons.BSERR_RECVSOCK_FAIL
|
|
89
|
+
data.error_msg = "网络接收错误。"
|
|
90
|
+
return data
|
|
91
|
+
|
|
92
|
+
msg_header = receive_data[0:cons.MESSAGE_HEADER_LENGTH]
|
|
93
|
+
msg_body = receive_data[cons.MESSAGE_HEADER_LENGTH:-1]
|
|
94
|
+
header_arr = msg_header.split(cons.MESSAGE_SPLIT)
|
|
95
|
+
body_arr = msg_body.split(cons.MESSAGE_SPLIT)
|
|
96
|
+
data.msg_body_length = header_arr[2]
|
|
97
|
+
data.error_code = body_arr[0]
|
|
98
|
+
data.error_msg = body_arr[1]
|
|
99
|
+
|
|
100
|
+
if cons.BSERR_SUCCESS == data.error_code:
|
|
101
|
+
data.method = body_arr[2]
|
|
102
|
+
data.user_id = body_arr[3]
|
|
103
|
+
data.cur_page_num = body_arr[4]
|
|
104
|
+
data.per_page_count = body_arr[5]
|
|
105
|
+
data.setData(body_arr[6])
|
|
106
|
+
data.code = body_arr[7]
|
|
107
|
+
data.start_date = body_arr[8]
|
|
108
|
+
data.end_date = body_arr[9]
|
|
109
|
+
data.setFields(body_arr[10])
|
|
110
|
+
|
|
111
|
+
return data
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def query_forecast_report(code, start_date=None, end_date=None):
|
|
115
|
+
"""公司业绩预告,
|
|
116
|
+
@param code: 证券代码,不可为空
|
|
117
|
+
@param start_date: 开始日期,默认2015-01-01;发布日期或统计日期在这个范围内。
|
|
118
|
+
@param end_date: 结束日期,默认系统当前日期;发布日期或统计日期在这个范围内。
|
|
119
|
+
"""
|
|
120
|
+
data = rs.ResultData()
|
|
121
|
+
if code is None or code == "":
|
|
122
|
+
print("股票代码不能为空,请检查。")
|
|
123
|
+
data.error_msg = "股票代码不能为空,请检查。"
|
|
124
|
+
data.error_code = cons.BSERR_PARAM_ERR
|
|
125
|
+
return data
|
|
126
|
+
if len(code) != cons.STOCK_CODE_LENGTH:
|
|
127
|
+
print("股票代码应为" + str(cons.STOCK_CODE_LENGTH) + "位,请检查。格式示例:sh.600000。")
|
|
128
|
+
data.error_msg = "股票代码应为" + str(cons.STOCK_CODE_LENGTH) + "位,请检查。格式示例:sh.600000。"
|
|
129
|
+
data.error_code = cons.BSERR_PARAM_ERR
|
|
130
|
+
return data
|
|
131
|
+
code = code.lower()
|
|
132
|
+
if (code.endswith("sh") or code.endswith("sz")):
|
|
133
|
+
code = code[7:9].lower() + "." + code[0:6]
|
|
134
|
+
|
|
135
|
+
if start_date is None or start_date == "":
|
|
136
|
+
start_date = cons.DEFAULT_START_DATE
|
|
137
|
+
if end_date is None or end_date == "":
|
|
138
|
+
end_date = time.strftime("%Y-%m-%d", time.localtime())
|
|
139
|
+
|
|
140
|
+
if start_date != "" and start_date is not None and end_date != "" and end_date is not None:
|
|
141
|
+
if strUtil.is_valid_date(start_date) and strUtil.is_valid_date(end_date):
|
|
142
|
+
start_date_time = datetime.datetime.strptime(
|
|
143
|
+
start_date, '%Y-%m-%d')
|
|
144
|
+
end_date_time = datetime.datetime.strptime(end_date, '%Y-%m-%d')
|
|
145
|
+
if end_date_time < start_date_time:
|
|
146
|
+
print("起始日期大于终止日期,请修改。")
|
|
147
|
+
data.error_code = cons.BSERR_START_BIGTHAN_END
|
|
148
|
+
data.error_msg = "起始日期大于终止日期,请修改。"
|
|
149
|
+
return data
|
|
150
|
+
else:
|
|
151
|
+
print("日期格式不正确,请修改。")
|
|
152
|
+
return
|
|
153
|
+
|
|
154
|
+
user_id = ""
|
|
155
|
+
try:
|
|
156
|
+
user_id = getattr(conx, "user_id")
|
|
157
|
+
except Exception:
|
|
158
|
+
print("you don't login.")
|
|
159
|
+
data.error_code = cons.BSERR_NO_LOGIN
|
|
160
|
+
data.error_msg = "you don't login."
|
|
161
|
+
return data
|
|
162
|
+
|
|
163
|
+
param = "%s,%s,%s,%s,%s,%s,%s" % (
|
|
164
|
+
"query_forecast_report", user_id, "1",
|
|
165
|
+
cons.BAOSTOCK_PER_PAGE_COUNT, code, start_date, end_date)
|
|
166
|
+
|
|
167
|
+
msg_body = strUtil.organize_msg_body(param)
|
|
168
|
+
msg_header = msgheader.to_message_header(
|
|
169
|
+
cons.MESSAGE_TYPE_QUERYFORECASTREPORT_REQUEST, len(msg_body))
|
|
170
|
+
|
|
171
|
+
data.msg_type = cons.MESSAGE_TYPE_QUERYFORECASTREPORT_REQUEST
|
|
172
|
+
data.msg_body = msg_body
|
|
173
|
+
|
|
174
|
+
head_body = msg_header + msg_body
|
|
175
|
+
crc32str = zlib.crc32(bytes(head_body, encoding='utf-8'))
|
|
176
|
+
receive_data = sock.send_msg(head_body + cons.MESSAGE_SPLIT + str(crc32str))
|
|
177
|
+
|
|
178
|
+
if receive_data is None or receive_data.strip() == "":
|
|
179
|
+
data.error_code = cons.BSERR_RECVSOCK_FAIL
|
|
180
|
+
data.error_msg = "网络接收错误。"
|
|
181
|
+
return data
|
|
182
|
+
|
|
183
|
+
msg_header = receive_data[0:cons.MESSAGE_HEADER_LENGTH]
|
|
184
|
+
msg_body = receive_data[cons.MESSAGE_HEADER_LENGTH:-1]
|
|
185
|
+
header_arr = msg_header.split(cons.MESSAGE_SPLIT)
|
|
186
|
+
body_arr = msg_body.split(cons.MESSAGE_SPLIT)
|
|
187
|
+
data.msg_body_length = header_arr[2]
|
|
188
|
+
data.error_code = body_arr[0]
|
|
189
|
+
data.error_msg = body_arr[1]
|
|
190
|
+
|
|
191
|
+
if cons.BSERR_SUCCESS == data.error_code:
|
|
192
|
+
data.method = body_arr[2]
|
|
193
|
+
data.user_id = body_arr[3]
|
|
194
|
+
data.cur_page_num = body_arr[4]
|
|
195
|
+
data.per_page_count = body_arr[5]
|
|
196
|
+
data.setData(body_arr[6])
|
|
197
|
+
data.code = body_arr[7]
|
|
198
|
+
data.start_date = body_arr[8]
|
|
199
|
+
data.end_date = body_arr[9]
|
|
200
|
+
data.setFields(body_arr[10])
|
|
201
|
+
|
|
202
|
+
return data
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# -*- coding:utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
封装消息头
|
|
4
|
+
@author: baostock.com
|
|
5
|
+
@group : baostock.com
|
|
6
|
+
@contact: baostock@163.com
|
|
7
|
+
"""
|
|
8
|
+
import baostock.common.contants as cons
|
|
9
|
+
import baostock.util.stringutil as strutil
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def to_message_header(msg_type, total_msg_length):
|
|
13
|
+
|
|
14
|
+
return_str = cons.BAOSTOCK_CLIENT_VERSION + cons.MESSAGE_SPLIT + msg_type \
|
|
15
|
+
+ cons.MESSAGE_SPLIT \
|
|
16
|
+
+ strutil.add_zero_for_string(total_msg_length, 10, True)
|
|
17
|
+
return return_str
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# -*- coding:utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
封装消息接口
|
|
4
|
+
@author: baostock.com
|
|
5
|
+
@group : baostock.com
|
|
6
|
+
@contact: baostock@163.com
|
|
7
|
+
"""
|
|
8
|
+
import baostock.common.contants as cons
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MessageHeader(object):
|
|
12
|
+
|
|
13
|
+
def __init__(self, msg_type, total_msg_length):
|
|
14
|
+
self.version = cons.BAOSTOCK_CLIENT_VERSION
|
|
15
|
+
self.msg_type = msg_type
|
|
16
|
+
self.total_msg_length = total_msg_length
|
|
17
|
+
|
|
18
|
+
def to_message_header_msg(self):
|
|
19
|
+
return self.version + cons.MESSAGE_SPLIT + self.msg_type \
|
|
20
|
+
+ cons.MESSAGE_SPLIT + self.total_msg_length
|
|
21
|
+
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# -*- coding:utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
返回数据接口
|
|
4
|
+
@author: baostock.com
|
|
5
|
+
@group : baostock.com
|
|
6
|
+
@contact: baostock@163.com
|
|
7
|
+
"""
|
|
8
|
+
import baostock.common.contants as cons
|
|
9
|
+
import pandas as pd
|
|
10
|
+
import json
|
|
11
|
+
import zlib
|
|
12
|
+
import baostock.data.messageheader as msgheader
|
|
13
|
+
import baostock.util.socketutil as sock
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ResultData(object):
|
|
17
|
+
def __init__(self):
|
|
18
|
+
"""初始化方法"""
|
|
19
|
+
|
|
20
|
+
# 消息头
|
|
21
|
+
self.version = cons.BAOSTOCK_CLIENT_VERSION
|
|
22
|
+
self.msg_type = 0 # 消息类型
|
|
23
|
+
self.msg_body_length = 0
|
|
24
|
+
|
|
25
|
+
# 消息体
|
|
26
|
+
self.method = "" # 方法名
|
|
27
|
+
self.user_id = "" # 用户账号
|
|
28
|
+
self.error_code = cons.BSERR_NO_LOGIN # 错误代码
|
|
29
|
+
self.error_msg = "" # 错误代码
|
|
30
|
+
|
|
31
|
+
self.cur_page_num = 1 # 当前页码
|
|
32
|
+
self.per_page_count = cons.BAOSTOCK_PER_PAGE_COUNT # 当前页条数
|
|
33
|
+
self.cur_row_num = 0 # 当前页面遍历条数 V0.5.5
|
|
34
|
+
|
|
35
|
+
self.code = "" # 股票代码
|
|
36
|
+
self.code_name = "" # 股票名称
|
|
37
|
+
self.fields = [] # 指示简称 list
|
|
38
|
+
self.start_date = "" # 开始日期
|
|
39
|
+
self.end_date = "" # 结束日期
|
|
40
|
+
self.frequency = "" # 数据类型
|
|
41
|
+
self.adjustflag = "" # 复权类型
|
|
42
|
+
self.data = [] # 数据值 list类型
|
|
43
|
+
|
|
44
|
+
self.msg_body = "" # 消息体
|
|
45
|
+
self.year = "" # 年份
|
|
46
|
+
self.yearType = "" # 年份类别
|
|
47
|
+
self.quarter = "" # 季度
|
|
48
|
+
self.day = "" # 天
|
|
49
|
+
|
|
50
|
+
self.date = "" #查询日期
|
|
51
|
+
# self.request_id = 0
|
|
52
|
+
# self.serial_id = 0
|
|
53
|
+
|
|
54
|
+
def next(self):
|
|
55
|
+
""" 判断是否还有后续数据
|
|
56
|
+
:return: 有数据时返回True,当前页没有数据时向服务器请求下一页;没有数据时返回False
|
|
57
|
+
"""
|
|
58
|
+
if len(self.data) == 0:
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
data_len = len(self.data)
|
|
62
|
+
if self.cur_row_num < data_len:
|
|
63
|
+
# 当前页还有数据
|
|
64
|
+
return True
|
|
65
|
+
else:
|
|
66
|
+
# 当前页获取的总记录数不足cons.BAOSTOCK_PER_PAGE_COUNT时,不请求下一页
|
|
67
|
+
if len(self.data) < cons.BAOSTOCK_PER_PAGE_COUNT:
|
|
68
|
+
return False
|
|
69
|
+
|
|
70
|
+
# 2026-06-22,当前页获取的总记录数大于cons.BAOSTOCK_PER_PAGE_COUNT时,代表向server端请求的数据不用翻页请求操作。例如:query_history_daily_k_AStock请求
|
|
71
|
+
if len(self.data) > cons.BAOSTOCK_PER_PAGE_COUNT:
|
|
72
|
+
return False
|
|
73
|
+
|
|
74
|
+
msg_body_split = self.msg_body.split(cons.MESSAGE_SPLIT)
|
|
75
|
+
|
|
76
|
+
if self.cur_page_num.isdigit():
|
|
77
|
+
# 取下一页数据
|
|
78
|
+
next_page = int(self.cur_page_num) + 1
|
|
79
|
+
msg_body_split[2] = str(next_page)
|
|
80
|
+
else:
|
|
81
|
+
print("当前页面编号不正确,请检查后再试")
|
|
82
|
+
return False
|
|
83
|
+
|
|
84
|
+
msg_body = cons.MESSAGE_SPLIT.join(msg_body_split)
|
|
85
|
+
msg_header = msgheader.to_message_header(
|
|
86
|
+
self.msg_type, len(msg_body))
|
|
87
|
+
|
|
88
|
+
head_body = msg_header + msg_body
|
|
89
|
+
crc32str = zlib.crc32(bytes(head_body, encoding='utf-8'))
|
|
90
|
+
receive_data = sock.send_msg(
|
|
91
|
+
head_body + cons.MESSAGE_SPLIT + str(crc32str))
|
|
92
|
+
|
|
93
|
+
if receive_data is None or receive_data.strip() == "":
|
|
94
|
+
return False
|
|
95
|
+
|
|
96
|
+
msg_header = receive_data[0:cons.MESSAGE_HEADER_LENGTH]
|
|
97
|
+
msg_body = receive_data[cons.MESSAGE_HEADER_LENGTH:-1]
|
|
98
|
+
|
|
99
|
+
header_arr = msg_header.split(cons.MESSAGE_SPLIT)
|
|
100
|
+
body_arr = msg_body.split(cons.MESSAGE_SPLIT)
|
|
101
|
+
# data.version = header_arr[0]
|
|
102
|
+
# self.msg_type = header_arr[1]
|
|
103
|
+
self.msg_body_length = header_arr[2]
|
|
104
|
+
|
|
105
|
+
self.error_code = body_arr[0]
|
|
106
|
+
self.error_msg = body_arr[1]
|
|
107
|
+
|
|
108
|
+
if cons.BSERR_SUCCESS == self.error_code:
|
|
109
|
+
self.method = body_arr[2]
|
|
110
|
+
self.user_id = body_arr[3]
|
|
111
|
+
self.cur_page_num = body_arr[4]
|
|
112
|
+
self.per_page_count = body_arr[5]
|
|
113
|
+
self.setData(body_arr[6])
|
|
114
|
+
self.cur_row_num = 0
|
|
115
|
+
if len(self.data) == 0:
|
|
116
|
+
return False
|
|
117
|
+
else:
|
|
118
|
+
return True
|
|
119
|
+
else:
|
|
120
|
+
return False
|
|
121
|
+
|
|
122
|
+
def get_row_data(self):
|
|
123
|
+
"""返回当前获取的结果的某一行
|
|
124
|
+
@return: 返回当前行数据
|
|
125
|
+
"""
|
|
126
|
+
# 组织返回数据
|
|
127
|
+
return_data = []
|
|
128
|
+
if self.cur_row_num < len(self.data):
|
|
129
|
+
return_data = self.data[self.cur_row_num]
|
|
130
|
+
self.cur_row_num = self.cur_row_num + 1
|
|
131
|
+
return return_data
|
|
132
|
+
|
|
133
|
+
def get_data(self):
|
|
134
|
+
"""返回当前获取的全部结果
|
|
135
|
+
@return:DataFrame类型
|
|
136
|
+
"""
|
|
137
|
+
if len(self.data) == 0:
|
|
138
|
+
return pd.DataFrame()
|
|
139
|
+
else:
|
|
140
|
+
# 组织返回数据
|
|
141
|
+
df = pd.DataFrame(self.data, columns=self.fields)
|
|
142
|
+
self.cur_row_num = len(self.data)
|
|
143
|
+
while (self.error_code == '0') & self.next():
|
|
144
|
+
# 获取一条记录,将记录合并在一起
|
|
145
|
+
temp_df = pd.DataFrame(self.data, columns=self.fields)
|
|
146
|
+
df = df.append(temp_df, ignore_index=True)
|
|
147
|
+
self.cur_row_num = len(self.data)
|
|
148
|
+
return df
|
|
149
|
+
|
|
150
|
+
def setData(self, receive_data):
|
|
151
|
+
"""对返回数据进行处理,将string转为list类型
|
|
152
|
+
@return: 返回处理后的list类型数据
|
|
153
|
+
"""
|
|
154
|
+
if receive_data.strip() != "":
|
|
155
|
+
# 先将数据分割,再进行合并,为了防止数据中间有换行等空字符,导致json.loads报错
|
|
156
|
+
receive_array = receive_data.split()
|
|
157
|
+
js_data = json.loads("".join(receive_array)) # dict
|
|
158
|
+
self.data = js_data['record'] # list
|
|
159
|
+
else:
|
|
160
|
+
self.data = []
|
|
161
|
+
|
|
162
|
+
def setFields(self, receive_fields):
|
|
163
|
+
"""对返回数据的指标参数进行处理,将string中的空格去除
|
|
164
|
+
@return: 返回去除空格后的指标参数
|
|
165
|
+
"""
|
|
166
|
+
field_arr = receive_fields.split(cons.ATTRIBUTE_SPLIT)
|
|
167
|
+
i = 0
|
|
168
|
+
while i < len(field_arr):
|
|
169
|
+
# 去除空格
|
|
170
|
+
field_arr[i] = field_arr[i].strip()
|
|
171
|
+
i += 1
|
|
172
|
+
self.fields = field_arr
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class SubscibeData(object):
|
|
176
|
+
def __init__(self):
|
|
177
|
+
"""实时数据初始化方法"""
|
|
178
|
+
|
|
179
|
+
# 消息头
|
|
180
|
+
self.version = cons.BAOSTOCK_CLIENT_VERSION
|
|
181
|
+
self.msg_type = 0 # 消息类型
|
|
182
|
+
self.msg_body_length = 0
|
|
183
|
+
|
|
184
|
+
# 消息体
|
|
185
|
+
self.method = "" # 方法名
|
|
186
|
+
self.user_id = "" # 用户账号
|
|
187
|
+
self.error_code = cons.BSERR_NO_LOGIN # 错误代码
|
|
188
|
+
self.error_msg = "" # 错误代码
|
|
189
|
+
self.msg_body = "" # 消息体
|
|
190
|
+
self.serial_id = None
|
|
191
|
+
|
|
192
|
+
self.subscribe_type = 0 # 订阅方式 0:按证券代码订阅, 1:按行情数据类型订阅
|
|
193
|
+
self.code_list = "" # 证券代码,每只证券代码之间用“英文逗号分隔符”
|
|
194
|
+
self.fncallback = None # 自定义回调方法
|
|
195
|
+
self.options = "" # 预留参数
|
|
196
|
+
self.user_params = None # 用户参数,回调时原样返回
|
|
197
|
+
|
|
198
|
+
self.data = {} # 返回数据类型为字典,以证券代码为key,value为列表保存各项值
|
|
199
|
+
|
|
200
|
+
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import baostock as bs
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
#### 登陆系统 ####
|
|
5
|
+
lg = bs.login()
|
|
6
|
+
# 显示登陆返回信息
|
|
7
|
+
print('login respond error_code:'+lg.error_code)
|
|
8
|
+
print('login respond error_msg:'+lg.error_msg)
|
|
9
|
+
|
|
10
|
+
#### 获取沪深A股历史K线数据 ####
|
|
11
|
+
# 详细指标参数,参见“历史行情指标参数”章节;“分钟线”参数与“日线”参数不同。“分钟线”不包含指数。
|
|
12
|
+
# 分钟线指标:date,time,code,open,high,low,close,volume,amount,adjustflag
|
|
13
|
+
# 周月线指标:date,code,open,high,low,close,volume,amount,adjustflag,turn,pctChg
|
|
14
|
+
rs = bs.query_history_k_data_plus("sh.600000",
|
|
15
|
+
"date,time,code,open,high,low,close,volume,amount,adjustflag",
|
|
16
|
+
start_date='2024-01-01', end_date='2024-12-31',
|
|
17
|
+
frequency="5", adjustflag="2") #frequency="5"取5分钟k线,adjustflag="3"默认不复权,"2"前复权
|
|
18
|
+
|
|
19
|
+
print('query_history_k_data_plus respond error_code:'+rs.error_code)
|
|
20
|
+
print('query_history_k_data_plus respond error_msg:'+rs.error_msg)
|
|
21
|
+
|
|
22
|
+
#### 打印结果集 ####
|
|
23
|
+
data_list = []
|
|
24
|
+
while (rs.error_code == '0') & rs.next():
|
|
25
|
+
# 获取一条记录,将记录合并在一起
|
|
26
|
+
data_list.append(rs.get_row_data())
|
|
27
|
+
result = pd.DataFrame(data_list, columns=rs.fields)
|
|
28
|
+
|
|
29
|
+
#### 结果集输出到csv文件 ####
|
|
30
|
+
result.to_csv("D:\\history_A_stock_5mk_data.csv", index=False)
|
|
31
|
+
print(result)
|
|
32
|
+
|
|
33
|
+
#### 登出系统 ####
|
|
34
|
+
bs.logout()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import baostock as bs
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
#### 登陆系统 ####
|
|
5
|
+
lg = bs.login()
|
|
6
|
+
# 显示登陆返回信息
|
|
7
|
+
print('login respond error_code:'+lg.error_code)
|
|
8
|
+
print('login respond error_msg:'+lg.error_msg)
|
|
9
|
+
|
|
10
|
+
#### 获取历史K线数据 ####
|
|
11
|
+
# 详细指标参数,参见“历史行情指标参数”章节
|
|
12
|
+
# rs = bs.query_history_k_data_plus("sh.600000",
|
|
13
|
+
# "date,code,open,high,low,close,preclose,volume,amount,adjustflag,turn,tradestatus,pctChg,peTTM,pbMRQ,psTTM,pcfNcfTTM,isST",
|
|
14
|
+
# start_date='2025-06-01', end_date='2025-12-31',
|
|
15
|
+
# frequency="d", adjustflag="2") #frequency="d"取日k线,adjustflag="3"默认不复权,"2"前复权
|
|
16
|
+
|
|
17
|
+
rs = bs.query_history_k_data_plus("sz.000024",
|
|
18
|
+
"date,code,open,high,low,close,preclose,volume,amount,adjustflag,turn,tradestatus,pctChg,peTTM,pbMRQ,psTTM,pcfNcfTTM,isST",
|
|
19
|
+
start_date='2015-06-01', end_date='2015-12-31',
|
|
20
|
+
frequency="d", adjustflag="2") #frequency="d"取日k线,adjustflag="3"默认不复权,"2"前复权
|
|
21
|
+
|
|
22
|
+
print('query_history_k_data_plus respond error_code:'+rs.error_code)
|
|
23
|
+
print('query_history_k_data_plus respond error_msg:'+rs.error_msg)
|
|
24
|
+
|
|
25
|
+
#### 打印结果集 ####
|
|
26
|
+
data_list = []
|
|
27
|
+
while (rs.error_code == '0') & rs.next():
|
|
28
|
+
# 获取一条记录,将记录合并在一起
|
|
29
|
+
data_list.append(rs.get_row_data())
|
|
30
|
+
result = pd.DataFrame(data_list, columns=rs.fields)
|
|
31
|
+
#### 结果集输出到csv文件 ####
|
|
32
|
+
result.to_csv("D:/history_k_data.csv", encoding="gbk", index=False)
|
|
33
|
+
print(result)
|
|
34
|
+
|
|
35
|
+
#### 登出系统 ####
|
|
36
|
+
bs.logout()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import baostock as bs
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
#### 登陆系统 ####
|
|
5
|
+
lg = bs.login()
|
|
6
|
+
# 显示登陆返回信息
|
|
7
|
+
print('login respond error_code:'+lg.error_code)
|
|
8
|
+
print('login respond error_msg:'+lg.error_msg)
|
|
9
|
+
|
|
10
|
+
#### 获取证券信息 ####
|
|
11
|
+
rs = bs.query_all_stock(day="2024-11-18")
|
|
12
|
+
print('query_all_stock respond error_code:'+rs.error_code)
|
|
13
|
+
print('query_all_stock respond error_msg:'+rs.error_msg)
|
|
14
|
+
|
|
15
|
+
#### 打印结果集 ####
|
|
16
|
+
data_list = []
|
|
17
|
+
while (rs.error_code == '0') & rs.next():
|
|
18
|
+
# 获取一条记录,将记录合并在一起
|
|
19
|
+
data_list.append(rs.get_row_data())
|
|
20
|
+
result = pd.DataFrame(data_list, columns=rs.fields)
|
|
21
|
+
|
|
22
|
+
#### 结果集输出到csv文件 ####
|
|
23
|
+
result.to_csv("D:\\all_stock.csv", encoding="gbk", index=False)
|
|
24
|
+
print(result)
|
|
25
|
+
|
|
26
|
+
#### 登出系统 ####
|
|
27
|
+
bs.logout()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import baostock as bs
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
# 登陆系统
|
|
5
|
+
lg = bs.login()
|
|
6
|
+
# 显示登陆返回信息
|
|
7
|
+
print('login respond error_code:'+lg.error_code)
|
|
8
|
+
print('login respond error_msg:'+lg.error_msg)
|
|
9
|
+
|
|
10
|
+
# 偿债能力
|
|
11
|
+
balance_list = []
|
|
12
|
+
rs_balance = bs.query_balance_data(code="sh.600000", year=2024, quarter=2)
|
|
13
|
+
while (rs_balance.error_code == '0') & rs_balance.next():
|
|
14
|
+
balance_list.append(rs_balance.get_row_data())
|
|
15
|
+
result_balance = pd.DataFrame(balance_list, columns=rs_balance.fields)
|
|
16
|
+
# 打印输出
|
|
17
|
+
print(result_balance)
|
|
18
|
+
# 结果集输出到csv文件
|
|
19
|
+
result_balance.to_csv("D:\\balance_data.csv", encoding="gbk", index=False)
|
|
20
|
+
|
|
21
|
+
# 登出系统
|
|
22
|
+
bs.logout()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import baostock as bs
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
# 登陆系统
|
|
5
|
+
lg = bs.login()
|
|
6
|
+
# 显示登陆返回信息
|
|
7
|
+
print('login respond error_code:'+lg.error_code)
|
|
8
|
+
print('login respond error_msg:'+lg.error_msg)
|
|
9
|
+
|
|
10
|
+
# 季频现金流量
|
|
11
|
+
cash_flow_list = []
|
|
12
|
+
rs_cash_flow = bs.query_cash_flow_data(code="sh.600000", year=2024, quarter=2)
|
|
13
|
+
while (rs_cash_flow.error_code == '0') & rs_cash_flow.next():
|
|
14
|
+
cash_flow_list.append(rs_cash_flow.get_row_data())
|
|
15
|
+
result_cash_flow = pd.DataFrame(cash_flow_list, columns=rs_cash_flow.fields)
|
|
16
|
+
# 打印输出
|
|
17
|
+
print(result_cash_flow)
|
|
18
|
+
# 结果集输出到csv文件
|
|
19
|
+
result_cash_flow.to_csv("D:\\cash_flow_data.csv", encoding="gbk", index=False)
|
|
20
|
+
|
|
21
|
+
# 登出系统
|
|
22
|
+
bs.logout()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import baostock as bs
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
#### 登陆系统 ####
|
|
5
|
+
lg = bs.login()
|
|
6
|
+
# 显示登陆返回信息
|
|
7
|
+
print('login respond error_code:'+lg.error_code)
|
|
8
|
+
print('login respond error_msg:'+lg.error_msg)
|
|
9
|
+
|
|
10
|
+
#### 查询除权除息信息####
|
|
11
|
+
# 查询2015年除权除息信息
|
|
12
|
+
rs_list = []
|
|
13
|
+
rs_dividend_2015 = bs.query_dividend_data(code="sh.600000", year="2015", yearType="report")
|
|
14
|
+
while (rs_dividend_2015.error_code == '0') & rs_dividend_2015.next():
|
|
15
|
+
rs_list.append(rs_dividend_2015.get_row_data())
|
|
16
|
+
|
|
17
|
+
# 查询2016年除权除息信息
|
|
18
|
+
rs_dividend_2016 = bs.query_dividend_data(code="sh.600000", year="2016", yearType="report")
|
|
19
|
+
while (rs_dividend_2016.error_code == '0') & rs_dividend_2016.next():
|
|
20
|
+
rs_list.append(rs_dividend_2016.get_row_data())
|
|
21
|
+
|
|
22
|
+
# 查询2017年除权除息信息
|
|
23
|
+
rs_dividend_2017 = bs.query_dividend_data(code="sh.600000", year="2017", yearType="report")
|
|
24
|
+
while (rs_dividend_2017.error_code == '0') & rs_dividend_2017.next():
|
|
25
|
+
rs_list.append(rs_dividend_2017.get_row_data())
|
|
26
|
+
|
|
27
|
+
result_dividend = pd.DataFrame(rs_list, columns=rs_dividend_2017.fields)
|
|
28
|
+
# 打印输出
|
|
29
|
+
print(result_dividend)
|
|
30
|
+
|
|
31
|
+
#### 结果集输出到csv文件 ####
|
|
32
|
+
result_dividend.to_csv("D:\\history_Dividend_data.csv", encoding="gbk",index=False)
|
|
33
|
+
|
|
34
|
+
#### 登出系统 ####
|
|
35
|
+
bs.logout()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import baostock as bs
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
# 登陆系统
|
|
5
|
+
lg = bs.login()
|
|
6
|
+
# 显示登陆返回信息
|
|
7
|
+
print('login respond error_code:'+lg.error_code)
|
|
8
|
+
print('login respond error_msg:'+lg.error_msg)
|
|
9
|
+
|
|
10
|
+
# 查询杜邦指数
|
|
11
|
+
dupont_list = []
|
|
12
|
+
#返回字段:code证券代码、pubDate公司发布财报的日期、statDate财报统计的季度的最后一天, 比如2017-03-31, 2017-06-30、dupontROE净资产收益率
|
|
13
|
+
# dupontAssetStoEquity权益乘数、dupontAssetTurn总资产周转率、dupontPnitoni归属母公司股东的净利润/净利润、dupontNitogr净利润/营业总收入
|
|
14
|
+
# dupontTaxBurden净利润/利润总额、dupontIntburden利润总额/息税前利润、dupontEbittogr息税前利润/营业总收入
|
|
15
|
+
rs_dupont = bs.query_dupont_data(code="sh.600000", year=2024, quarter=2)
|
|
16
|
+
while (rs_dupont.error_code == '0') & rs_dupont.next():
|
|
17
|
+
dupont_list.append(rs_dupont.get_row_data())
|
|
18
|
+
result_profit = pd.DataFrame(dupont_list, columns=rs_dupont.fields)
|
|
19
|
+
# 打印输出
|
|
20
|
+
print(result_profit)
|
|
21
|
+
# 结果集输出到csv文件
|
|
22
|
+
result_profit.to_csv("D:\\dupont_data.csv", encoding="gbk", index=False)
|
|
23
|
+
|
|
24
|
+
# 登出系统
|
|
25
|
+
bs.logout()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import baostock as bs
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
#### 登陆系统 ####
|
|
5
|
+
lg = bs.login()
|
|
6
|
+
# 显示登陆返回信息
|
|
7
|
+
print('login respond error_code:'+lg.error_code)
|
|
8
|
+
print('login respond error_msg:'+lg.error_msg)
|
|
9
|
+
|
|
10
|
+
#### 获取公司业绩预告 ####
|
|
11
|
+
rs_forecast = bs.query_forecast_report("sh.600000", start_date="2010-01-01", end_date="2024-12-31")
|
|
12
|
+
print('query_forecast_reprot respond error_code:'+rs_forecast.error_code)
|
|
13
|
+
print('query_forecast_reprot respond error_msg:'+rs_forecast.error_msg)
|
|
14
|
+
rs_forecast_list = []
|
|
15
|
+
while (rs_forecast.error_code == '0') & rs_forecast.next():
|
|
16
|
+
# 分页查询,将每页信息合并在一起
|
|
17
|
+
rs_forecast_list.append(rs_forecast.get_row_data())
|
|
18
|
+
result_forecast = pd.DataFrame(rs_forecast_list, columns=rs_forecast.fields)
|
|
19
|
+
#### 结果集输出到csv文件 ####
|
|
20
|
+
result_forecast.to_csv("D:\\forecast_report.csv", encoding="gbk", index=False)
|
|
21
|
+
print(result_forecast)
|
|
22
|
+
|
|
23
|
+
#### 登出系统 ####
|
|
24
|
+
bs.logout()
|