Skip to content

Commit

Permalink
Merge pull request #527 from tauruswang/master
Browse files Browse the repository at this point in the history
quantaxis__db_description
  • Loading branch information
yutiansut authored Jun 4, 2018
2 parents c334339 + 050cda2 commit 2be2dfc
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 4 deletions.
11 changes: 11 additions & 0 deletions QUANTAXIS/QAFetch/QAQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ def QA_fetch_stock_basic_info_tushare(collections=DATABASE.stock_info_tushare):
return items


def QA_fetch_stock_to_market_date(stock_code):
'''
根据tushare 的数据库查找上市的日期
:param stock_code: '600001'
:return: string 上市日期 eg: '2018-05-15'
'''
items = QA_fetch_stock_basic_info_tushare()
for row in items:
if row['code'] == stock_code:
return row['timeToMarket']


def QA_fetch_stock_full(date, format='numpy', collections=DATABASE.stock_day):
'获取全市场的某一日的数据'
Expand Down
82 changes: 82 additions & 0 deletions QUANTAXIS/QASU/save_to_db_fields_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

'''
'''
quantaxis__db_description= [

{
'stock_info_tushare':
[
{'code':'代码'},
{'name','名称'},
{'industry','所属行业'},
{'area','地区'},
{'pe','市盈率'},
{'outstanding','流通股本(亿)'},
{'totals','总股本(亿)'},
{'totalAssets','总资产(万)'},
{'liquidAssets','流动资产'},
{'fixedAssets','固定资产'},
{'reserved','公积金'},
{'reservedPerShare','每股公积金'},
{'esp','每股收益'},
{'bvps','每股净资'},
{'pb','市净率'},
{'timeToMarket','上市日期'},
{'undp','未分利润'},
{'perundp', '每股未分配'},
{'rev','收入同比(%)'},
{'profit','利润同比(%)'},
{'gpr','毛利率(%)'},
{'npr','净利润率(%)'},
{'holders','股东人数'},
]
},
{
'stock_info':
[
{"market": '1'},
{"code": "代码"},
{"liutongguben": '流通股本(单位)'},
{"province": "省市代码区域"},
{"industry": "行业分类代码"},
{"updated_date": '最后更新时间'},
{"ipo_date": "首次公开发行日期"},
{"zongguben": "总股本"},
{"guojiagu": "国家股"},
{"faqirenfarengu": "发起人法人股"},
{"farengu": "法人股"},
{"bgu": "B股"},
{"hgu": "H股"},
{"zhigonggu": "职工股"},
{"zongzichan": "总资产"},
{"liudongzichan": "流动资产"},
{"gudingzichan": "固定资产"},
{"wuxingzichan": "无形资产"},
{"gudongrenshu": "股东人数"},
{"liudongfuzhai": "流动负责"},
{"changqifuzhai": "长期负责"},
{"zibengongjijin": "资本公积金"},
{"jingzichan": "净资产"},
{"zhuyingshouru": "主营收入"},
{"zhuyinglirun": "主营利润"},
{"yingshouzhangkuan": "营收账款"},
{"yingyelirun": "营业利润"},
{"touzishouyu": "投资收益"},
{"jingyingxianjinliu": ""},
{"zongxianjinliu": ""},
{"cunhuo": "存货"},
{"lirunzonghe": "利润总和"},
{"shuihoulirun": "税后利润"},
{"jinglirun": "净利润"},
{"weifenpeilirun": "未分配利润"},
{"meigujingzichan": "每股净资产"},
{"baoliu2": "保留"}

]
}



]

3 changes: 2 additions & 1 deletion QUANTAXIS/QASU/save_tushare.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ def QA_SU_save_stock_info_tushare(client=DATABASE):
print("📡 Get stock info from tushare,stock count is %d"% len(df))
coll = client.stock_info_tushare
client.drop_collection(coll)
json_data = json.loads(df.to_json(orient='records'))
json_data = json.loads(df.reset_index().to_json(orient='records'))
coll.insert(json_data)
print("📝 Save data to stock_info_tushare collection, OK✅")



def QA_SU_save_trade_date_all(client=DATABASE):
data = QA_fetch_get_trade_date('', '')
coll = client.trade_date
Expand Down
60 changes: 58 additions & 2 deletions QUANTAXIS_Test/QAFetch_Test/QAQuery_Advance_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

