def get_top_inst_list(self, task=None):
        """
        获取每日龙虎榜列表(龙虎榜上榜是根据上榜原因定的,因此有的股票可能会有多个原因,存在多条记录),并保存到文件中
        获取当日机构购买详情,不能赋值日期,默认只能获取最近一天的交易详情
        Parameters
        ----------
        task:指定任意参数表示获取某一天的龙虎榜,否则为获取当日的龙虎榜

        """
        d = self.today if task is None else self.end
        top_list_df = ts.top_list(d)
        inst_detail_df = ts.inst_detail() if task is None else None

        if os.path.exists(u"{}/top_list_data.csv".format(data_path)):
            with codecs.open(u"{}/top_list_data.csv".format(data_path), "a+", "utf-8") as f:
                top_list_df.to_csv(f, header=False, sep="\t", index=True)
        else:
            with codecs.open(u"{}/top_list_data.csv".format(data_path), "a+", "utf-8") as f:
                top_list_df.to_csv(f, header=True, sep="\t", index=True)

        if inst_detail_df is not None:
            if os.path.exists(u"{}/inst_detail_data.csv".format(data_path)):
                with codecs.open(u"{}/inst_detail_data.csv".format(data_path), "a+", "utf-8") as f:
                    top_list_df.to_csv(f, header=False, sep="\t", index=True)
            else:
                with codecs.open(u"{}/inst_detail_data.csv".format(data_path), "a+", "utf-8") as f:
                    top_list_df.to_csv(f, header=True, sep="\t", index=True)
Exemplo n.º 2
0
 def store_top_data(self, trading_date=None):
     """龙虎榜数据: 龙虎榜数据接口提供历史龙虎榜上榜股票数据"""
     trading_date = self.last_trading_date if trading_date is None else trading_date
     # 每日龙虎榜列表
     print('top_list...')
     top_df = ts.top_list(self.stock_date_format(trading_date))
     self.mysqlUtils.append_data(top_df, 'top_list')
     # 个股上榜统计
     print('cap_tops...')
     cap_tops_df = ts.cap_tops()
     cap_tops_df['date'] = trading_date
     self.mysqlUtils.append_data(cap_tops_df, 'cap_tops')
     # 营业部上榜统计
     print('broker_tops...')
     broker_tops_df = ts.broker_tops()
     broker_tops_df['date'] = trading_date
     self.mysqlUtils.append_data(broker_tops_df, 'broker_tops')
     # 龙虎榜机构席位追踪
     print('inst_tops...')
     inst_tops_df = ts.inst_tops()
     inst_tops_df['date'] = trading_date
     self.mysqlUtils.append_data(inst_tops_df, 'inst_tops')
     # 龙虎榜机构席位成交明细
     print('inst_detail...')
     inst_detail_df = ts.inst_detail()
     self.mysqlUtils.append_data(inst_detail_df, 'inst_detail')
Exemplo n.º 3
0
def job_7():
    try:
        print("I'm working......龙虎榜数据")
        # 每日龙虎榜列表
        top_list = ts.top_list(today)
        data = pd.DataFrame(top_list)
        data.to_sql('top_list',engine,index=True,if_exists='replace')
        print("每日龙虎榜列表......done")

        # 个股上榜统计
        cap_tops = ts.cap_tops()
        data = pd.DataFrame(cap_tops)
        data.to_sql('cap_tops',engine,index=True,if_exists='replace')
        print("个股上榜统计......done")

        # 营业部上榜统计
        broker_tops = ts.broker_tops()
        data = pd.DataFrame(broker_tops)
        data.to_sql('broker_tops',engine,index=True,if_exists='replace')
        print("营业部上榜统计......done")

        # 机构席位追踪
        inst_tops = ts.inst_tops()
        data = pd.DataFrame(inst_tops)
        data.to_sql('inst_tops',engine,index=True,if_exists='replace')
        print("机构席位追踪......done")

        # 机构成交明细
        inst_detail = ts.inst_detail()
        data = pd.DataFrame(inst_detail)
        data.to_sql('inst_detail',engine,index=True,if_exists='replace')
        print("机构成交明细......done")
    except Exception as e:
        print(e)
Exemplo n.º 4
0
def longhu():
    db.get_collection('topList').remove()
    longhu = ts.top_list()
    longhu = longhu.to_json(orient='index', )
    longhu = json.loads(longhu)
    for k, v in longhu.items():
        db.get_collection('topList').insert(v)
