def crawl_earning_of_stocks(question='昨日涨停 非st 非新股 非退市', day=getCurrentTradeDay(), showDetail=False): # print(question) stocks = crawl_stock_data(question) total = 0 index = 0 # 过滤空数据 stocks = filter(lambda x: filterNone(x, day), stocks) # 可能有停牌的票,则取0 stocks = sorted(stocks, key=lambda stock: float( stock.get('涨跌幅:前复权[%s]' % day, stock.get('最新涨跌幅', 0))), reverse=True) for stock in stocks: index += 1 if showDetail: print(index, stock['股票简称'], stock.get('涨跌幅:前复权[%s]' % day, stock.get('最新涨跌幅', 0))) # 可能有停牌的票,则取0 total += float( '%.2f' % float(stock.get('涨跌幅:前复权[%s]' % day, stock.get('最新涨跌幅', 0)))) if len(stocks) == 0: return '-' return float(str('%.2f' % float(total / len(stocks))))
def getHistoryData(): global hasWriteHeader, a daylength = 5 # currentDay = '20200106' currentDay = getCurrentTradeDay() for i in range(0, daylength): values = getData(currentDay) # values= a[currentDay] worksheet.write(letter[0] + str(daylength-(i-1)), datetime.datetime.strptime(currentDay, '%Y%m%d').strftime("%Y/%m/%d")) for index, value in enumerate(values): worksheet.write(letter[index+1] + str(daylength -(i-1)), value) print(i, currentDay, values) currentDay = getLastTradeDay(currentDay) hasWriteHeader = True
def getData(day = getCurrentTradeDay()): global hasWriteHeader categories = getCategories(day) max = len(categories) values = [] if not hasWriteHeader: worksheet.write('A1', '日期') for d in range(0, max): value = None category = categories[d] if 'func' in category: value = category['func'] else: value = category.get('method', crawl_earning_of_stocks)(category['category']) # print(category['text'], value) if not hasWriteHeader: worksheet.write(letter[d+1] + '1', category['text']) values.append(value) return values
def crawl_lost_of_stocks(question='曾涨停', day=getCurrentTradeDay()): # print(question) stocks = crawl_stock_data(question) total = 0 upTotal = 0 index = 0 stocks = sorted(stocks, key=lambda stock: float( stock.get('涨跌幅:前复权[%s]' % day, stock.get('最新涨跌幅', 0))), reverse=True) for stock in stocks: topValue = stock['涨停价[%s]' % day] closeValue = stock['收盘价:不复权[%s]' % day] lastDayCloseValue = stock['收盘价:不复权[%s]' % getLastTradeDay(day)] percent = (float(topValue) - float(closeValue)) / lastDayCloseValue * 100 index += 1 # print(index, stock['股票简称'], '回撤值', percent) total += float('%.2f' % float(percent)) if len(stocks) == 0: return '-' return -float(str('%.2f' % float(total / len(stocks))))
from meepwn import crawl_source_data import json import datetime import numpy as np import pandas as pd import tushare as ts import os from tushareUtils import getCurrentTradeDay, getLastSpecificTradeDay, getLastTradeDay token='cee7373f5534cd6ac10783e468db6710767cf637007930de27ce3a08' ts.set_token(token) pro = ts.pro_api() currentDay = getCurrentTradeDay() arr = ['股票简称', 'hqCode'] timearr = ['几天几板','涨停类型', '涨停原因类别'] def getPropertyStr(stcok): t = str(datetime.datetime.now().date()).replace('-', '') # t= '20220121' inner_str = "" for p1 in arr: inner_str += stcok[p1] + ' ' for p2 in timearr: inner_str += stcok[p2 + '[' + t +']'] +' ' return inner_str + '\n' # 打印基础数据 def printBaseData(data, t):
def crawl_index(question='昨日涨停 非st 非新股 非退市', day=getCurrentTradeDay()): stocks = crawl_stock_data(question) percentage = stocks[0]['指数@涨跌幅:前复权[%s]' % day] return float(str('%.2f' % percentage))