Skip to content

Commit

Permalink
Merge pull request #232 from fasiondog/feature/tmpstock
Browse files Browse the repository at this point in the history
fixed 新增的北交所股票类型还是A股
  • Loading branch information
fasiondog committed Apr 18, 2024
2 parents 21bafa8 + 993860e commit 1294944
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 15 deletions.
10 changes: 8 additions & 2 deletions hikyuu/data/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class STOCKTYPE:
BOND = 7 # 其他债券
GEM = 8 # 创业板
START = 9 # 科创板
A_BJ = 11 # 北交所A股


def get_a_stktype_list():
"""获取A股市场证券类型元组,含B股"""
return (STOCKTYPE.A, STOCKTYPE.INDEX, STOCKTYPE.B, STOCKTYPE.GEM, STOCKTYPE.START, STOCKTYPE.A_BJ)


def get_stktype_list(quotations=None):
Expand All @@ -68,13 +74,13 @@ def get_stktype_list(quotations=None):
:return: 股票类别元组
"""
if not quotations:
return (1, 2, 3, 4, 5, 6, 7, 8, 9)
return (1, 2, 3, 4, 5, 6, 7, 8, 9, 11)

result = []
for quotation in quotations:
new_quotation = quotation.lower()
if new_quotation == 'stock':
result += [STOCKTYPE.A, STOCKTYPE.INDEX, STOCKTYPE.B, STOCKTYPE.GEM, STOCKTYPE.START]
result += list(get_a_stktype_list())
elif new_quotation == 'fund':
result += [STOCKTYPE.FUND, STOCKTYPE.ETF]
elif new_quotation == 'bond':
Expand Down
3 changes: 3 additions & 0 deletions hikyuu/data/mysql_upgrade/0014.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE `hku_base`.`stock` set `type`=11 where `marketid`=3;
UPDATE `hku_base`.`coderuletype` set `type`=11 where `marketid`=3;
UPDATE `hku_base`.`version` set `version` = 14;
6 changes: 3 additions & 3 deletions hikyuu/data/pytdx_finance_to_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from hikyuu.data.common import MARKETID, STOCKTYPE, historyfinancialreader
from hikyuu.data.common import MARKETID, STOCKTYPE, historyfinancialreader, get_a_stktype_list
from hikyuu.data.common_mysql import get_marketid
from hikyuu.util import *

Expand All @@ -31,8 +31,8 @@
def pytdx_import_finance_to_mysql(db_connect, pytdx_connect, market):
"""导入公司财务信息"""
marketid = get_marketid(db_connect, market)
sql = "select `stockid`, `marketid`, `code`, `valid`, `type` from `hku_base`.`stock` where marketid={} and type = {} and valid=1"\
.format(marketid, STOCKTYPE.A)
sql = "select `stockid`, `marketid`, `code`, `valid`, `type` from `hku_base`.`stock` where marketid={} and type in {} and valid=1"\
.format(marketid, get_a_stktype_list())

cur = db_connect.cursor()
a = cur.execute(sql)
Expand Down
6 changes: 3 additions & 3 deletions hikyuu/data/pytdx_finance_to_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from hikyuu.data.common import MARKETID, STOCKTYPE, historyfinancialreader
from hikyuu.data.common import MARKETID, STOCKTYPE, historyfinancialreader, get_a_stktype_list
from hikyuu.data.common_sqlite3 import get_marketid, create_database


def pytdx_import_finance_to_sqlite(db_connect, pytdx_connect, market):
"""导入公司财务信息"""
marketid = get_marketid(db_connect, market)
sql = "select stockid, marketid, code, valid, type from stock where marketid={} and type = {} and valid=1"\
.format(marketid, STOCKTYPE.A)
sql = "select stockid, marketid, code, valid, type from stock where marketid={} and type in {} and valid=1"\
.format(marketid, get_a_stktype_list())

cur = db_connect.cursor()
all_list = cur.execute(sql).fetchall()
Expand Down
3 changes: 2 additions & 1 deletion hikyuu/data/pytdx_to_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,9 @@ def import_trans(connect, market, quotations, api, dest_dir, max_days=30, progre
stock_list = get_stock_list(connect, market, quotations)

total = len(stock_list)
a_stktype_list = get_a_stktype_list()
for i, stock in enumerate(stock_list):
if stock[3] == 0 or len(stock[2]) != 6 or stock[4] not in (STOCKTYPE.A, STOCKTYPE.B, STOCKTYPE.GEM):
if stock[3] == 0 or len(stock[2]) != 6 or stock[4] not in a_stktype_list:
if progress:
progress(i, total)
continue
Expand Down
3 changes: 2 additions & 1 deletion hikyuu/data/pytdx_to_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,9 @@ def import_trans(

stock_list = get_stock_list(connect, market, quotations)
total = len(stock_list)
a_stktype_list = get_a_stktype_list()
for i, stock in enumerate(stock_list):
if stock[3] == 0 or len(stock[2]) != 6 or stock[4] not in (STOCKTYPE.A, STOCKTYPE.B, STOCKTYPE.GEM):
if stock[3] == 0 or len(stock[2]) != 6 or stock[4] not in a_stktype_list:
if progress:
progress(i, total)
continue
Expand Down
7 changes: 7 additions & 0 deletions hikyuu/data/sqlite_upgrade/0015.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN TRANSACTION;

UPDATE `Stock` set `type`=11 where `marketid`=3;
UPDATE `CodeRuleType` set `type`=11 where `marketid`=3;
UPDATE `version` set `version` = 15;

COMMIT;
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ vector<HistoryFinanceInfo> MySQLBaseInfoDriver::getHistoryFinance(const string &
vector<HistoryFinanceTable> finances;
con->batchLoad(finances, ((Field("market_code") == market_code) &
(Field("report_date") >= new_start.ymd()) &
Field("report_date") < new_end.ymd()) +
(Field("report_date") < new_end.ymd())) +
ASC("report_date"));
size_t total = finances.size();
result.resize(total);
Expand Down
4 changes: 0 additions & 4 deletions hikyuu_cpp/hikyuu/data_driver/kdata/DoNothingKDataDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ class DoNothingKDataDriver : public KDataDriver {
return std::make_shared<DoNothingKDataDriver>();
}

virtual bool _init() override {
return true;
}

virtual bool isIndexFirst() override {
return true;
}
Expand Down

0 comments on commit 1294944

Please sign in to comment.