Exemplo n.º 5
0
def stat_all(tmp_datetime):
    datetime_str = (tmp_datetime).strftime("%Y-%m-%d")
    datetime_int = (tmp_datetime).strftime("%Y%m%d")

    cache_dir = common.bash_stock_tmp % (datetime_str[0:7], datetime_str)
    if os.path.exists(cache_dir):
        shutil.rmtree(cache_dir)
        print("remove cache dir force :", cache_dir)

    print("datetime_str:", datetime_str)
    print("datetime_int:", datetime_int)
    data = ts.top_list(datetime_str)
    # 处理重复数据,保存最新一条数据。最后一步处理,否则concat有问题。
    #
    if not data is None and len(data) > 0:
        # 插入数据库。
        # del data["reason"]
        data["date"] = datetime_int  # 修改时间成为int类型。
        data = data.drop_duplicates(subset="code", keep="last")
        data.head(n=1)
        common.insert_db(data, "ts_top_list", False, "`date`,`code`")
    else:
        print("no data .")

    print(datetime_str)
Exemplo n.º 6
0
def get_last_ranklist_detail():
    """
    :return: 
    """
    fields = [
        'code', 'name', 'pchange', 'amount', 'buy', 'bratio', 'sell', 'sratio',
        'reason', 'date'
    ]
    today = (datetime.datetime.today() -
             datetime.timedelta(days=1)).strftime('%Y-%m-%d')
    top_list = ts.top_list(today)
    if top_list is None or not len(top_list):
        return
    if RankListDailyData.objects.filter(type_date=today).exists():
        return

    bulk_list = []
    for i in range(len(top_list)):
        per_dict = dict()
        for f in fields:
            per_dict.update({f: top_list[f][i]})
        r_model = RankListDailyData(code=per_dict.get('code'),
                                    name=per_dict.get('name'),
                                    pcharge=per_dict.get('pchange'),
                                    amount=per_dict.get('amount'),
                                    buy=per_dict.get('buy'),
                                    bratio=per_dict.get('bratio'),
                                    sell=per_dict.get('sell'),
                                    sratio=per_dict.get('sratio'),
                                    reason=compare_by_value_get_key(
                                        RANK_REASON, per_dict.get('reason')),
                                    type_date=per_dict.get('date'))
        bulk_list.append(r_model)
    RankListDailyData.objects.bulk_create(bulk_list)
Exemplo n.º 7
0
def run():
    start = datetime.datetime.now()
    config = {
        'host': '10.60.42.201',
        'user': '******',
        'password': '******',
        'port': 13142,
        'database': 'javaEE',
        'charset': 'utf8'
    }
    conn = mysql.connector.connect(**config)
    cursor = conn.cursor()

    today = datetime.date.today()
    today = str(today)
    td = ts.top_list('2017-12-01')

    params = []
    for index, row in td.iterrows():
        params.append((row['code'], row['name'], row['pchange'], row['amount'],
                       row['buy'], row['bratio'], row['sell'], row['sratio'],
                       row['reason']))

    sql = "INSERT INTO winnerlist VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
    cursor.executemany(sql, params)
    cursor.execute("Commit;")

    cursor.close()
    conn.close()

    print datetime.datetime.now() - start
Exemplo n.º 8
0
def get_top_list(date):
    try:
        df = ts.top_list(date)
        engine = create_engine('mysql://*****:*****@127.0.0.1/stock?charset=utf8')
        df.to_sql('top_list', engine, if_exists='append')
        print "message"
    except Exception, e:
        e.message
Exemplo n.º 9
0
def get_top_list():
    today = datetime.date.today()
    delta = datetime.timedelta(days=1)
    ndays_before = today - delta
    date_str = ndays_before.strftime('%Y-%m-%d');
    logging.info("date: %s", date_str)
    df = ts.top_list(date_str)
    df.to_sql('top_list', engine, if_exists='append', index=False, index_label='code')
Exemplo n.º 10
0
def get_top_list(date):
    '''
    return long hu bang
    :param date: Format is 'YYYY-MM-DD'
    :return: long hu bang
    '''
    df = ts.top_list(date)
    df[['pchange', 'amount', 'buy', 'bratio', 'sell', 'sratio']] = df[['pchange', 'amount', 'buy', 'bratio', 'sell', 'sratio']].apply(pd.to_numeric, errors='ignore')
    return df
