1 Star 0 Fork 61

frankygtd/TDXPystock

forked from 金诺/TDXPystock 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
通达信早盘选股.py 7.60 KB
一键复制 编辑 原始数据 按行查看 历史
金诺 提交于 2022-01-22 21:22 . Update 通达信早盘选股.py
from __future__ import division
import tushare as ts
import time,re
import pandas as pds
import util.logout as log
import util.TDX_OpenDataOutput as TDX_OpenDataOutput
pro = ts.pro_api('XXX')
ts.set_token('XXX')
#早盘选股,选量比>25的,现量大于3000手,3日涨幅% <15%,流通盘小150亿
###################sfile早盘竞价后导出EXCEL文件
def getstockopenamo(sfile):
sfile1=sfile
newlist=[] #存取符合条件的个股记录
#date1 =time.strftime("%Y%m%d", time.localtime())
#date1 = sfile[-12:-4:1] #取文件名中的日期
date1 = re.search(r'\d+.txt$', sfile).group()[0:8]
#print('日期为%s\t 早盘选股 '%date1)
log.logout('日期: %s\t 早盘股 \r---------------------------------------'%date1)
try:
count=0
list1=pds.read_csv(sfile, sep="\t",encoding='gbk')
try:
for i in list1.index.values: #一行一行处理
count+=1
list2 = list1.loc[i, ['代码']]
codenum = str(list2['代码']).rjust(6, '0')
#print('codenum',codenum)
list11 = list1.loc[i, ['名称']]
codename=str(format(list11['名称']))
#print('codename', codename)
list3 = list1.loc[i, ['开盘金额']]
if '--' in str(list3) :
#print('此股数据有问题',codenum)
continue
codeamo = str(format(list3['开盘金额']))
#print('codeamo',codeamo)
list4 = list1.loc[i, ['开盘换手Z']]
if '--' in str(list4) :
#rint('此股数据有问题',codenum)
continue
switchvalue=str(format(list4['开盘换手Z']))
#print('switchvalue',switchvalue)
list5 = list1.loc[i, ['涨幅%']]
if '--' in str(list5):
# rint('此股数据有问题',codenum)
continue
increase=str(format(list5['涨幅%']))
#print('increase',increase)
list6 = list1.loc[i, ['现量']]
if '--' in str(list6):
# rint('此股数据有问题',codenum)
continue
volline=str(format(list6['现量']))
#print('volline', volline)
list7 = list1.loc[i, ['流通市值']]
if '--' in str(list7):
# rint('此股数据有问题',codenum)
continue
temp=str(list7['流通市值'])
temp1 =re.findall(r"[^\W\d_]+|\d+.\d+", temp)[0]
Circulationmarketvalue =float(temp1)
#print('Circulationmarketvalue', Circulationmarketvalue)
list8 = list1.loc[i, ['3日涨幅%']]
if '--' in str(list8):
# rint('此股数据有问题',codenum)
continue
Threeincrease=str(format(list8['3日涨幅%']))
#print('Threeincrease', Threeincrease)
list9 = list1.loc[i, ['20日涨幅%']]
if '--' in str(list9):
# rint('此股数据有问题',codenum)
continue
tewincrease=str(format(list9['20日涨幅%']))
#print('tewincrease', tewincrease)
list10 = list1.loc[i, ['开盘%']]
if '--' in str(list10):
# rint('此股数据有问题',codenum)
continue
openpercent=str(format(list10['开盘%']))
#print('openpercent', openpercent)
list12 = list1.loc[i, ['量比']]
if '--' in str(list12):
# rint('此股数据有问题',codenum)
continue
volpercent = str(format(list12['量比']))
#print('volpercent', volpercent)
#print('{0},{01},{2},{3},{4},{5},{6},{7},{8},{9}'%(codenum,codeamo,switchvalue,
#increase, volline,Circulationmarketvalue,Threeincrease,tewincrease,openpercent,codename))
if float(volpercent)>1: #有数据表示未停牌
# 按量比排序,选量比>25的,现量大于3000手,3日涨幅% <15% and 流通市值小于100亿
if float(openpercent) <4 and float(openpercent)>-1.5 and float(volpercent)>25 and float(volline)>3000 and float(Threeincrease)<15 and float(Circulationmarketvalue)<100:
newlist.append(str(codenum)+':'+str(codename)+':'+str(volpercent)+':'+str(volline)+':'+str(Circulationmarketvalue))
#print('量比条件个股代码为:%s: %s'%(codenum,codename))
log.logout('量比组合条件个股: %s: %s'%(codenum,codename))
#print(newlist)
# 按换手选 换手在在0.8到2之间,现量大于3000手,3日涨幅% <15% and 流通市值小于100亿
if float(openpercent) <4 and float(openpercent)>-1.5 and float(switchvalue) >0.9 and float(switchvalue)<=2 and float(volline) > 3000 and float(Threeincrease) < 15 and float(
Circulationmarketvalue) < 100:
newlist.append(str(codenum) + ':' + str(codename) + ':' + str(volpercent) + ':' + str(
volline) + ':' + str(Circulationmarketvalue))
log.logout('换手组合条件个股: %s: %s' % (codenum, codename))
#print('换手条件个股代码为:%s: %s' % (codenum, codename))
# print(newlist)
else:
continue
print('该股暂停牌')
except BaseException as be:
print(be)
print('处理%s 数据后出现问题'%count)
print('处理股票:%s,出现问题'%codename)
print(codenum,codeamo,switchvalue,
increase, volline,Circulationmarketvalue,Threeincrease,tewincrease,openpercent,codename,volpercent)
print('到此未有问题')
#print(newlist)
except FileNotFoundError as fnot1:
print(fnot1)
return newlist
return newlist
for stockopendata in newlist: #输出选择到的股膘
print(stockopendata)
def procesopenstockprice(sfile):
try:
sfile1=sfile
getstockopenamo(sfile1)
except BaseException as ee:
print(ee)
print('处理异常请检查')
print('处理完成')
spath='c:\\十档行情\\T0002\\export'
spathbak='c:\\十档行情\\T0002\\exportbak'
outdate = time.strftime("%Y%m%d", time.localtime())
sfile1='c:\\十档行情\\T0002\\export\\板块指数'+outdate+'.txt' #导出数据为excel /后每天执行一次
sfile2='c:\\十档行情\\T0002\\export\\沪深A股'+outdate+'.txt' #导出数据为excel /后每天执行一次
dpath='C:\\十档行情\\T0002\\signals\\signals_user_9601\\'
if __name__=='__main__':
# TDX_OpenDataOutput.TDX_OpenDataOutputTXT() #导出数据
getstockopenamo(sfile2) #读取导出的txt,选股
#listfile =os.listdir(spath)
#下面代码每天调用一次即可
# for fl in listfile:
# print('代处理的文件为:',spath+'\\'+fl)
# if fl.endswith('xls'):
# procesdata(spath+'\\'+fl, dpath)
# print('文件:%s,处理成功!',spath+'\\'+fl)
# if not os.path.exists(spathbak):
# os.makedirs(spathbak)
# else:
# movefile(spath+'\\'+fl,spathbak+'\\'+fl)
# print("move %s -> %s",fl,(spathbak+fl))
# #movefile(sfile2,spathbak+'\\'+'沪深A股20201126.xls')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/frankygtd/TDXPystock.git
git@gitee.com:frankygtd/TDXPystock.git
frankygtd
TDXPystock
TDXPystock
newmastor

搜索帮助