股票自动化交易
代码如下:
import timefrom 手机版选股 import *ths_user = Wencai() ths_user.login(Config["userid"],Config["password"])# 登陆交易账号 def 选股():# qes = '(成交额/总市值)>5%,成交额>5亿,换手率>5%,量比>2,kdj金叉'# qes = '周平均换手率>10%,成交额>10亿'# qes = '基金重仓,基金连续6个季度增仓,上市天数大于500,rsi金叉'# qes = "rsi上穿70,量比大于2,dea大于0,股价大于60均线,换手率大于3%,涨幅小于5%"# qes = "kdj金叉,量比大于3,dea大于0,股价大于60均线,换手率大于3%,涨幅小于5%"# qes = "macd上移,量比大于2,dea大于0,股价大于60均线,换手率大于5%,涨幅小于5%"# qes = 'rsi3上穿30,涨幅<3%,量比>2'# qes = 'macd金叉,dea>0,量比>1,涨幅<3%'# qes = '60分钟macd金叉,dea>0,涨幅<3%,量比>2'# qes = '周KDJ金叉,量比大于2,换手率大于5%'# qes = 'macd金叉,dea>0,量比>1,涨幅<3%'# qes = 'rsi24上穿30,dea>0,量比>1,涨幅<3%,非st,非*st'qes = '周rsi24上穿30,非st,非*st,量比>1'# qes = '连续三年净利润同比增长率大于50%,macd金叉,dea>0,量比>1,涨幅<3%'# qes = 'K上穿30,均线多头排列'# qes = 'kdj金叉,均线多头排列'Data_list = ths_user.Xuangu(qes)for i in Data_list:print(i["代码"][:-3])print(i)开仓 = ths_user.buy(stock_code=i["代码"][:-3],price=i["价格"],amount=1000)#同花顺# print(开仓)def 止损止盈(止损=-300,止盈=500):ths_user.qryChedan() # 撤销全部委托全部持仓 = ths_user.qryChicang() # 全部持仓for pos in 全部持仓:print("="*30)print("编号",pos["d_3001"])print("证券代码",pos["d_2102"])print("证券名称",pos["d_2103"])print("可用余额",pos["d_2121"])print("成本价",pos["d_2122"])print("市价",pos["d_2124"])print("市值",pos["d_2125"])print("浮动盈亏",pos["d_2147"])if float(pos["d_2147"]) <= float(止损) or float(pos["d_2147"]) > float(止盈):stock = ths_user.sell( stock_code=pos["d_2102"], price=pos["d_2124"], amount=pos["d_2121"], volume=0, entrust_prop='limit')print("平仓")def 定时():while True:time.sleep(6)_time = time.strftime('%H%M%S')if _time == '100100':选股()# if _time == '102500' or _time == '112500' or _time == '132600' or _time == '142500':# 止损止盈() 止损止盈() if __name__ == '__main__':定时()
关注微信公众号: Ctp接口量化