Exemplo n.º 11
0
def get_stock_winner(datetime):
    """
        获取每日龙虎榜列表
    """
    try:
        res = ts.top_list(datetime)
        return res
    except:
        return None
Exemplo n.º 12
0
 def Gettop_list(self):
     """今天是星期六或者星期天 不是交易日 周六做异常判断"""
     todays = datetime.date.today()
     dayOfWeek = datetime.date.today().weekday()
     if dayOfWeek == 5: timess = todays - datetime.timedelta(days=1)
     elif dayOfWeek == 6: timess = todays - datetime.timedelta(days=2)
     else: timess = todays
     dates = ts.top_list('%s' % (timess))
     self.SaveCSV(dates, 'toplist.csv')
Exemplo n.º 13
0
def getdragontigerdata():
    curday = datetime.date.today()
    curdate = curday.strftime('%Y%m%d')
    print(curdate)

    mylogger = getmylogger()

    # 每日龙虎榜列表
    df = ts.top_list(curday.strftime('%Y-%m-%d'))
    if df is not None:
        df['date'] = curdate
        tosql(df, 'toplistdata', "append", "每日龙虎榜数据", mylogger)
    else:
        mylogger.info("没有每日龙虎榜数据。")

    # 个股上榜统计
    for i in [5, 10, 30, 60]:
        df = ts.cap_tops(i)
        logmsg = "个股上榜数据" + "%d日:" % i
        if df is not None:
            df['date'] = curdate
            df['period'] = i
            tosql(df, 'captops', "append", logmsg, mylogger)
        else:
            mylogger.info("没有" + logmsg)

    # 营业部上榜统计
    for i in [5, 10, 30, 60]:
        df = ts.broker_tops(i)
        logmsg = "营业部上榜数据" + "%d日:" % i
        if df is not None:
            df['date'] = curdate
            df['period'] = i
            tosql(df, 'brokertops', "append", logmsg, mylogger)
        else:
            mylogger.info("没有" + logmsg)

    # 机构席位追踪
    for i in [5, 10, 30, 60]:
        df = ts.inst_tops(i)
        logmsg = "机构席位追踪数据" + "%d日:" % i
        if df is not None:
            df['date'] = curdate
            df['period'] = i
            tosql(df, 'instops', "append", logmsg, mylogger)
        else:
            mylogger.info("没有" + logmsg)

    # 机构成交明细
    df = ts.inst_detail()
    logmsg = "机构成交明细:"
    if df is not None:
        df['date'] = curdate
        tosql(df, 'instdetail', "append", logmsg, mylogger)
    else:
        mylogger.info("没有机构成交明细。")
Exemplo n.º 14
0
def prepare_data():
    current_date = time.strftime("%Y-%m-%d")
    top_list = ts.top_list(current_date)
    if top_list is None or top_list.empty:
        return
    record_json = top_list.to_json(orient='records')
    print(record_json)
    collection = mongoConfig.get_collection_default("stock_top_list")
    mongoConfig.clear_collection(collection)
    mongoConfig.insert_json(collection, json.loads(record_json))
Exemplo n.º 15
0
def get_td_list(date=None):
    """
    description: 每日榜单
    params:
        date: 日期
    """
    if date is None:
        date = time_utils.today()
    data = ts.top_list(date)
    return data
Exemplo n.º 16
0
def lhb_daily(date, pause=0.5):
    """
    每日龙虎榜数据
    :param date:
    :return:
    """
    fs = ts.top_list(date, pause=pause)
    fs['dif'] = fs.apply(lambda x: float(x.buy) - float(x.sell), axis=1)

    return fs
Exemplo n.º 17
0
def getLastData(strdate):
    date = lastTddate(strdate)
    dfLastTradeDay = ts.top_list(lastTddate(date))

    strIndex = date.replace("-", "")
    listIndex = []
    for i in range(len(dfLastTradeDay)):
        listIndex.append(strIndex + "{:0>2}".format(i))
    dfLastTradeDay.index = listIndex
    return dfLastTradeDay
Exemplo n.º 18
0
def stk_top_list(dat=str(date.today())):
    print("======获取龙虎榜列表============")
    print("\n插入数据:" + 'stk_top_list')
    try:

        df = ts.top_list(retry_count=10,pause=1,date=dat)
        # print(df)
        df.to_sql('stk_top_list',engine,if_exists='append')
    except Exception as e :
        print("insert failed." + str(e))
