当前位置:   article > 正文

同花顺问财选股python源码_同花顺 问财 python

同花顺 问财 python

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

提示:同花顺网js加密动态生成请求中所需要的cookie


提示:以下是本篇文章正文内容,下面案例可供参考

一、使用步骤

1.引入库

import execjs
import requests
import json
  • 1
  • 2
  • 3

2.完整代码

代码如下(示例):

"""
关注微信公众号:Ctp接口量化
"""
import execjs
import requests
import json
from pyapi import DFCFTrader,THSTrader


with open('./xuangu.js', 'r') as f:
    jscontent = f.read()
context= execjs.compile(jscontent)
Trade = DFCFTrader()  #东方财富
THSTrade = THSTrader('帐号','密码','上海股东卡','深圳股东卡')    # 137
headers ={
        "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "Accept-Encoding":"gzip, deflate",
        "Accept-Language":"zh-CN,zh;q=0.9",
        "Connection":"keep-alive",
        'Cookie': "",
        "Host": "www.iwencai.com",
        "Referer": "http://www.iwencai.com/stockpick?tid=stockpick",
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"
        }    
        
def Get_stock(token=''):
    url = 'http://www.iwencai.com/unifiedwap/&perpage=500&page=1&block_list=&token=c0a8d1d315985718214337154&source=Ths_iwencai_Xuangu&version=2.0&question='
    url = url+token
    headers['cookie'] = 'v={}'.format(context.call("v"))
    res = requests.get(headers=headers, url=url)
    info = json.loads(res.text)
    数据=info['data']['answer'][0]["txt"][0]["content"]["components"][0]["data"]["datas"]
    print(len(数据))
    Data_list = []
    for i in 数据:
        if '最新价' in i.keys():
            print(i["股票代码"],i["股票简称"],i["最新价"])
            print("="*48)
            DOHLCV = {}
            DOHLCV['代码'] = i["股票代码"]
            DOHLCV['名称'] = i["股票简称"]
            DOHLCV['价格'] = i["最新价"]
            Data_list.append(DOHLCV)
        else:
            print(i["股票代码"],i["股票简称"])
            print("="*48)     
    return Data_list
def 选股():
    # qes = 'macd金叉,dea>0,量比>2,涨幅<3%'
    # qes = '60分钟macd金叉,涨幅<3%,量比>2'
    # qes = '(成交额/总市值)>5%,成交额>5亿,换手率>5%,量比>2,kdj金叉'
    # qes = '连续三天量比>2'
    # qes = 'rsi(rsi24值)上穿30,换手率大于3%,涨幅<3%,量比>2'
    # qes = '周平均换手率>10%,上市天数>200天,macd金叉,dea>0'
    # qes = '基金重仓,基金连续6个季度增仓,上市天数大于500,rsi金叉'
    # qes = '成交额>5亿,涨幅<3%,量比>2'
    # qes = '周rsi上穿30,涨幅<3%,量比>3'
    # 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金叉,涨幅<3%'
    # qes = '60分钟macd金叉,涨幅<3%,量比>2'
    # qes = 'rsi3上穿30,涨幅<3%,量比>2'
    # qes = '连续五日资金流入前100,连续十日资金流入前100,连续三日资金流入前100,macd金叉'
    # qes = '连续五日资金流入前100,macd金叉'
    # qes = 'macd金叉,dea>0,量比>1,涨幅<3%'
    # qes = '券商股'
    # qes = 'rsi24上穿30,dea>0,量比>1,涨幅<3%,非st,非*st'
    # qes = '周rsi24上穿30'
    # qes = '资金流入大于1亿,dea>0,量比>1,涨幅<3%'
    # qes = '连续三年净利润同比增长率大于50%,macd金叉,dea>0,量比>1,涨幅<3%'
    # qes = 'K上穿30'
    qes = '周KDJ金叉,量比大于2,换手率大于5%'
    gupiao = Get_stock(qes)
    for i in gupiao:
        # print(i["代码"][:-3])
        # print(i)      
        开仓 = Trade.buy(stock_code=i["代码"][:-3],price=i["价格"],amount=300)      #东方财富
        print(开仓)
        开仓 = THSTrade.buy(stock_code=i["代码"][:-3],price=i["价格"],amount=1000)      #同花顺
        # print(开仓)
        # t = Thread(target = Trade.buy,args = (i["代码"][:-3],i["价格"],300))   #东方财富
        # t.start()   
        # t = Thread(target = THSTrade.buy,args = (i["代码"][:-3],i["价格"],500)) #同花顺
        # t.start()        
def 定时():
    while True:
        time.sleep(60)
        _time = time.strftime('%H%M%S')
        if _time == '100100':
            撤单()
            东方财富风控()
            同花顺风控()
            选股()
        if _time == '102500' or _time == '112500' or _time == '132600' or _time == '142500':
            撤单()
            东方财富风控()
            同花顺风控()         

if __name__ == '__main__':
    选股()
    # #定时()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

更多内容请关注微信公众号:Ctp接口量化

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号