import unittest


import fnmatch
import os


import sqlite3
import tushare as QATs

from QUANTAXIS import *
Expand All @@ -18,12 +24,45 @@

class Test_Query_Advance(unittest.TestCase):
'''
读取钱龙数据库进行比对
清洗数据。
# 读取钱龙数据库 ,
# 存取数据到 SQLite
# 🛠 todo
读取同花顺数据库进行比对
读取通达信数据库进行比对
'''

def setUp(self):

# mac or linux 可以使用wine 来运行 , 需要指定字符集防止乱码
# env LC_ALL=zh_CN.UTF-8 wine instjd_1000.exe
#
#设置 钱龙金典 数据下载目录 http://download2.ql18.com.cn/download/software/instjd_1000.exe
self.strQianLong_QLDATA_ = '/Users/jerryw/.wine/drive_c/qianlong/jindian/QLDATA'

self.strQianLong_SHASE_day = self.strQianLong_QLDATA_ + ('/history/SHASE/day')
self.strQianLong_SHASE_weight = self.strQianLong_QLDATA_ + ('/history/SHASE/weight')
self.strQianLong_SHASE_nmn = self.strQianLong_QLDATA_ + ('/history/SHASE/nmn')

self.strQianLong_SZNSE_day = self.strQianLong_QLDATA_ + ('/history/SZNSE/day')
self.strQianLong_SZNSE_weight = self.strQianLong_QLDATA_ + ('/history/SZNSE/weight')
self.strQianLong_SZNSE_nmn = self.strQianLong_QLDATA_ + ('/history/SZNSE/nmn')

#获取目录文件名,股票代码
#读取数据
#写到sqllite

for file in os.listdir(self.strQianLong_SHASE_day):
if fnmatch.fnmatch(file, '*.day'):
print(file)

print(" ")

#self.stock_list = QA_fetch_stock_list_adv()
# print(self.stock_list)

Expand All @@ -35,14 +74,22 @@ def setUp(self):
pass

def tearDown(self):

pass

def test_QA_fetch_stock_min_adv(self):

# dataStruct = QA_fetch_stock_min_adv(start='2018-05-28 00:00:00',code = '300439')
# print("获取1分钟数据")
# print(dataStruct)
# #dataStruct.show()

dataStruct = QA_fetch_stock_min_adv(
start='2018-05-28 00:00:00', code='300439')
print("获取1分钟数据")
print(dataStruct)
# dataStruct.show()

pass

def test_001(self):
Expand All @@ -51,7 +98,11 @@ def test_001(self):
# df = QATs.get_stock_basics()
# print(df)
# print("-----------------------------------------------------------------------")

#data = QA_fetch_get_stock_list(package = "tdx")

data = QA_fetch_get_stock_list(package="tdx")

# print(data)
# print("-----------------------------------------------------------------------")

Expand All @@ -67,4 +118,9 @@ def test_001(self):
# coll = client.stock_list
# coll.insert({'date': date, 'date_stamp': date_stamp,
# 'stock': {'code': data}})
# return list(df.index)

#return list(df.index)
pass



13 changes: 12 additions & 1 deletion QUANTAXIS_Test/QAFetch_Test/QAQuery_Test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import unittest

from QUANTAXIS.QAFetch.QAQuery import QA_fetch_stock_basic_info_tushare
from QUANTAXIS.QAFetch.QAQuery import (QA_fetch_stock_basic_info_tushare, QA_fetch_stock_to_market_date)
from QUANTAXIS.QASU.save_to_db_fields_description import quantaxis__db_description


class QAQuery_test(unittest.TestCase):
Expand All @@ -15,3 +16,13 @@ def test_QA_fetch_stock_basic_info_tusare(self):
# print(i)
if i['industry'] == '半导体':
print(i)

def test_QA_fetch_stock_to_market_date(self):
to_market_date = QA_fetch_stock_to_market_date(stock_code='300439')
print(to_market_date)
self.assertEqual(to_market_date,'2015-05-15')


def test_quantaxis__db_description(self):

print(quantaxis__db_description)

0 comments on commit 2be2dfc

Please sign in to comment.