Exemplo n.º 19
0
def test():
    ts.get_sz50s()
    ts.get_hs300s()
    ts.get_zz500s()
    ts.realtime_boxoffice()
    ts.get_latest_news()
    ts.get_notices(tk)
    ts.guba_sina()
    ts.get_cpi()
    ts.get_ppi()
    ts.get_stock_basics()
    ts.get_concept_classified()
    ts.get_money_supply()
    ts.get_gold_and_foreign_reserves()
    ts.top_list()  #每日龙虎榜列表
    ts.cap_tops()  #个股上榜统计
    ts.broker_tops()  #营业部上榜统计
    ts.inst_tops()  # 获取机构席位追踪统计数据
    ts.inst_detail()
Exemplo n.º 20
0
def GetBillBoardOn(date):
    """
    Get BillBoard data according to date.

    Args:
        date: a data string whose format is "YYYY-MM-DD"

    Returns:
    """
    return ts.top_list(date)
Exemplo n.º 21
0
    def __init__(self, init=True):
        """
        初始化,筛除688,300,ST,退市股,新股,低价股,下跌股
        """
        if init:
            self.data = ts.get_today_all()  #今日复盘
            self.updateNMC(self.data)
            # data = ts.get_day_all(date='2021-02-18')   #历史复盘
            filt = self.data['code'].str.contains('^(?!688|605|300|301|8|43)')
            self.data = self.data[filt]
            filt = self.data['name'].str.contains('^(?!S|退市|\*ST|N)')
            self.data = self.data[filt]
            self.data = self.data.drop_duplicates()
            data = self.data[self.data['trade'] >= 2]
            data = data[data['changepercent'] > -3]
            data = data.to_json(orient='records')
            db.get_collection('today').remove()
            base = db.get_collection('base').find()
            industry = {i['code']: i['industry'] for i in base}
            self.intersect = {}
            for i in eval(data):
                db.get_collection('today').insert(i)
            res = db.get_collection('today').find()
            for i in res:
                try:
                    db.get_collection('today').update_many(
                        {'code': i['code']},
                        {'$set': {
                            'industry': industry[i['code']]
                        }})
                except:
                    pass

            # 剔除新股
            try:
                newStock = ts.new_stocks()
                if not newStock.empty:
                    newStock = newStock[newStock.ipo_date > '2020-01-01']
                    for i in newStock['code'].tolist():
                        db.get_collection('today').remove({'code': i},
                                                          multi=True)
            except Exception as e:
                print('newStock Error', e)

            # 剔除停牌
            db.get_collection('today').remove({'open': 0})

            # 龙虎榜
            if not (10 < time.localtime().tm_hour < 18):
                db.get_collection('topList').remove()
                longhu = ts.top_list()
                longhu = longhu.to_json(orient='index', )
                longhu = json.loads(longhu)
                for k, v in longhu.items():
                    db.get_collection('topList').insert(v)
Exemplo n.º 22
0
def download_top_list(time):

    Datas_b= ts.top_list(time)

    files_path = '../report/Brokerage/%s'%todaytime
    if os.path.exists(files_path) == False: # 判断文件是不是存在
        os.mkdir(files_path)                # 创建目录
    Datas_b.to_csv(files_path+'/%s_top_list_csv.csv'%(todaytime),encoding='gbk')
    with pd.ExcelWriter(files_path+'/%s_top_list_xlx.xlsx'%(todaytime)) as writer:
        Datas_b.to_excel(writer, sheet_name='Sheet1')
    print('\n%s龙虎have been saved'%(todaytime))
Exemplo n.º 23
0
def get_lbh_top_list(data):
    """
    按日期获取历史当日上榜的个股数据,
    如果一个股票有多个上榜原因,则会出现该股票多条数据
    """
    df = ts.top_list(data)
    print(df)
    if df is not None:
        res = df.to_sql(lbh_top_list, engine, if_exists='replace')
        msg = 'ok' if res is None else res
        print('获取历史当日上榜的个股数据: 开始时间:{0}  {1}'.format(data, msg) + '\n')
    else:
        print('获取历史当日上榜的个股数据: 开始时间:{0}  {1}'.format(data, 'None') + '\n')
