@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.
Files changed (302) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +5 -4
  3. package/THIRD_PARTY_NOTICES.md +16 -0
  4. package/automation/package.json +1 -1
  5. package/chart-ui/package.json +1 -1
  6. package/config/package.json +1 -1
  7. package/lib/collector-runtime.js +56 -1
  8. package/lib/data-collector/catalog-taxonomy.d.ts +1 -1
  9. package/lib/data-collector/catalog-taxonomy.js +33 -0
  10. package/lib/data-collector/tools.js +7 -7
  11. package/lib/host-version.d.ts +9 -0
  12. package/lib/host-version.js +57 -0
  13. package/lib/python-runtime/errors.d.ts +1 -1
  14. package/lib/python-runtime/errors.js +2 -0
  15. package/lib/python-runtime/manager.d.ts +28 -1
  16. package/lib/python-runtime/manager.js +141 -5
  17. package/lib/python-runtime/probe.d.ts +24 -0
  18. package/lib/python-runtime/probe.js +66 -50
  19. package/lib/runtime-entry.js +8 -0
  20. package/lib/sources/csindex-http.d.ts +4 -0
  21. package/lib/sources/csindex-http.js +233 -0
  22. package/lib/sources/eastmoney-http.js +1504 -1
  23. package/lib/sources/fuyao-rest.js +168 -8
  24. package/lib/sources/official-http.d.ts +4 -0
  25. package/lib/sources/official-http.js +477 -0
  26. package/lib/sources/python-remote.d.ts +25 -0
  27. package/lib/sources/python-remote.js +461 -0
  28. package/lib/sources/sina-http.d.ts +2 -0
  29. package/lib/sources/sina-http.js +484 -0
  30. package/lib/sources/tencent-http.js +23 -8
  31. package/lib/sources/ths-http.d.ts +2 -0
  32. package/lib/sources/ths-http.js +514 -0
  33. package/lib/time/tools.js +19 -0
  34. package/lib/web-retriever/local-fetch.d.ts +1 -1
  35. package/lib/web-retriever/local-fetch.js +1 -1
  36. package/lib/web-retriever/sources.d.ts +7 -0
  37. package/lib/web-retriever/sources.js +46 -21
  38. package/lib/web-retriever/throttle.d.ts +8 -0
  39. package/lib/web-retriever/throttle.js +13 -0
  40. package/lib/web-retriever/tools.js +1 -1
  41. package/lib/web-retriever/wind-client.d.ts +1 -1
  42. package/lib/web-retriever/wind-client.js +1 -1
  43. package/package.json +6 -3
  44. package/preset/capital-generation/agent.patch.yml +7 -5
  45. package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +16 -16
  46. package/python/scripts/baostock_stock_basic.py +129 -0
  47. package/python/scripts/baostock_valuation_history.py +141 -0
  48. package/python/scripts/pbc_social_financing.py +291 -0
  49. package/python/vendor/baostock/LICENSE +19 -0
  50. package/python/vendor/baostock/__init__.py +42 -0
  51. package/python/vendor/baostock/common/__init__.py +0 -0
  52. package/python/vendor/baostock/common/contants.py +189 -0
  53. package/python/vendor/baostock/common/context.py +4 -0
  54. package/python/vendor/baostock/corpreport/__init__.py +0 -0
  55. package/python/vendor/baostock/corpreport/corp_performance.py +202 -0
  56. package/python/vendor/baostock/data/__init__.py +0 -0
  57. package/python/vendor/baostock/data/messageheader.py +17 -0
  58. package/python/vendor/baostock/data/msg.py +21 -0
  59. package/python/vendor/baostock/data/resultset.py +200 -0
  60. package/python/vendor/baostock/demo/__init__.py +0 -0
  61. package/python/vendor/baostock/demo/demo_A_stock_5mk-data.py +34 -0
  62. package/python/vendor/baostock/demo/demo_A_stock_k_data.py +36 -0
  63. package/python/vendor/baostock/demo/demo_AllStock.py +27 -0
  64. package/python/vendor/baostock/demo/demo_Balance_data.py +22 -0
  65. package/python/vendor/baostock/demo/demo_CashFlow_data.py +22 -0
  66. package/python/vendor/baostock/demo/demo_Dividend_data.py +35 -0
  67. package/python/vendor/baostock/demo/demo_Dupont_data.py +25 -0
  68. package/python/vendor/baostock/demo/demo_Forecast_report.py +24 -0
  69. package/python/vendor/baostock/demo/demo_Growth_data.py +22 -0
  70. package/python/vendor/baostock/demo/demo_Index_k_data.py +39 -0
  71. package/python/vendor/baostock/demo/demo_Operation_data.py +22 -0
  72. package/python/vendor/baostock/demo/demo_PerformanceExpress_report.py +25 -0
  73. package/python/vendor/baostock/demo/demo_Profit_data.py +22 -0
  74. package/python/vendor/baostock/demo/demo_TradeDates.py +27 -0
  75. package/python/vendor/baostock/demo/demo_adjust_factor_data.py +23 -0
  76. package/python/vendor/baostock/demo/demo_assignDayData.py +23 -0
  77. package/python/vendor/baostock/demo/demo_daily_adjust_factor_data.py +28 -0
  78. package/python/vendor/baostock/demo/demo_daily_k_4_AStock.py +28 -0
  79. package/python/vendor/baostock/demo/demo_daily_k_4_ETF.py +28 -0
  80. package/python/vendor/baostock/demo/demo_depositRate_data.py +26 -0
  81. package/python/vendor/baostock/demo/demo_hs300_stocks.py +26 -0
  82. package/python/vendor/baostock/demo/demo_loanRate_data.py +26 -0
  83. package/python/vendor/baostock/demo/demo_moneySupplyDataMonth_data.py +26 -0
  84. package/python/vendor/baostock/demo/demo_moneySupplyDataYear_data.py +26 -0
  85. package/python/vendor/baostock/demo/demo_requiredReserveRatio_data.py +26 -0
  86. package/python/vendor/baostock/demo/demo_set_API_key.py +37 -0
  87. package/python/vendor/baostock/demo/demo_stockBasic_data.py +27 -0
  88. package/python/vendor/baostock/demo/demo_stock_Valuation_indicator_data.py +34 -0
  89. package/python/vendor/baostock/demo/demo_stock_industry.py +26 -0
  90. package/python/vendor/baostock/demo/demo_sz50stocks.py +26 -0
  91. package/python/vendor/baostock/demo/demo_zz500_stock.py +26 -0
  92. package/python/vendor/baostock/evaluation/__init__.py +0 -0
  93. package/python/vendor/baostock/evaluation/season_index.py +758 -0
  94. package/python/vendor/baostock/login/__init__.py +0 -0
  95. package/python/vendor/baostock/login/loginout.py +230 -0
  96. package/python/vendor/baostock/macroscopic/__init__.py +0 -0
  97. package/python/vendor/baostock/macroscopic/economic_data.py +723 -0
  98. package/python/vendor/baostock/metadata/__init__.py +0 -0
  99. package/python/vendor/baostock/metadata/stock_metadata.py +207 -0
  100. package/python/vendor/baostock/security/__init__.py +0 -0
  101. package/python/vendor/baostock/security/history.py +265 -0
  102. package/python/vendor/baostock/security/sectorinfo.py +1024 -0
  103. package/python/vendor/baostock/util/__init__.py +0 -0
  104. package/python/vendor/baostock/util/socketutil.py +97 -0
  105. package/python/vendor/baostock/util/stringutil.py +83 -0
  106. package/python/vendor/et_xmlfile/LICENSE +23 -0
  107. package/python/vendor/et_xmlfile/LICENSE.python +298 -0
  108. package/python/vendor/et_xmlfile/__init__.py +8 -0
  109. package/python/vendor/et_xmlfile/incremental_tree.py +917 -0
  110. package/python/vendor/et_xmlfile/xmlfile.py +158 -0
  111. package/python/vendor/openpyxl/LICENSE +23 -0
  112. package/python/vendor/openpyxl/__init__.py +19 -0
  113. package/python/vendor/openpyxl/_constants.py +13 -0
  114. package/python/vendor/openpyxl/cell/__init__.py +4 -0
  115. package/python/vendor/openpyxl/cell/_writer.py +136 -0
  116. package/python/vendor/openpyxl/cell/cell.py +332 -0
  117. package/python/vendor/openpyxl/cell/read_only.py +136 -0
  118. package/python/vendor/openpyxl/cell/rich_text.py +202 -0
  119. package/python/vendor/openpyxl/cell/text.py +184 -0
  120. package/python/vendor/openpyxl/chart/_3d.py +105 -0
  121. package/python/vendor/openpyxl/chart/__init__.py +19 -0
  122. package/python/vendor/openpyxl/chart/_chart.py +199 -0
  123. package/python/vendor/openpyxl/chart/area_chart.py +106 -0
  124. package/python/vendor/openpyxl/chart/axis.py +401 -0
  125. package/python/vendor/openpyxl/chart/bar_chart.py +144 -0
  126. package/python/vendor/openpyxl/chart/bubble_chart.py +67 -0
  127. package/python/vendor/openpyxl/chart/chartspace.py +195 -0
  128. package/python/vendor/openpyxl/chart/data_source.py +246 -0
  129. package/python/vendor/openpyxl/chart/descriptors.py +43 -0
  130. package/python/vendor/openpyxl/chart/error_bar.py +62 -0
  131. package/python/vendor/openpyxl/chart/label.py +127 -0
  132. package/python/vendor/openpyxl/chart/layout.py +74 -0
  133. package/python/vendor/openpyxl/chart/legend.py +75 -0
  134. package/python/vendor/openpyxl/chart/line_chart.py +129 -0
  135. package/python/vendor/openpyxl/chart/marker.py +90 -0
  136. package/python/vendor/openpyxl/chart/picture.py +35 -0
  137. package/python/vendor/openpyxl/chart/pie_chart.py +177 -0
  138. package/python/vendor/openpyxl/chart/pivot.py +65 -0
  139. package/python/vendor/openpyxl/chart/plotarea.py +162 -0
  140. package/python/vendor/openpyxl/chart/print_settings.py +57 -0
  141. package/python/vendor/openpyxl/chart/radar_chart.py +55 -0
  142. package/python/vendor/openpyxl/chart/reader.py +32 -0
  143. package/python/vendor/openpyxl/chart/reference.py +124 -0
  144. package/python/vendor/openpyxl/chart/scatter_chart.py +53 -0
  145. package/python/vendor/openpyxl/chart/series.py +197 -0
  146. package/python/vendor/openpyxl/chart/series_factory.py +41 -0
  147. package/python/vendor/openpyxl/chart/shapes.py +89 -0
  148. package/python/vendor/openpyxl/chart/stock_chart.py +54 -0
  149. package/python/vendor/openpyxl/chart/surface_chart.py +119 -0
  150. package/python/vendor/openpyxl/chart/text.py +78 -0
  151. package/python/vendor/openpyxl/chart/title.py +76 -0
  152. package/python/vendor/openpyxl/chart/trendline.py +98 -0
  153. package/python/vendor/openpyxl/chart/updown_bars.py +31 -0
  154. package/python/vendor/openpyxl/chartsheet/__init__.py +3 -0
  155. package/python/vendor/openpyxl/chartsheet/chartsheet.py +107 -0
  156. package/python/vendor/openpyxl/chartsheet/custom.py +61 -0
  157. package/python/vendor/openpyxl/chartsheet/properties.py +28 -0
  158. package/python/vendor/openpyxl/chartsheet/protection.py +41 -0
  159. package/python/vendor/openpyxl/chartsheet/publish.py +58 -0
  160. package/python/vendor/openpyxl/chartsheet/relation.py +97 -0
  161. package/python/vendor/openpyxl/chartsheet/views.py +51 -0
  162. package/python/vendor/openpyxl/comments/__init__.py +4 -0
  163. package/python/vendor/openpyxl/comments/author.py +21 -0
  164. package/python/vendor/openpyxl/comments/comment_sheet.py +211 -0
  165. package/python/vendor/openpyxl/comments/comments.py +62 -0
  166. package/python/vendor/openpyxl/comments/shape_writer.py +112 -0
  167. package/python/vendor/openpyxl/compat/__init__.py +54 -0
  168. package/python/vendor/openpyxl/compat/abc.py +8 -0
  169. package/python/vendor/openpyxl/compat/numbers.py +43 -0
  170. package/python/vendor/openpyxl/compat/product.py +17 -0
  171. package/python/vendor/openpyxl/compat/singleton.py +40 -0
  172. package/python/vendor/openpyxl/compat/strings.py +25 -0
  173. package/python/vendor/openpyxl/descriptors/__init__.py +58 -0
  174. package/python/vendor/openpyxl/descriptors/base.py +272 -0
  175. package/python/vendor/openpyxl/descriptors/container.py +41 -0
  176. package/python/vendor/openpyxl/descriptors/excel.py +112 -0
  177. package/python/vendor/openpyxl/descriptors/namespace.py +12 -0
  178. package/python/vendor/openpyxl/descriptors/nested.py +129 -0
  179. package/python/vendor/openpyxl/descriptors/sequence.py +136 -0
  180. package/python/vendor/openpyxl/descriptors/serialisable.py +240 -0
  181. package/python/vendor/openpyxl/descriptors/slots.py +18 -0
  182. package/python/vendor/openpyxl/drawing/__init__.py +4 -0
  183. package/python/vendor/openpyxl/drawing/colors.py +435 -0
  184. package/python/vendor/openpyxl/drawing/connector.py +144 -0
  185. package/python/vendor/openpyxl/drawing/drawing.py +92 -0
  186. package/python/vendor/openpyxl/drawing/effect.py +407 -0
  187. package/python/vendor/openpyxl/drawing/fill.py +425 -0
  188. package/python/vendor/openpyxl/drawing/geometry.py +584 -0
  189. package/python/vendor/openpyxl/drawing/graphic.py +177 -0
  190. package/python/vendor/openpyxl/drawing/image.py +65 -0
  191. package/python/vendor/openpyxl/drawing/line.py +144 -0
  192. package/python/vendor/openpyxl/drawing/picture.py +144 -0
  193. package/python/vendor/openpyxl/drawing/properties.py +174 -0
  194. package/python/vendor/openpyxl/drawing/relation.py +17 -0
  195. package/python/vendor/openpyxl/drawing/spreadsheet_drawing.py +382 -0
  196. package/python/vendor/openpyxl/drawing/text.py +717 -0
  197. package/python/vendor/openpyxl/drawing/xdr.py +33 -0
  198. package/python/vendor/openpyxl/formatting/__init__.py +3 -0
  199. package/python/vendor/openpyxl/formatting/formatting.py +114 -0
  200. package/python/vendor/openpyxl/formatting/rule.py +291 -0
  201. package/python/vendor/openpyxl/formula/__init__.py +3 -0
  202. package/python/vendor/openpyxl/formula/tokenizer.py +446 -0
  203. package/python/vendor/openpyxl/formula/translate.py +166 -0
  204. package/python/vendor/openpyxl/packaging/__init__.py +3 -0
  205. package/python/vendor/openpyxl/packaging/core.py +115 -0
  206. package/python/vendor/openpyxl/packaging/custom.py +289 -0
  207. package/python/vendor/openpyxl/packaging/extended.py +137 -0
  208. package/python/vendor/openpyxl/packaging/interface.py +56 -0
  209. package/python/vendor/openpyxl/packaging/manifest.py +194 -0
  210. package/python/vendor/openpyxl/packaging/relationship.py +158 -0
  211. package/python/vendor/openpyxl/packaging/workbook.py +185 -0
  212. package/python/vendor/openpyxl/pivot/__init__.py +1 -0
  213. package/python/vendor/openpyxl/pivot/cache.py +965 -0
  214. package/python/vendor/openpyxl/pivot/fields.py +326 -0
  215. package/python/vendor/openpyxl/pivot/record.py +111 -0
  216. package/python/vendor/openpyxl/pivot/table.py +1261 -0
  217. package/python/vendor/openpyxl/reader/__init__.py +1 -0
  218. package/python/vendor/openpyxl/reader/drawings.py +71 -0
  219. package/python/vendor/openpyxl/reader/excel.py +349 -0
  220. package/python/vendor/openpyxl/reader/strings.py +44 -0
  221. package/python/vendor/openpyxl/reader/workbook.py +133 -0
  222. package/python/vendor/openpyxl/styles/__init__.py +11 -0
  223. package/python/vendor/openpyxl/styles/alignment.py +62 -0
  224. package/python/vendor/openpyxl/styles/borders.py +103 -0
  225. package/python/vendor/openpyxl/styles/builtins.py +1397 -0
  226. package/python/vendor/openpyxl/styles/cell_style.py +206 -0
  227. package/python/vendor/openpyxl/styles/colors.py +172 -0
  228. package/python/vendor/openpyxl/styles/differential.py +95 -0
  229. package/python/vendor/openpyxl/styles/fills.py +224 -0
  230. package/python/vendor/openpyxl/styles/fonts.py +113 -0
  231. package/python/vendor/openpyxl/styles/named_styles.py +282 -0
  232. package/python/vendor/openpyxl/styles/numbers.py +200 -0
  233. package/python/vendor/openpyxl/styles/protection.py +17 -0
  234. package/python/vendor/openpyxl/styles/proxy.py +62 -0
  235. package/python/vendor/openpyxl/styles/styleable.py +151 -0
  236. package/python/vendor/openpyxl/styles/stylesheet.py +274 -0
  237. package/python/vendor/openpyxl/styles/table.py +94 -0
  238. package/python/vendor/openpyxl/utils/__init__.py +17 -0
  239. package/python/vendor/openpyxl/utils/bound_dictionary.py +26 -0
  240. package/python/vendor/openpyxl/utils/cell.py +240 -0
  241. package/python/vendor/openpyxl/utils/dataframe.py +87 -0
  242. package/python/vendor/openpyxl/utils/datetime.py +140 -0
  243. package/python/vendor/openpyxl/utils/escape.py +43 -0
  244. package/python/vendor/openpyxl/utils/exceptions.py +34 -0
  245. package/python/vendor/openpyxl/utils/formulas.py +24 -0
  246. package/python/vendor/openpyxl/utils/indexed_list.py +49 -0
  247. package/python/vendor/openpyxl/utils/inference.py +60 -0
  248. package/python/vendor/openpyxl/utils/protection.py +22 -0
  249. package/python/vendor/openpyxl/utils/units.py +108 -0
  250. package/python/vendor/openpyxl/workbook/__init__.py +4 -0
  251. package/python/vendor/openpyxl/workbook/_writer.py +197 -0
  252. package/python/vendor/openpyxl/workbook/child.py +166 -0
  253. package/python/vendor/openpyxl/workbook/defined_name.py +189 -0
  254. package/python/vendor/openpyxl/workbook/external_link/__init__.py +3 -0
  255. package/python/vendor/openpyxl/workbook/external_link/external.py +190 -0
  256. package/python/vendor/openpyxl/workbook/external_reference.py +18 -0
  257. package/python/vendor/openpyxl/workbook/function_group.py +36 -0
  258. package/python/vendor/openpyxl/workbook/properties.py +151 -0
  259. package/python/vendor/openpyxl/workbook/protection.py +163 -0
  260. package/python/vendor/openpyxl/workbook/smart_tags.py +56 -0
  261. package/python/vendor/openpyxl/workbook/views.py +155 -0
  262. package/python/vendor/openpyxl/workbook/web.py +98 -0
  263. package/python/vendor/openpyxl/workbook/workbook.py +438 -0
  264. package/python/vendor/openpyxl/worksheet/__init__.py +1 -0
  265. package/python/vendor/openpyxl/worksheet/_read_only.py +190 -0
  266. package/python/vendor/openpyxl/worksheet/_reader.py +472 -0
  267. package/python/vendor/openpyxl/worksheet/_write_only.py +160 -0
  268. package/python/vendor/openpyxl/worksheet/_writer.py +390 -0
  269. package/python/vendor/openpyxl/worksheet/cell_range.py +512 -0
  270. package/python/vendor/openpyxl/worksheet/cell_watch.py +34 -0
  271. package/python/vendor/openpyxl/worksheet/controls.py +107 -0
  272. package/python/vendor/openpyxl/worksheet/copier.py +70 -0
  273. package/python/vendor/openpyxl/worksheet/custom.py +35 -0
  274. package/python/vendor/openpyxl/worksheet/datavalidation.py +202 -0
  275. package/python/vendor/openpyxl/worksheet/dimensions.py +306 -0
  276. package/python/vendor/openpyxl/worksheet/drawing.py +14 -0
  277. package/python/vendor/openpyxl/worksheet/errors.py +93 -0
  278. package/python/vendor/openpyxl/worksheet/filters.py +486 -0
  279. package/python/vendor/openpyxl/worksheet/formula.py +51 -0
  280. package/python/vendor/openpyxl/worksheet/header_footer.py +270 -0
  281. package/python/vendor/openpyxl/worksheet/hyperlink.py +46 -0
  282. package/python/vendor/openpyxl/worksheet/merge.py +141 -0
  283. package/python/vendor/openpyxl/worksheet/ole.py +133 -0
  284. package/python/vendor/openpyxl/worksheet/page.py +174 -0
  285. package/python/vendor/openpyxl/worksheet/pagebreak.py +94 -0
  286. package/python/vendor/openpyxl/worksheet/picture.py +8 -0
  287. package/python/vendor/openpyxl/worksheet/print_settings.py +184 -0
  288. package/python/vendor/openpyxl/worksheet/properties.py +97 -0
  289. package/python/vendor/openpyxl/worksheet/protection.py +120 -0
  290. package/python/vendor/openpyxl/worksheet/related.py +17 -0
  291. package/python/vendor/openpyxl/worksheet/scenario.py +105 -0
  292. package/python/vendor/openpyxl/worksheet/smart_tag.py +78 -0
  293. package/python/vendor/openpyxl/worksheet/table.py +385 -0
  294. package/python/vendor/openpyxl/worksheet/views.py +155 -0
  295. package/python/vendor/openpyxl/worksheet/worksheet.py +907 -0
  296. package/python/vendor/openpyxl/writer/__init__.py +1 -0
  297. package/python/vendor/openpyxl/writer/excel.py +295 -0
  298. package/python/vendor/openpyxl/writer/theme.py +291 -0
  299. package/python/vendor/openpyxl/xml/__init__.py +42 -0
  300. package/python/vendor/openpyxl/xml/constants.py +129 -0
  301. package/python/vendor/openpyxl/xml/functions.py +87 -0
  302. package/watchlist/package.json +1 -1
