forked from wenxingxing/pytdx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rainx#216 from rainx/feature/history-financial-api…
…-support Feature/history financial api support
- Loading branch information
Showing
8 changed files
with
207 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# coding=utf-8 | ||
|
||
from pytdx.parser.base import BaseParser | ||
from pytdx.helper import get_datetime, get_volume, get_price | ||
from collections import OrderedDict | ||
import struct | ||
import six | ||
import sys | ||
|
||
|
||
class GetReportFile(BaseParser): | ||
def setParams(self, filename, offset=0): | ||
pkg = bytearray.fromhex(u'0C 12 34 00 00 00') | ||
# Fom DTGear request.py file | ||
node_size = 0x7530 | ||
raw_data = struct.pack(r"<H2I100s", 0x06B9, | ||
offset, node_size, filename.encode("utf-8")) | ||
raw_data_len = struct.calcsize(r"<H2I100s") | ||
pkg.extend(struct.pack(u"<HH{}s".format(raw_data_len), | ||
raw_data_len, raw_data_len, raw_data)) | ||
self.send_pkg = pkg | ||
|
||
def parseResponse(self, body_buf): | ||
(chunksize, ) = struct.unpack("<I", body_buf[:4]) | ||
|
||
if chunksize > 0: | ||
return { | ||
"chunksize": chunksize, | ||
"chunkdata": body_buf[4:] | ||
} | ||
else: | ||
return { | ||
"chunksize": 0 | ||
} | ||
|
||
|
||
if __name__ == "__main__": | ||
from pytdx.hq import TdxHq_API | ||
api = TdxHq_API() | ||
api.need_setup = False | ||
# calc.tdx.com.cn, calc2.tdx.com.cn | ||
with api.connect(ip="120.76.152.87"): | ||
# response = api.get_report_file(r"tdxfin/gpcw19980630.zip", 386003) | ||
content = api.get_report_file_by_size("tdxfin/gpcw.txt") | ||
# content = api.get_report_file_by_size("tdxfin/gpcw19980630.zip", 386073) | ||
print(content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
import pandas as pd | ||
from pytdx.crawler.base_crawler import demo_reporthook | ||
from pytdx.crawler.history_financial_crawler import HistoryFinancialListCrawler | ||
|
||
def test_crawl_history_financial_list_via_tcp(): | ||
|
||
crawler = HistoryFinancialListCrawler() | ||
|
||
list_data = crawler.fetch_and_parse(reporthook=demo_reporthook) | ||
df = pd.DataFrame(data=list_data) | ||
assert df["filename"].str.contains("gpcw20190630.zip").any() | ||
|
||
def test_crawl_history_financial_list_via_http(): | ||
# via yutianst's http server | ||
crawler = HistoryFinancialListCrawler() | ||
crawler.mode = "http" | ||
|
||
list_data = crawler.fetch_and_parse(reporthook=demo_reporthook) | ||
df = pd.DataFrame(data=list_data) | ||
assert df["filename"].str.contains("gpcw20190630.zip").any() |