Exemplo n.º 24
0
def stk_top_list_detail(dat=str(date.today())):
    df = ts.top_list(date=dat,retry_count=3,pause=1)
    # print(df)
    #http://vip.stock.finance.sina.com.cn/q/api/jsonp.php/var%20details=/InvestConsultService.getLHBComBSData?symbol=300708&tradedate=2018-01-24&type=5
    for code in (df[df.reason.str.contains('日涨幅偏离值达到7%的前五只证券')]['code']):
        type='01'
        url = 'http://vip.stock.finance.sina.com.cn/q/api/jsonp.php/var%20details=/InvestConsultService.getLHBComBSData?symbol=' + code + '&tradedate=' + dat + '&type=' + str(type)
        r = requests.get(url)
        f = open('r.txt','w+')
        f.write(r.text)
        # print(r.text)
        for line in f.readline():
            r1 = line.replace('.*script.*','')
            print(r1)
Exemplo n.º 25
0
def showTopList():
    date = request.args['date']
    date = date.encode('ascii') if date else datetime.today()
    # logging.error(date)
    df = cache.get('topList_%s'%date)
    # logging.error('topList_%s'%date)
    if df is None:
        df = ts.top_list(date=date)
        if df is None:
             html_tbl = u"<p>这一天没有数据</p>"
        else:
            cache.set('topList_%s'%date, df, timeout=600)
            html_tbl = df.to_html()
    return render_template('stock_topList.html', tbl=html_tbl)
Exemplo n.º 26
0
def get_top_list_tu(_trade_date):
    stock_list = None

    count = 0
    while count < 2:
        count = count + 1
        try:
            stock_list = ts.top_list(_trade_date)
            break
        except Exception:
            log_error("warn: ts.top_list exception: %d!", count)
            time.sleep(5)

    return stock_list
Exemplo n.º 27
0
    def get_top_list(self):
        #print(ts.get_day_all())
        for i in range(0,10):
            now=datetime.datetime.now()
            delta=datetime.timedelta(days=i)
            n_days=now-delta      
            tradedate = n_days.strftime('%Y-%m-%d')

            ts_data = ts.top_list(tradedate)
            if not  ts_data  is None:
                break
        
        df=pd.DataFrame(data=ts_data) 
        print(df)
        return df
Exemplo n.º 28
0
Arquivo: tops.py Projeto: cnslyq/ts
def tops_list_worker(engine, sdate, edate):
	pid = os.getpid()
	tsl.log("pid %i start with %s ~ %s..." % (pid, str(sdate), str(edate)))
	cdate = sdate
	df = pd.DataFrame()
	while cdate <= edate:
		if not tsu.is_holiday(cdate):
			try:
				newdf = ts.top_list(str(cdate))
				if df is not None:
					df = df.append(newdf, ignore_index=True)
			except BaseException, e:
				print e
				tsl.log("pid %i error on %s" % (pid, str(cdate)))
		cdate += datetime.timedelta(days=1)
Exemplo n.º 29
0
def intoDB(date='2017-10-20'):
    '''
    Insert symbols to Mysql
    '''
    print("[info] getting {}".format(date))
    data = ts.top_list(date)
    data['date'] = date
    data = data.drop_duplicates(['code', 'date'])

    print("[info] into mysql")
    engine = create_engine('mysql://*****:*****@127.0.0.1/stock?charset=utf8',
                           encoding='utf-8')

    try:
        data.to_sql('longhu', engine, if_exists="append", index=False)
    except Exception as e:
        print("error: {}".format(e))
Exemplo n.º 30
0
def stat_all(tmp_datetime):
    datetime_str = (tmp_datetime).strftime("%Y-%m-%d")
    datetime_int = (tmp_datetime).strftime("%Y%m%d")
    print("datetime_str:", datetime_str)
    print("datetime_int:", datetime_int)
    data = ts.top_list(datetime_str)
    # 处理重复数据,保存最新一条数据。最后一步处理,否则concat有问题。
    #
    if not data is None and len(data) > 0:
        # 插入数据库。
        #del data["reason"]
        data["date"] = datetime_int  # 修改时间成为int类型。
        data = data.drop_duplicates(subset="code", keep="last")
        data.head(n=1)
        common.insert_db(data, "ts_top_list", False, "`date`,`code`")
    else:
        print("no data .")

    print(datetime_str)