File without changes
@@ -0,0 +1,207 @@
1
+ # -*- coding:utf-8 -*-
2
+ """
3
+ 证券系统元方法,如获取交易日等
4
+ """
5
+ import time
6
+ import zlib
7
+ import baostock.data.resultset as rs
8
+ import baostock.common.contants as cons
9
+ import baostock.util.stringutil as strUtil
10
+ import baostock.common.context as conx
11
+ import baostock.util.socketutil as sock
12
+ import baostock.data.messageheader as msgheader
13
+
14
+
15
+ def query_trade_dates(start_date=None, end_date=None):
16
+ """查询出给定范围的交易日信息
17
+
18
+ @param start_date: 起始日期,默认2015-01-01
19
+ @param end_date: 终止日期,默认当前日期
20
+ @return: calendar_date 日期;is_trading_day,是否交易日,0:非交易日;1:交易日
21
+ """
22
+ data = rs.ResultData()
23
+
24
+ if start_date is None or start_date == "":
25
+ start_date = cons.DEFAULT_START_DATE
26
+ if end_date is None or end_date == "":
27
+ end_date = time.strftime("%Y-%m-%d", time.localtime())
28
+
29
+ user_id = ""
30
+ try:
31
+ user_id = getattr(conx, "user_id")
32
+ except Exception:
33
+ print("you don't login.")
34
+ data.error_code = cons.BSERR_NO_LOGIN
35
+ data.error_msg = "you don't login."
36
+ return data
37
+
38
+ param = "%s,%s,%s,%s,%s,%s" % (
39
+ "query_trade_dates", user_id, "1",
40
+ cons.BAOSTOCK_PER_PAGE_COUNT, start_date, end_date)
41
+
42
+ msg_body = strUtil.organize_msg_body(param)
43
+ msg_header = msgheader.to_message_header(
44
+ cons.MESSAGE_TYPE_QUERYTRADEDATES_REQUEST, len(msg_body))
45
+
46
+ data.msg_type = cons.MESSAGE_TYPE_QUERYTRADEDATES_REQUEST
47
+ data.msg_body = msg_body
48
+
49
+ head_body = msg_header + msg_body
50
+ crc32str = zlib.crc32(bytes(head_body, encoding='utf-8'))
51
+ receive_data = sock.send_msg(head_body + cons.MESSAGE_SPLIT + str(crc32str))
52
+
53
+ if receive_data is None or receive_data.strip() == "":
54
+ data.error_code = cons.BSERR_RECVSOCK_FAIL
55
+ data.error_msg = "网络接收错误。"
56
+ return data
57
+
58
+ msg_header = receive_data[0:cons.MESSAGE_HEADER_LENGTH]
59
+ msg_body = receive_data[cons.MESSAGE_HEADER_LENGTH:-1]
60
+ header_arr = msg_header.split(cons.MESSAGE_SPLIT)
61
+ body_arr = msg_body.split(cons.MESSAGE_SPLIT)
62
+ data.msg_body_length = header_arr[2]
63
+ data.error_code = body_arr[0]
64
+ data.error_msg = body_arr[1]
65
+
66
+ if cons.BSERR_SUCCESS == data.error_code:
67
+ data.method = body_arr[2]
68
+ data.user_id = body_arr[3]
69
+ data.cur_page_num = body_arr[4]
70
+ data.per_page_count = body_arr[5]
71
+ data.setData(body_arr[6])
72
+ data.start_date = body_arr[7]
73
+ data.end_date = body_arr[8]
74
+ data.setFields(body_arr[9])
75
+
76
+ return data
77
+
78
+
79
+ def query_all_stock(day=None):
80
+ """查询给定日期的所有证券信息,
81
+
82
+ @param day: 默认当前日期
83
+ """
84
+ data = rs.ResultData()
85
+
86
+ if day is None or day == "":
87
+ day = time.strftime("%Y-%m-%d", time.localtime())
88
+
89
+ user_id = ""
90
+ try:
91
+ user_id = getattr(conx, "user_id")
92
+ except Exception:
93
+ print("you don't login.")
94
+ data.error_code = cons.BSERR_NO_LOGIN
95
+ data.error_msg = "you don't login."
96
+ return data
97
+
98
+ param = "%s,%s,%s,%s,%s" % (
99
+ "query_all_stock", user_id, "1",
100
+ cons.BAOSTOCK_PER_PAGE_COUNT, day)
101
+
102
+ msg_body = strUtil.organize_msg_body(param)
103
+ msg_header = msgheader.to_message_header(
104
+ cons.MESSAGE_TYPE_QUERYALLSTOCK_REQUEST, len(msg_body))
105
+
106
+ data.msg_type = cons.MESSAGE_TYPE_QUERYALLSTOCK_REQUEST
107
+ data.msg_body = msg_body
108
+
109
+ head_body = msg_header + msg_body
110
+ crc32str = zlib.crc32(bytes(head_body, encoding='utf-8'))
111
+ receive_data = sock.send_msg(head_body + cons.MESSAGE_SPLIT + str(crc32str))
112
+
113
+ if receive_data is None or receive_data.strip() == "":
114
+ data.error_code = cons.BSERR_RECVSOCK_FAIL
115
+ data.error_msg = "网络接收错误。"
116
+ return data
117
+
118
+ msg_header = receive_data[0:cons.MESSAGE_HEADER_LENGTH]
119
+ msg_body = receive_data[cons.MESSAGE_HEADER_LENGTH:-1]
120
+ header_arr = msg_header.split(cons.MESSAGE_SPLIT)
121
+ body_arr = msg_body.split(cons.MESSAGE_SPLIT)
122
+ data.msg_body_length = header_arr[2]
123
+ data.error_code = body_arr[0]
124
+ data.error_msg = body_arr[1]
125
+
126
+ if cons.BSERR_SUCCESS == data.error_code:
127
+ data.method = body_arr[2]
128
+ data.user_id = body_arr[3]
129
+ data.cur_page_num = body_arr[4]
130
+ data.per_page_count = body_arr[5]
131
+ data.setData(body_arr[6])
132
+ data.day = body_arr[7]
133
+ data.setFields(body_arr[8])
134
+
135
+ return data
136
+
137
+
138
+ def query_stock_basic(code="", code_name=""):
139
+ """A股证券基本资料
140
+ @param code: 证券代码,可为空
141
+ @param code_name: 证券名称,可为空,支持模糊查询
142
+ """
143
+ data = rs.ResultData()
144
+
145
+ if code is None or code == "":
146
+ code = ""
147
+ if code != "" and code is not None:
148
+ if len(code) != cons.STOCK_CODE_LENGTH:
149
+ print("股票代码应为" + str(cons.STOCK_CODE_LENGTH) + "位,请检查。格式示例:sh.600000。")
150
+ data.error_msg = "股票代码应为" + str(cons.STOCK_CODE_LENGTH) + "位,请检查。格式示例:sh.600000。"
151
+ data.error_code = cons.BSERR_PARAM_ERR
152
+ return data
153
+ code = code.lower()
154
+ if (code.endswith("sh") or code.endswith("sz")):
155
+ code = code[7:9].lower() + "." + code[0:6]
156
+
157
+ if code_name is None or code_name == "":
158
+ code_name = ""
159
+
160
+ user_id = ""
161
+ try:
162
+ user_id = getattr(conx, "user_id")
163
+ except Exception:
164
+ print("you don't login.")
165
+ data.error_code = cons.BSERR_NO_LOGIN
166
+ data.error_msg = "you don't login."
167
+ return data
168
+
169
+ param = "query_stock_basic," + str(user_id) + ",1," + \
170
+ str(cons.BAOSTOCK_PER_PAGE_COUNT) + \
171
+ "," + str(code) + "," + str(code_name)
172
+
173
+ msg_body = strUtil.organize_msg_body(param)
174
+ msg_header = msgheader.to_message_header(
175
+ cons.MESSAGE_TYPE_QUERYSTOCKBASIC_REQUEST, len(msg_body))
176
+
177
+ data.msg_type = cons.MESSAGE_TYPE_QUERYSTOCKBASIC_REQUEST
178
+ data.msg_body = msg_body
179
+
180
+ head_body = msg_header + msg_body
181
+ crc32str = zlib.crc32(bytes(head_body, encoding='utf-8'))
182
+ receive_data = sock.send_msg(head_body + cons.MESSAGE_SPLIT + str(crc32str))
183
+
184
+ if receive_data is None or receive_data.strip() == "":
185
+ data.error_code = cons.BSERR_RECVSOCK_FAIL
186
+ data.error_msg = "网络接收错误。"
187
+ return data
188
+
189
+ msg_header = receive_data[0:cons.MESSAGE_HEADER_LENGTH]
190
+ msg_body = receive_data[cons.MESSAGE_HEADER_LENGTH:-1]
191
+ header_arr = msg_header.split(cons.MESSAGE_SPLIT)
192
+ body_arr = msg_body.split(cons.MESSAGE_SPLIT)
193
+ data.msg_body_length = header_arr[2]
194
+ data.error_code = body_arr[0]
195
+ data.error_msg = body_arr[1]
196
+
197
+ if cons.BSERR_SUCCESS == data.error_code:
198
+ data.method = body_arr[2]
199
+ data.user_id = body_arr[3]
200
+ data.cur_page_num = body_arr[4]
201
+ data.per_page_count = body_arr[5]
202
+ data.setData(body_arr[6])
203
+ data.code = body_arr[7]
204
+ data.code_name = body_arr[8]
205
+ data.setFields(body_arr[9])
206
+
207
+ return data
File without changes
@@ -0,0 +1,265 @@
1
+ # -*- coding:utf-8 -*-
2
+ """
3
+ 获取历史行情
4
+ @author: baostock.com
5
+ @group : baostock.com
6
+ @contact: baostock@163.com
7
+ """
8
+ import datetime
9
+ import time
10
+ import zlib
11
+
12
+ import baostock.common.contants as cons
13
+ import baostock.common.context as conx
14
+ import baostock.data.messageheader as msgheader
15
+ import baostock.data.resultset as rs
16
+ import baostock.util.socketutil as sock
17
+ import baostock.util.stringutil as strUtil
18
+
19
+
20
+ def query_history_k_data_plus(code, fields, start_date=None, end_date=None,
21
+ frequency='d', adjustflag='3'):
22
+ """获取历史K线plus"""
23
+ return __query_history_k_data_plus_page(1, cons.BAOSTOCK_PER_PAGE_COUNT, code, fields, start_date,
24
+ end_date, frequency, adjustflag)
25
+
26
+
27
+ def __query_history_k_data_plus_page(cur_page_num, per_page_count, code, fields,
28
+ start_date, end_date, frequency, adjustflag):
29
+ """获取历史K线,私有方法"""
30
+ data = rs.ResultData()
31
+ if code is None or code == "":
32
+ print("股票代码不能为空,请检查。")
33
+ data.error_msg = "股票代码不能为空,请检查。"
34
+ data.error_code = cons.BSERR_PARAM_ERR
35
+ return data
36
+ if len(code) != cons.STOCK_CODE_LENGTH:
37
+ print("股票代码应为" + str(cons.STOCK_CODE_LENGTH) + "位,请检查。格式示例:sh.600000。")
38
+ data.error_msg = "股票代码应为" + str(cons.STOCK_CODE_LENGTH) + "位,请检查。格式示例:sh.600000。"
39
+ data.error_code = cons.BSERR_PARAM_ERR
40
+ return data
41
+ code = code.lower()
42
+ if (code.endswith("sh") or code.endswith("sz")):
43
+ code = code[7:9].lower() + "." + code[0:6]
44
+ if fields is None or fields == "":
45
+ data.error_msg = "指示简称不能为空,请检查。"
46
+ data.error_code = cons.BSERR_PARAM_ERR
47
+ print("指示简称不能为空,请检查。")
48
+ return data
49
+
50
+ if start_date is None or start_date == "":
51
+ start_date = cons.DEFAULT_START_DATE
52
+ if end_date is None or end_date == "":
53
+ end_date = time.strftime("%Y-%m-%d", time.localtime())
54
+
55
+ if start_date != "" and end_date != "":
56
+ if strUtil.is_valid_date(start_date) and strUtil.is_valid_date(end_date):
57
+ start_date_time = datetime.datetime.strptime(
58
+ start_date, '%Y-%m-%d')
59
+ end_date_time = datetime.datetime.strptime(end_date, '%Y-%m-%d')
60
+ if end_date_time < start_date_time:
61
+ print("起始日期大于终止日期,请修改。")
62
+ data.error_code = cons.BSERR_START_BIGTHAN_END
63
+ data.error_msg = "起始日期大于终止日期,请修改。"
64
+ return data
65
+ else:
66
+ print("日期格式不正确,请修改。")
67
+ return
68
+
69
+ if frequency is None or frequency == "":
70
+ print("数据类型(frequency)不可为空,请检查。")
71
+ data.error_msg = "数据类型(frequency)不可为空,请检查"
72
+ data.error_code = cons.BSERR_PARAM_ERR
73
+ return data
74
+ if adjustflag is None or adjustflag == "":
75
+ print("复权类型(adjustflag)不可为空,请检查。")
76
+ data.error_msg = "复权类型(adjustflag)不可为空,请检查。"
77
+ data.error_code = cons.BSERR_PARAM_ERR
78
+ return data
79
+
80
+ user_id = ""
81
+ try:
82
+ user_id = getattr(conx, "user_id")
83
+ except Exception:
84
+ print("you don't login.")
85
+ data.error_code = cons.BSERR_NO_LOGIN
86
+ data.error_msg = "you don't login."
87
+ return data
88
+
89
+ msg_body = "query_history_k_data_plus" + cons.MESSAGE_SPLIT + user_id + cons.MESSAGE_SPLIT \
90
+ + str(cur_page_num) + cons.MESSAGE_SPLIT + str(per_page_count) + cons.MESSAGE_SPLIT + code \
91
+ + cons.MESSAGE_SPLIT + fields + cons.MESSAGE_SPLIT + start_date \
92
+ + cons.MESSAGE_SPLIT + end_date + cons.MESSAGE_SPLIT + frequency \
93
+ + cons.MESSAGE_SPLIT + adjustflag
94
+
95
+ msg_header = msgheader.to_message_header(
96
+ cons.MESSAGE_TYPE_GETKDATAPLUS_REQUEST, len(msg_body))
97
+
98
+ data.msg_type = cons.MESSAGE_TYPE_GETKDATAPLUS_REQUEST
99
+ data.msg_body = msg_body
100
+
101
+ head_body = msg_header + msg_body
102
+ crc32str = zlib.crc32(bytes(head_body, encoding='utf-8'))
103
+
104
+ receive_data = sock.send_msg(head_body + cons.MESSAGE_SPLIT + str(crc32str))
105
+
106
+ if receive_data is None or receive_data.strip() == "":
107
+ data.error_code = cons.BSERR_RECVSOCK_FAIL
108
+ data.error_msg = "网络接收错误。"
109
+ return data
110
+
111
+ msg_header = receive_data[0:cons.MESSAGE_HEADER_LENGTH]
112
+ msg_body = receive_data[cons.MESSAGE_HEADER_LENGTH:-1]
113
+
114
+ header_arr = msg_header.split(cons.MESSAGE_SPLIT)
115
+ body_arr = msg_body.split(cons.MESSAGE_SPLIT)
116
+
117
+ # data.version = header_arr[0]
118
+ # data.msg_type = header_arr[1]
119
+ data.msg_body_length = header_arr[2]
120
+
121
+ data.error_code = body_arr[0]
122
+ data.error_msg = body_arr[1]
123
+
124
+ if cons.BSERR_SUCCESS == data.error_code:
125
+ data.method = body_arr[2]
126
+ data.user_id = body_arr[3]
127
+ data.cur_page_num = body_arr[4]
128
+ data.per_page_count = body_arr[5]
129
+ data.setData(body_arr[6])
130
+ data.code = body_arr[7]
131
+ data.setFields(body_arr[8])
132
+ data.start_date = body_arr[9]
133
+ data.end_date = body_arr[10]
134
+ data.frequency = body_arr[11]
135
+ data.adjustflag = body_arr[12]
136
+
137
+ return data
138
+
139
+
140
+ def query_daily_history_k_AStock(date=""):
141
+ """获取某日所有股票日K线数据"""
142
+ data = rs.ResultData()
143
+ if date is None or date == "":
144
+ date = time.strftime("%Y-%m-%d", time.localtime())
145
+
146
+ if date != "":
147
+ if strUtil.is_valid_date(date) == False:
148
+ data.error_msg = "日期格式不正确,请修改。"
149
+ data.error_code = cons.BSERR_DATE_ERR
150
+ print("日期格式不正确,请修改。")
151
+ return data
152
+
153
+ user_id = ""
154
+ try:
155
+ user_id = getattr(conx, "user_id")
156
+ except Exception:
157
+ print("you don't login.")
158
+ data.error_code = cons.BSERR_NO_LOGIN
159
+ data.error_msg = "you don't login."
160
+ return data
161
+
162
+ msg_body = "query_daily_history_k_AStock" + cons.MESSAGE_SPLIT + user_id \
163
+ + cons.MESSAGE_SPLIT + date
164
+
165
+ msg_header = msgheader.to_message_header(
166
+ cons.MESSAGE_TYPE_GETKDaily_D_AStock_REQUEST, len(msg_body))
167
+
168
+ data.msg_type = cons.MESSAGE_TYPE_GETKDaily_D_AStock_REQUEST
169
+ data.msg_body = msg_body
170
+
171
+ head_body = msg_header + msg_body
172
+ crc32str = zlib.crc32(bytes(head_body, encoding='utf-8'))
173
+
174
+ receive_data = sock.send_msg(head_body + cons.MESSAGE_SPLIT + str(crc32str))
175
+
176
+ if receive_data is None or receive_data.strip() == "":
177
+ data.error_code = cons.BSERR_RECVSOCK_FAIL
178
+ data.error_msg = "网络接收错误。"
179
+ return data
180
+
181
+ msg_header = receive_data[0:cons.MESSAGE_HEADER_LENGTH]
182
+ msg_body = receive_data[cons.MESSAGE_HEADER_LENGTH:len(receive_data)]
183
+
184
+ header_arr = msg_header.split(cons.MESSAGE_SPLIT)
185
+ body_arr = msg_body.split(cons.MESSAGE_SPLIT)
186
+
187
+ # data.version = header_arr[0]
188
+ # data.msg_type = header_arr[1]
189
+ data.msg_body_length = header_arr[2]
190
+
191
+ data.error_code = body_arr[0]
192
+ data.error_msg = body_arr[1]
193
+
194
+ if cons.BSERR_SUCCESS == data.error_code:
195
+ data.method = body_arr[2]
196
+ data.user_id = body_arr[3]
197
+ data.setData(body_arr[4])
198
+ data.setFields(body_arr[5])
199
+ data.cur_page_num = '1' #起始第一条记录开始
200
+ data.per_page_count = '20000' #当前query_daily_history_k_AStock查询不进行分页查询处理,所有设置一页最多20000条记录。
201
+ return data
202
+
203
+
204
+ def query_daily_history_k_ETF(date=""):
205
+ """获取某日所有ETF日K线数据"""
206
+ data = rs.ResultData()
207
+ if date is None or date == "":
208
+ date = time.strftime("%Y-%m-%d", time.localtime())
209
+
210
+ if date != "":
211
+ if strUtil.is_valid_date(date) == False:
212
+ data.error_msg = "日期格式不正确,请修改。"
213
+ data.error_code = cons.BSERR_DATE_ERR
214
+ print("日期格式不正确,请修改。")
215
+ return data
216
+
217
+ user_id = ""
218
+ try:
219
+ user_id = getattr(conx, "user_id")
220
+ except Exception:
221
+ print("you don't login.")
222
+ data.error_code = cons.BSERR_NO_LOGIN
223
+ data.error_msg = "you don't login."
224
+ return data
225
+
226
+ msg_body = "query_daily_history_k_ETF" + cons.MESSAGE_SPLIT + user_id \
227
+ + cons.MESSAGE_SPLIT + date
228
+
229
+ msg_header = msgheader.to_message_header(
230
+ cons.MESSAGE_TYPE_GETKDaily_D_ETF_REQUEST, len(msg_body))
231
+
232
+ data.msg_type = cons.MESSAGE_TYPE_GETKDaily_D_ETF_REQUEST
233
+ data.msg_body = msg_body
234
+
235
+ head_body = msg_header + msg_body
236
+ crc32str = zlib.crc32(bytes(head_body, encoding='utf-8'))
237
+
238
+ receive_data = sock.send_msg(head_body + cons.MESSAGE_SPLIT + str(crc32str))
239
+
240
+ if receive_data is None or receive_data.strip() == "":
241
+ data.error_code = cons.BSERR_RECVSOCK_FAIL
242
+ data.error_msg = "网络接收错误。"
243
+ return data
244
+
245
+ msg_header = receive_data[0:cons.MESSAGE_HEADER_LENGTH]
246
+ msg_body = receive_data[cons.MESSAGE_HEADER_LENGTH:len(receive_data)]
247
+
248
+ header_arr = msg_header.split(cons.MESSAGE_SPLIT)
249
+ body_arr = msg_body.split(cons.MESSAGE_SPLIT)
250
+
251
+ # data.version = header_arr[0]
252
+ # data.msg_type = header_arr[1]
253
+ data.msg_body_length = header_arr[2]
254
+
255
+ data.error_code = body_arr[0]
256
+ data.error_msg = body_arr[1]
257
+
258
+ if cons.BSERR_SUCCESS == data.error_code:
259
+ data.method = body_arr[2]
260
+ data.user_id = body_arr[3]
261
+ data.setData(body_arr[4])
262
+ data.setFields(body_arr[5])
263
+ data.cur_page_num = '1' #起始第一条记录开始
264
+ data.per_page_count = '20000' #当前query_history_daily_k_ETF查询不进行分页查询处理,所有设置一页最多20000条记录。
265
+ return data