Exemplo n.º 31
0
def get_top_list(date, retry_count=RETRY_COUNT, pause=PAUSE):
    """每日龙虎榜列表"""

    logger.info('Begin get TopList. Date is: %s.' % date)
    try:
        data_df = ts.top_list(date, retry_count, pause)
    except Exception as e:
        logger.exception('Error get TopList. Date is: %s.' % date)
        return None
    else:
        data_dicts = []
        if data_df is None or data_df.empty:
            logger.warn('Empty get TopList. Date is: %s.' % date)
        else:
            data_dicts = [{'code': row[0], 'name': row[1],
                           'pchange': row[2], 'amount': row[3], 'buy': row[4],
                           'sell': row[5], 'reason': row[6], 'bratio': row[7],
                           'sratio': row[8], 'date': row[9]}
                          for row in data_df.values]
            logger.info('Success get TopList. Date is: %s.' % date)
        return data_dicts
Exemplo n.º 32
0
def top_type(top_type):
    today = datetime.datetime.today().strftime('%Y-%m-%d')
    if top_type == 'top_list':
        top_list = ts.top_list(today)
        if top_list is not None:
            top_list.to_sql('top_list',
                            engine,
                            flavor='mysql',
                            if_exists='append')
    elif top_type == 'cap_tops':
        cap_tops = ts.cap_tops()
        if cap_tops is not None:
            cap_tops['date'] = today
            cap_tops.to_sql('top_cap_tops',
                            engine,
                            flavor='mysql',
                            if_exists='append')
    elif top_type == 'broker_tops':
        broker_tops = ts.broker_tops()
        if broker_tops is not None:
            broker_tops['date'] = today
            broker_tops.to_sql('top_broker_tops',
                               engine,
                               flavor='mysql',
                               if_exists='append')
    elif top_type == 'inst_tops':
        inst_tops = ts.inst_tops()
        if inst_tops is not None:
            inst_tops['date'] = today
            inst_tops.to_sql('top_inst_tops',
                             engine,
                             flavor='mysql',
                             if_exists='append')
    elif top_type == 'inst_detail':
        inst_detail = ts.inst_detail()
        if inst_detail is not None:
            inst_detail.to_sql('top_inst_detail',
                               engine,
                               flavor='mysql',
                               if_exists='append')
def getData_huanshoulv(date, reasonson):
    # print(111)
    reasons = [
        # '无价格涨跌幅限制的证券',
        '日换手率达到20%的前五只证券',
        # '日涨幅偏离值达到7%的前五只证券',
        # '日跌幅偏离值达到7%的前五只证券',
        # '有价格涨跌幅限制的日价格振幅达到15%的前三只证券',
        # '有价格涨跌幅限制的日换手率达到20%的前三只证券',
        # '有价格涨跌幅限制的日收盘价格涨幅偏离值达到7%的前三只证券',
        # '连续三个交易日内,涨幅偏离值累计达到12%的ST证券、*ST证券和未完成股改证券',
        # '连续三个交易日内,涨幅偏离值累计达到20%的证券',
        # '退市整理期',
        # '非ST、*ST和S证券连续三个交易日内收盘价格涨幅偏离值累计达到20%的证券'
    ]

    rea = '日换手率达到20%的前五只证券'
    df = ts.top_list(date)
    # df = df.sort(columns='reason')
    name = list(df['name'])
    change = list(df['pchange'])
    reason = list(df['reason'])
    # print(len(code))
    # for i in code:
    #     print(i)
    # for i in name:
    #     print(i)
    # for i in reason:
    #     print(i)
    names = []
    changes = []
    for i in range(0, len(name)):
        if reason[i] == rea:
            names.append(name[i])
            changes.append(change[i])
    print(len(names))
    for i in names:
        print(i)
    for i in changes:
        print(i)
Exemplo n.º 34
0
def QA_fetch_get_lhb(date):
    return ts.top_list(date)
Exemplo n.º 35
0
def QA_fetch_get_lhb(date):
  return  QATs.top_list(date)
Exemplo n.º 36
0
 def daily_longhu(self):
     # date=self.date
     date = '2016-04-05'
     df = ts.top_list(date)
     df.to_excel(date + ".xlsx")
Exemplo n.º 37
0
# 取两融数据
df = ts.sh_margins(start='2015-01-01',end='2016-05-04')
df = ts.sh_margin_details(start='2016-01-01',end='2016-05-04')
df = ts.sh_margin_details(start='2015-01-01', end='2015-04-19', symbol='601989')
df = ts.sz_margins(start='2015-06-01',end='2016-05-04')
# 只能一天天取
df = ts.sz_margin_details('2015-04-20')
# 取 沪深 日,周,分钟
df = ts.get_hist_data('sh', ktype='W')
df = ts.get_hist_data('sz', ktype='60')
df = ts.get_hist_data('cyb')
df = ts.get_hist_data('zxb')

# 龙虎榜
df = ts.top_list('2016-05-04')

# 计算macd
short_win = 12
long_win = 26
macd_win = 9
df = ts.get_hist_data('600405')
d = df['close']
dlist = d.tolist()
# 反向
dlist.reverse()
prices = np.array(dlist)
macd_tmp = tb.MACD(prices,fastperiod=short_win, slowperiod=long_win,signalperiod=macd_win)
MACD = macd_tmp[2]
DEA = macd_tmp[1]
DIF = macd_tmp[0]
Exemplo n.º 38
0
 def longhuban(self, date):
     print(ts.top_list(date))
     print(ts.cap_tops())
Exemplo n.º 39
0
 def longhuban(self, date):
     print(ts.top_list(date))
     print(ts.cap_tops())
Exemplo n.º 40
0
today = str(date.today())

# today = '2016-07-01'

conn = MySQLdb.connect(host="localhost", user="******", passwd="root", db="stock", charset="utf8")
cursor = conn.cursor()

sql = "select calendarDate from trade_cal where isOpen=1 and calendarDate='" + today + "'"
cursor.execute(sql)
dateRes = cursor.fetchone()

if dateRes:
    # 每日龙虎榜列表
    try:
        df = ts.top_list(today)
        if df is not None:
            for idx in df.index:
                temp = df.ix[idx]
                sql = "insert into top_list(code,name,pchange,amount,buy,bratio,sell,sratio,reason,date) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
                param = (temp['code'],temp['name'],temp['pchange'],temp['amount'],temp['buy'],temp['bratio'],temp['sell'],temp['sratio'],temp['reason'],temp['date'])
                cursor.execute(sql, param)
                conn.commit()
    except:
        f=open("errors/"+today+".log",'a')
        traceback.print_exc(file=f)
        f.flush()
        f.close()
        
    # 个股上榜统计            
    try:
Exemplo n.º 41
0
__author__='Bill Dan'
import tushare as ts
import pymongo
from pymongo import MongoClient
import json
# conn=pymongo.Connection('127.0.0.1',port=27017)
client = MongoClient()
client = MongoClient('mongodb://localhost:27017/')
db=client.refdata
print 'start...'
df=ts.top_list('2017-03-21')
db.top_list.insert(json.loads(df.to_json(orient='records')))
print 'completed'
Exemplo n.º 42
0
import pandas as pd
import tushare as ts


# pd.set_option('display.height', 1000)
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)

def remove_percent(s):
    if '.' in s and '%' in s:
        return float(s.strip('%'))
    return s

df = ts.top_list('2015-10-30')
df['pchange'] = df['pchange'].replace('%', '', regex=True).astype('float')
# print dir(df)
# print df.sort_values(by='pchange', ascending=False)[df.pchange>8.0]['code']

up_c_top_list = df[df.pchange>7.0]['code'].tolist()
up_n_top_list = df[df.pchange>7.0]['name'].tolist()

for c, n in zip(up_c_top_list, up_n_top_list):
    # print c
    df1 = ts.get_hist_data(c,start='2015-10-27',end='2015-10-30')
    try:
        if not df1.empty and df1['close'].tolist()[-1] < df1['ma20'].tolist()[-1]:
            print c, n
            print df1
    except:
        pass
Exemplo n.º 43
0
 def daily_longhu(self):
     # date=self.date
     date = '2016-04-05'
     df = ts.top_list(date)
     df.to_excel(date + ".xlsx")
Exemplo n.º 44
0
def EveryDayTop():
	day=dt.date.today()
	while ts.is_holiday(str(day)):
		day=day-dt.timedelta(days=1)
	df=ts.top_list(str(day))
	return [u"%s日龙虎榜列表:(%s条)"%(str(day+dt.timedelta(days=1)),len(df)),df]