Ejemplo n.º 1
0
 def __init__(self, strategy, strategyName):
     self.strategyName = strategyName
     if strategy == 'a':
         self.pm = pathManager(u'康力泉')
     elif strategy == 'b':
         self.pm = pathManager(u'父母')
     self.requestHeaderManager = requestHeaderManager()
Ejemplo n.º 2
0
 def __init__(self, strategy='a'):
     if strategy == 'a':
         self.pm = pathManager(strategyName='康力泉')
     elif strategy == 'b':
         self.pm = pathManager(strategyName='父母')
     self.fundCategorys = self.getFundCategorys()
     self.colorConstants = colorConstants()
     self.fundJsonFilePathExt = ''
     self.dingtalk = dingtalk()
Ejemplo n.º 3
0
    def __init__(self, strategy='a'):

        self.totalMarketCap = 0.0
        self.totalGain = 0.0
        self.results = []
        self.strategy = strategy
        if strategy == 'a':
            self.pm = pathManager(strategyName=u'康力泉')
        elif strategy == 'b':
            self.pm = pathManager(strategyName=u'父母')
        self.headerManager = requestHeaderManager()
Ejemplo n.º 4
0
 def __init__(self,strategy):
     # 补充 150 份
     self.urlForPlan150 = u'https://qieman.com/pmdj/v2/long-win/ca/assets-summary?capitalAccountId=CA8UKLYHA67WPK&useV2OrderApi=true&classify=true'
     # S 定投
     self.urlForPlanS = u'https://qieman.com/pmdj/v2/long-win/ca/assets-summary?capitalAccountId=CA8FCJKFPANTP2&useV2OrderApi=true&classify=true'
     # ★ 填写验证必须参数
     self.headerManager = requestHeaderManager()
     if strategy == 'a':
         self.pm = pathManager('康力泉')
     elif strategy == 'b':
         self.pm = pathManager('父母')
Ejemplo n.º 5
0
    def __init__(self, strategy='a'):
        url = 'https://danjuanapp.com/djapi/holding/plan/'

        self.luosidingUrl = url + u'CSI666'
        self.dingdingbao90 = url + u'CSI1021'
        self.dingdingbao365 = url + u'CSI1019'

        self.strategy = strategy
        if strategy == 'a':
            self.pm = pathManager(strategyName='康力泉')
        elif strategy == 'b':
            self.pm = pathManager(strategyName='父母')
        self.headerManager = requestHeaderManager()
Ejemplo n.º 6
0
 def __init__(self, strategy='a'):
     if strategy == 'a':
         self.pm = pathManager(strategyName='康力泉')
     elif strategy == 'b':
         self.pm = pathManager(strategyName='父母')
     self.fundCategorys = self.getFundCategorys()
     categoryConstants = assetCategoryConstants()
     self.category1Array = categoryConstants.category1Array
     self.category2Array = categoryConstants.category2Array
     self.category3Array = categoryConstants.category3Array
     self.modelArray = []
     self.colorConstants = colorConstants()
     self.accountManager = accountManager()
     self.fundJsonFilePathExt = ''
     self.dingtalk = dingtalk()
Ejemplo n.º 7
0
 def __init__(self, strategy='a'):
     categoryConstants = assetCategoryConstants()
     self.colorConstants = colorConstants()
     self.category1Array = categoryConstants.category1Array
     self.category2Array = categoryConstants.category2Array
     self.category3Array = categoryConstants.category3Array
     self.modelArray = []
     self.jsonStr = u''
     self.echarts = []
     self.strategy = strategy
     if strategy == 'a':
         self.pm = pathManager(strategyName='康力泉')
     elif strategy == 'b':
         self.pm = pathManager(strategyName='父母')
     elif strategy == 'd':
         self.pm = pathManager(strategyName='全家')
Ejemplo n.º 8
0
 def requestWithName(self, url, name, header):
     headers = header
     if url == None:
         url = self.luosidingUrl
     ssl._create_default_https_context = ssl._create_unverified_context
     requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
     response = requests.get(url, headers=headers, verify=False)
     pm = pathManager()
     with open(os.path.join(self.pm.holdingOutputPath,
                            u'danjuan_{}.txt'.format(name)),
               'w',
               encoding='utf-8') as f:
         data = json.loads(response.text)['data']
         titleLine = u'{0}\t总市值\t{1}\t累计收益\t{2}'.format(
             name, round(data['total_assets'], 2),
             round(data['total_gain'], 2))
         print(titleLine)
         f.write(titleLine + '\n')
         headerLine = u'基金名称\t基金代码\t持仓成本\t持仓份额\t持仓市值\t累计收益'
         print(headerLine)
         f.write(headerLine + '\n')
         for item in data['items']:
             # 名称,代码,持仓成本,持仓份额,持仓市值,累计收益
             seq = (item['fd_name'],item['fd_code'],str(round(item['holding_cost'],4)),\
             str(round(item['volume'],2)),str(round(item['market_value'],2)),str(round(item['total_gain'],2)))
             print(u'\t'.join(seq))
             f.write(u'\t'.join(seq) + '\n')
         print('\n')
Ejemplo n.º 9
0
    def dataFormat(self):
        if not os.path.exists(self.path):
            print(u'[ERROR] 当前文件夹下未找到 {0}'.format(self.path))
            exit()

        # 读取 + 计算必要信息
        with open(self.path, 'r', encoding='utf-8') as inputfile:
            headers = inputfile.readline().replace('\n', '').split('\t')
            for col in self.neededColumnNames:
                if col in headers:
                    index = headers.index(col)
                    #print(col,index)
                    self.neededColumnIndexs.append(index)
                else:
                    continue
            if len(self.neededColumnIndexs) < 6:
                print(u'[ERROR] 所需列数不足。当前列数:{0}'.format(
                    len(self.neededColumnIndexs)))
                exit()
            # 读取并暂存数据(inputfile.readline() 已经让内部游标 +1 了,所以 readlines() 将是从第一行数据开始)
            for line in inputfile.readlines():
                data = line.replace('\n', '').split('\t')
                # 用雪球获取场内净值
                manager = fundEstimateManager()
                innerMarketData = manager.estimateInnerMarketETF(
                    data[self.neededColumnIndexs[1]])
                lastNetValue = float(innerMarketData[2])
                lastMarketCap = round(lastNetValue *
                                      float(data[self.neededColumnIndexs[3]]),
                                      2)  # 最新净值 * 仓位
                lastTotalGain = round(
                    (lastNetValue - float(data[self.neededColumnIndexs[2]])) *
                    float(data[self.neededColumnIndexs[3]]), 2)
                # 名称,代码,持仓成本,持仓份额,持仓市值,累计收益
                seq = (data[self.neededColumnIndexs[0]],data[self.neededColumnIndexs[1]],data[self.neededColumnIndexs[2]],\
                        data[self.neededColumnIndexs[3]],str(lastMarketCap), str(lastTotalGain))
                self.totalMarketCap = self.totalMarketCap + round(
                    float(lastMarketCap), 2)
                self.totalGain = self.totalGain + round(
                    float(lastTotalGain), 2)
                self.results.append(u'\t'.join(seq))

        # 写入输出文件
        pm = pathManager()
        with open(os.path.join(pm.holdingOutputPath, u'huatai_康力泉.txt'),
                  'w',
                  encoding='utf-8') as outfile:
            titleLine = u'{0}\t总市值\t{1}\t累计收益\t{2}'.format(
                u'华泰证券', round(self.totalMarketCap, 2),
                round(self.totalGain, 2))
            print(titleLine)
            outfile.write(titleLine + '\n')
            headerLine = u'基金名称\t基金代码\t持仓成本\t持仓份额\t持仓市值\t累计收益'
            print(headerLine)
            outfile.write(headerLine + '\n')
            for item in self.results:
                # 名称,代码,持仓成本,持仓份额,持仓市值,累计收益
                print(item)
                outfile.write(item + '\n')
            print('\n')
Ejemplo n.º 10
0
 def requestWithName(self, name):
     headers = self.headerManager.getGuangfaKLQ()
     ssl._create_default_https_context = ssl._create_unverified_context
     requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
     response = requests.get(self.url, headers=headers, verify=False)
     pm = pathManager()
     with open(os.path.join(pm.holdingOutputPath,
                            u'guangfa_{}.txt'.format(name)),
               'w',
               encoding='utf-8') as f:
         jsonData = json.loads(response.text)['data']
         contentList = jsonData['fundPositionGainList']
         for data in contentList:
             # 注意:我们只要广发基金中,来自于蚂蚁金服的份额。这一部分是支付宝买的
             if data['fundCode'] == '001064':
                 for buyInfo in data['fundAgencyPositionGains']:
                     if buyInfo[u'agencyName'] == u'蚂蚁杭州':
                         titleLine = u'{0}\t总市值\t{1}\t累计收益\t{2}'.format(
                             name, round(float(buyInfo['totalBalance']), 2),
                             round(float(buyInfo['positionGain']), 2))
                         print(titleLine)
                         f.write(titleLine + '\n')
                         headerLine = u'基金名称\t基金代码\t持仓成本\t持仓份额\t持仓市值\t累计收益'
                         print(headerLine)
                         f.write(headerLine + '\n')
                         # 名称,代码,持仓成本,持仓份额,持仓市值,累计收益
                         seq = (data['fundName'],data['fundCode'],str(round(float(buyInfo['purchasePrice']),4)),\
                         str(round(float(buyInfo['currentShares']),2)),str(round(float(buyInfo['totalBalance']),2)),str(round(float(buyInfo['positionGain']),2)))
                         print(u'\t'.join(seq))
                         print(u'\n\n')
                         f.write(u'\t'.join(seq) + '\n')
                         break
                 break
             print('\n')
Ejemplo n.º 11
0
 def functionSelect(self, event):
     print("功能选择:%s" % event.widget['text'])
     params = event.widget['text'].split(' ')
     pm = pathManager()
     if params[0] == u'allFundSpider':
         pyFile = os.path.join(
             pm.parentDir, u'allFundSpiderMultiProcess.py')  # 切换到多线程并发的版本
         args = [r"powershell", "python", pyFile, params[1]]
         print('[Executing] {0} {1} ...'.format(pyFile, params[1]))
         p = subprocess.Popen(args)
     if params[0] == u'assetCombine':
         pyFile = os.path.join(pm.parentDir, u'assetAllocationCombine.py')
         args = [r"powershell", "python", pyFile, params[1]]
         print('[Executing] {0} {1} ...'.format(pyFile, params[1]))
         p = subprocess.Popen(args)
     if params[0] == u'estimateFund':
         # html
         pyFile = os.path.join(pm.parentDir,
                               u'assetAllocationEstimateHtmlParser.py')
         args = [r"powershell", "python", pyFile, params[1]]
         print('[Executing] {0} {1} ...'.format(pyFile, params[1]))
         p = subprocess.Popen(args)
         # excel
         pyFile = os.path.join(pm.parentDir,
                               u'assetAllocationEstimateExcelParser.py')
         args = [r"powershell", "python", pyFile, params[1]]
         print('[Executing] {0} {1} ...'.format(pyFile, params[1]))
         p = subprocess.Popen(args)
Ejemplo n.º 12
0
 def shorthandSelect(self, event):
     # print("打开:%s" % event.widget['text'].replace(' Folder',''))
     param = event.widget['text'].replace(' Folder', '')
     pm = pathManager()
     if param == u'src':
         os.startfile(pm.parentDir)
     if param == u'config':
         os.startfile(pm.configPath)
     if param == u'input':
         os.startfile(pm.inputPath)
     if param == u'output':
         os.startfile(pm.outputPath)
     if param == u'echarts':
         os.startfile(pm.echartsPath)
     if param == u'fetch Headers':
         # 打开所有网页
         os.startfile(u'http://login.1234567.com.cn/')
         os.startfile(u'http://www.gffunds.com.cn/')
         os.startfile(u'http://www.qieman.com/')
         os.startfile(u'http://www.danjuanapp.com/')
         os.startfile(u'http://www.xueqiu.com/')
         # 把 Charles Filter 字符串写入剪切板和控制台
         text = u'(gffunds.com.cn/mapi/account/assets/summary)|(https://qieman.com/pmdj/v2/uma/(.*?)/detail)|(https://danjuanapp.com/djapi/account/user_info_check)|(https://trade(.*?).1234567.com.cn/do.aspx/CheckLogin)|(https://www.sui.com/account/account.do)'
         print(u'Charles Filter Text:\n\n\{0}\n\n已经自动写入剪切板'.format(text))
         self.window.clipboard_clear()  # 清除剪贴板内容
         self.window.clipboard_append(text)  # 向剪贴板追加内容
Ejemplo n.º 13
0
    def __init__(self):
        self.pm = pathManager()
        self.colorManager = colorConstants()
        self.allAccounts = []
        dataPath = os.path.join(self.pm.configPath, 'account.json')

        if os.path.exists(dataPath):
            with open(dataPath, 'r', encoding='utf-8') as f:
                self.allAccounts = json.loads(f.read())
Ejemplo n.º 14
0
 def __init__(self):
     self.pm = pathManager()
     self.fundCategorys = self.getFundCategorys()
     categoryConstants = assetCategoryConstants()
     self.category1Array = categoryConstants.category1Array
     self.category2Array = categoryConstants.category2Array
     self.category3Array = categoryConstants.category3Array
     self.modelArray = []
     self.colorConstants = colorConstants()
Ejemplo n.º 15
0
 def __init__(self):
     pm = pathManager()
     self.path = os.path.join(pm.inputPath, u'huatai.txt')
     self.results = []
     self.neededColumnNames = [
         u'证券名称', u'证券代码', u'成本价', u'证券数量', u'最新市值', u'浮动盈亏'
     ]
     self.neededColumnIndexs = []
     self.totalMarketCap = 0.0
     self.totalGain = 0.0
Ejemplo n.º 16
0
 def __init__(self):
     self.requestHeaderManager = requestHeaderManager()
     self.pm = pathManager()
     self.indexValueInfoList = []
     self.indexValues = []
     self.qiemanEvaluations = []
     self.danjuanEvaluations = []
     # 读取磁盘数据
     with open(os.path.join(self.pm.configPath,u'indexValueInfo.json'),u'r',encoding='utf-8') as f:
         self.indexValueInfoList = json.loads(f.read())
 def __init__(self, path):
     self.pm = pathManager()
     self.colorConstants = colorConstants()
     categoryConstants = assetCategoryConstants()
     self.category1Array = categoryConstants.category1Array
     self.category2Array = categoryConstants.category2Array
     self.category3Array = categoryConstants.category3Array
     self.indexValueInfo = indexValueInfo()
     self.historyManager = historyProfitManager()
     self.dingtalk = dingtalk()
     self.outputPath = path
Ejemplo n.º 18
0
 def __init__(self):
     self.pm = pathManager()
     self.category_df = pd.read_excel(
         path.join(self.pm.configPath, '资产配置分类表.xlsx'))
     # 把数字补 0 改成 字符串
     self.category_df['基金代码'] = self.category_df['基金代码'].apply(
         lambda x: str(x).zfill(6))
     self.allCodes = list(self.category_df.基金代码.unique())
     self.category1Array = list(self.category_df.一级分类.unique())
     self.category2Array = list(self.category_df.二级分类.unique())
     self.category3Array = list(self.category_df.三级分类.unique())
Ejemplo n.º 19
0
 def __init__(self):
     self.pm = pathManager()
     self.fundCategorys = self.getFundCategorys()
     self.historyManager = historyProfitManager()
     categoryConstants = assetCategoryConstants()
     self.category1Array = categoryConstants.category1Array
     self.category2Array = categoryConstants.category2Array
     self.category3Array = categoryConstants.category3Array
     self.modelArray = []
     self.accountManager = accountManager()
     self.colorConstants = colorConstants()
     self.dingtalk = dingtalk()
Ejemplo n.º 20
0
    def __init__(self):
        self.pm = pathManager()
        self.history_df = pd.read_excel(
            path.join(self.pm.configPath, '历史交易盈亏.xlsx'))
        # 把数字补 0 改成 字符串
        self.history_df['基金代码'] = self.history_df['基金代码'].apply(
            lambda x: str(x).zfill(6))
        self.allCodes = list(self.history_df.基金代码.unique())
        self.category1Array = list(self.history_df.一级分类.unique())
        self.category2Array = list(self.history_df.二级分类.unique())
        self.category3Array = list(self.history_df.三级分类.unique())

        self.parent_df = self.getParentsHistoryProfit()
        self.klq_df = self.getKLQHistoryProfit()
Ejemplo n.º 21
0
 def __init__(self):
     # 场内代码
     self.innerMarketCodes = assetCategoryManager().getEstimableFunds(
         isInnerMarket=True).values()
     self.headerManager = requestHeaderManager()
     self.dateFormat = u'%Y-%m-%d %H:%M:%S'
     self.pm = pathManager()
     self.cacheTimeStamp = 0
     self.cacheFundModelArray = []
     # 尝试查询缓存
     timeStamp, cacheFundModelArray = self.loadCache()
     if timeStamp > 0 and len(cacheFundModelArray) > 0:
         self.cacheTimeStamp = timeStamp
         self.cacheFundModelArray = cacheFundModelArray
Ejemplo n.º 22
0
    def __init__(self):
        auth('13810650842', '123456a')
        print(u'聚宽数据API:{0}'.format(get_query_count()))
        self.pm = pathManager('全家')
        self.colorConstants = colorConstants()
        self.result_df = pd.read_csv(os.path.join(self.pm.holdingOutputPath,u'indexHoldingInfo.csv'), sep='\t')
        self.outputRenameColumns = {'name': '名称', 'code': '代码', 'market_cap': '市值(亿元)', 'pe_ratio': 'pe', 'pb_ratio': 'pb', 'daily_change': '涨跌幅',
                                    'holding': '持有市值(元)', 'daily_gain': '日盈亏', 'hy_code1': '一级行业代码', 'hy_name1': '一级行业名称', 'hy_code2': '二级行业代码', 'hy_name2': '二级行业名称', 'relate_index': '相关指数'}
        # 转置列名的 key-value,作为读入内存后的列名
        self.inputRenameColumns = dict(
            [(value, key) for key, value in self.outputRenameColumns.items()])
        self.result_df = self.result_df.rename(columns=self.inputRenameColumns)

        with open(os.path.join(self.pm.configPath,u'indexIndustryInfo.json'),'r',encoding='utf-8') as f:
            self.swIndexInfos = json.loads(f.read())
Ejemplo n.º 23
0
 def saveHeaderToFile(self, event):
     #print("左键单击:%s" % event.widget['text'])
     clipboardText = self.clipboardValue.get()
     if not self.isSupposeToBeHeaderText(clipboardText):
         result = tkinter.messagebox.showerror(
             u'错误', u'剪切板信息不像是 Header(不包含 User-Agent)')
         return
     else:
         pm = pathManager()
         filename = event.widget['text']
         filepath = os.path.join(pm.configPath, u'requestHeader',
                                 u'{0}.txt'.format(filename))
         print(f'保存文件:{filepath}')
         with open(filepath, 'w', encoding='utf-8') as f:
             f.write(clipboardText)
         result = tkinter.messagebox.showinfo('', u'保存成功')
Ejemplo n.º 24
0
    def __init__(self):
        # 需要比对年线的品种
        self.indexValueInfos = [ \
            {u"category1":u"A 股",u"category2":u"大盘股",u"category3":u"上证50",u"indexCode":u"000016",u"requestCode":u"0000161",u"categoryId":u"111"}, \
            {u"category1":u"A 股",u"category2":u"大盘股",u"category3":u"50AH",u"indexCode":u"000170",u"requestCode":u"0001701",u"categoryId":u"112"}, \
            {u"category1":u"A 股",u"category2":u"大盘股",u"category3":u"沪深300",u"indexCode":u"000300",u"requestCode":u"0003001",u"categoryId":u"113"}, \
            {u"category1":u"A 股",u"category2":u"大盘股",u"category3":u"300价值",u"indexCode":u"000919",u"requestCode":u"0009191",u"categoryId":u"114"}, \
            {u"category1":u"A 股",u"category2":u"大盘股",u"category3":u"基本面60",u"indexCode":u"399701",u"requestCode":u"3997012",u"categoryId":u"115"}, \
            {u"category1":u"A 股",u"category2":u"大盘股",u"category3":u"基本面120",u"indexCode":u"399702",u"requestCode":u"3997022",u"categoryId":u"116"}, \
            {u"category1":u"A 股",u"category2":u"大盘股",u"category3":u"中小板",u"indexCode":u"399005",u"requestCode":u"3990052",u"categoryId":u"117"}, \
            {u"category1":u"A 股",u"category2":u"中小盘股",u"category3":u"中证500",u"indexCode":u"000905",u"requestCode":u"0009051",u"categoryId":u"121"}, \
            {u"category1":u"A 股",u"category2":u"中小盘股",u"category3":u"中证1000",u"indexCode":u"000852",u"requestCode":u"0008521",u"categoryId":u"123"}, \
            {u"category1":u"A 股",u"category2":u"中小盘股",u"category3":u"创业板",u"indexCode":u"399006",u"requestCode":u"3990062",u"categoryId":u"124"}, \
            {u"category1":u"A 股",u"category2":u"红利价值",u"category3":u"中证红利",u"indexCode":u"000922",u"requestCode":u"0009221",u"categoryId":u"131"}, \
            {u"category1":u"A 股",u"category2":u"行业股",u"category3":u"养老产业",u"indexCode":u"399812",u"requestCode":u"3998122",u"categoryId":u"141"}, \
            {u"category1":u"A 股",u"category2":u"行业股",u"category3":u"全指医药",u"indexCode":u"000991",u"requestCode":u"0009911",u"categoryId":u"142"}, \
            {u"category1":u"A 股",u"category2":u"行业股",u"category3":u"中证环保",u"indexCode":u"000827",u"requestCode":u"0008271",u"categoryId":u"143"}, \
            {u"category1":u"A 股",u"category2":u"行业股",u"category3":u"中证传媒",u"indexCode":u"399971",u"requestCode":u"3999712",u"categoryId":u"144"}, \
            {u"category1":u"A 股",u"category2":u"行业股",u"category3":u"证券公司",u"indexCode":u"399975",u"requestCode":u"3999752",u"categoryId":u"145"}, \
            {u"category1":u"A 股",u"category2":u"行业股",u"category3":u"金融地产",u"indexCode":u"000992",u"requestCode":u"0009921",u"categoryId":u"146"}, \
            {u"category1":u"A 股",u"category2":u"行业股",u"category3":u"全指消费",u"indexCode":u"000990",u"requestCode":u"0009901",u"categoryId":u"147"}, \
            {u"category1":u"海外新兴",u"category2":u"香港",u"category3":u"恒生",u"indexCode":u"HSI5",u"requestCode":u"HSI5",u"categoryId":u"211"}, \
            {u"category1":u"海外新兴",u"category2":u"台湾",u"category3":u"台湾加权",u"indexCode":u"TWII_UI",u"requestCode":u"TWII_UI",u"categoryId":u"213"}, \
            {u"category1":u"海外新兴",u"category2":u"日本",u"category3":u"日经225",u"indexCode":u"N225_UI",u"requestCode":u"N225_UI",u"categoryId":u"214"}, \
            {u"category1":u"海外成熟",u"category2":u"海外成熟",u"category3":u"德国30",u"indexCode":u"GDAXI_UI",u"requestCode":u"GDAXI_UI",u"categoryId":u"311"}, \
            {u"category1":u"海外成熟",u"category2":u"海外成熟",u"category3":u"富时100",u"indexCode":u"FTSE_UI",u"requestCode":u"FTSE_UI",u"categoryId":u"312"}, \
            {u"category1":u"海外成熟",u"category2":u"海外成熟",u"category3":u"法国40",u"indexCode":u"FCHI_UI",u"requestCode":u"FCHI_UI",u"categoryId":u"313"}, \
            {u"category1":u"海外成熟",u"category2":u"海外成熟",u"category3":u"道琼斯",u"indexCode":u"DJIA_UI",u"requestCode":u"DJIA_UI",u"categoryId":u"314"}, \
            {u"category1":u"海外成熟",u"category2":u"海外成熟",u"category3":u"纳斯达克",u"indexCode":u"NDX_UI",u"requestCode":u"NDX_UI",u"categoryId":u"315"}, \
            {u"category1":u"海外成熟",u"category2":u"海外成熟",u"category3":u"标普500",u"indexCode":u"SPX_UI",u"requestCode":u"SPX_UI",u"categoryId":u"316"}, \
            {u"category1":u"债券",u"category2":u"国内债券",u"category3":u"可转债",u"indexCode":u"000832",u"requestCode":u"0008321",u"categoryId":u"411"}, \
            {u"category1":u"商品",u"category2":u"商品",u"category3":u"黄金",u"indexCode":u"GC00Y",u"requestCode":u"GC00Y0",u"categoryId":u"511"}, \
            {u"category1":u"商品",u"category2":u"商品",u"category3":u"原油",u"indexCode":u"CL00Y",u"requestCode":u"CL00Y0",u"categoryId":u"512"}, \
            {u"category1":u"商品",u"category2":u"商品",u"category3":u"白银",u"indexCode":u"SI00Y",u"requestCode":u"SI00Y0",u"categoryId":u"513"} \
        ]

        self.colorConstants = colorConstants()

        self.pm = pathManager()
        self.outputDir = os.path.join(self.pm.outputPath,
                                      u'indexYearDataCompare')
        if not os.path.exists(self.outputDir):
            os.makedirs(self.outputDir)
Ejemplo n.º 25
0
 def getParent(self):
     fileNameExt = u'父母'
     self.pm = pathManager(strategyName=fileNameExt)
     # 多线程并发(都传策略 b)
     for pyFile in self.parentSpidersArray:
         args = [
             r"powershell", "python",
             os.path.join(self.pm.spiderPath, pyFile), "b"
         ]
         print('[Executing] {0} b...'.format(
             os.path.join(self.pm.spiderPath, pyFile)))
         p = subprocess.Popen(args)
     # 拷贝文件
     fileName = u'cash_{0}.txt'.format(u'父母')
     shutil.copy(os.path.join(self.pm.inputPath, fileName),
                 os.path.join(self.pm.holdingOutputPath, fileName))
     with open(os.path.join(self.pm.holdingOutputPath, fileName),
               'r',
               encoding='utf-8') as f:
         for line in f.readlines():
             print(line, end='')
Ejemplo n.º 26
0
    def requestWithName(self, name, header, singleHeader):
        """
        天天基金的爬虫略麻烦:
        1)请求为 POST 记得附带参数
        2)持仓摊薄成本和持仓份额需要进行二次查询,去 detail 页面解析
        3)需要通过解析 html 标签取值,接口返回的是 html 代码
        """
        headers = header
        # 天天基金 Post 请求的配置参数
        postData = json.dumps({
            'type': '0',
            'sorttype': '5',
            'isNeedTotal': 'true'
        })
        ssl._create_default_https_context = ssl._create_unverified_context
        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
        response = requests.post(self.url,
                                 verify=False,
                                 headers=headers,
                                 data=postData)
        data = json.loads(response.text)

        html = json.loads(data['d'])['content']
        soup = BeautifulSoup(html, 'lxml')
        # 取出条目列表
        contentList = soup.find_all('tr')
        totalCount = len(contentList)
        current = 1
        pm = pathManager()
        with open(os.path.join(self.pm.holdingOutputPath,
                               'tiantian_{}.txt'.format(name)),
                  'w',
                  encoding='utf-8') as f:
            for item in contentList:
                # 取出所有 td
                tds = item.find_all('td')
                a = item.find(attrs={'class': u'btn-more f14'})
                # 拼接详情页 URL
                detailUrl = self.urlPrefix + a.get('href')
                # 从持仓详情页,取出品种的 摊薄单价 & 持仓份额
                ssl._create_default_https_context = ssl._create_unverified_context
                requests.packages.urllib3.disable_warnings(
                    InsecureRequestWarning)
                # 老妈的天天基金详情需要独立的请求 header 无奈出此下策
                singleHeaders = singleHeader

                detailResponse = requests.get(detailUrl,
                                              headers=singleHeaders,
                                              verify=False)
                # e.g.
                # <span id="tanbaodanjia">摊薄单价(元):<span class="number14">1.0193</span></span>
                # <div class="h20"><span class="ft w220">持仓份额(份):<span class="numbergray14">65064.33</span></span></div>
                detailSoup = BeautifulSoup(detailResponse.text, 'lxml')
                # 持仓成本
                price = detailSoup.find(id=u'tanbaodanjia').span.text
                h20s = detailSoup.find_all(attrs={'class': 'h20'})
                # 持仓份额
                volume = h20s[0].span.span.text
                partent = re.compile(u'^(.*?)((.*?))$')
                re_get = re.findall(partent, tds[0].p.a.text)
                # 名称
                fundName = re_get[0][0]
                # 代码
                fundCode = re_get[0][1]
                # 持仓市值
                partent2 = re.compile(u'([0-9]+.[0-9]+)')  # 123.45 排除“有在途交易”
                re_get2 = re.findall(partent2, tds[1].text.replace(',', ''))
                marketValue = re_get2[0]
                # 累计收益
                totalGain = tds[2].span.text.replace(',', '')
                seq = (re_get[0][0],re_get[0][1],price,\
                volume,marketValue,totalGain)
                self.results.append(u'\t'.join(seq))
                # 计算整体情况
                self.totalMarketCap = self.totalMarketCap + round(
                    float(marketValue), 2)
                self.totalGain = self.totalGain + round(float(totalGain), 2)
                print('\r天天基金进度:{0:.2f}% {1} / {2}'.format(
                    float(current) / totalCount * 100, current, totalCount),
                      end='',
                      flush=True)
                if current == totalCount:
                    print('\n')
                current = current + 1
            # 开始写入整体情况
            titleLine = u'{0}\t总市值\t{1}\t累计收益\t{2}'.format(
                u'天天基金', round(self.totalMarketCap, 2),
                round(self.totalGain, 2))
            print(titleLine)
            f.write(titleLine + '\n')
            # 写入表头
            headerLine = u'基金名称\t基金代码\t持仓成本\t持仓份额\t持仓市值\t累计收益'
            print(headerLine)
            f.write(headerLine + '\n')
            for string in self.results:
                print(string)
                f.write(string + '\n')
            print('\n')
 def __init__(self, strategyName, skipUpdateIfExist=False):
     self.strategyName = strategyName
     self.pm = pathManager(self.strategyName)
     self.colorConstants = colorConstants()
     self.echarts = []
     # 市值情况
     with open(os.path.join(self.pm.configPath, 'indexHoldingInfo.json'),
               u'r',
               encoding=u'utf-8') as f:
         self.holdingInfos = json.loads(f.read())
     # print(self.holdingInfos)
     # 输出时切换到中文列名
     self.outputRenameColumns = {
         'name': '名称',
         'code': '代码',
         'market_cap': '市值(亿元)',
         'pe_ratio': 'pe',
         'pb_ratio': 'pb',
         'daily_change': '涨跌幅',
         'holding': '持有市值(元)',
         'daily_gain': '日盈亏',
         'hy_code1': '一级行业代码',
         'hy_name1': '一级行业名称',
         'hy_code2': '二级行业代码',
         'hy_name2': '二级行业名称',
         'relate_index': '相关指数'
     }
     # 转置列名的 key-value,作为读入内存后的列名
     self.inputRenameColumns = dict([
         (value, key) for key, value in self.outputRenameColumns.items()
     ])
     # print(self.inputRenameColumns)
     # 个股持仓明细表
     cachFile = os.path.join(self.pm.holdingOutputPath,
                             'indexHoldingInfo.csv')
     if (not os.path.exists(cachFile)) or (not skipUpdateIfExist):
         shouldUpdate = True
     else:
         shouldUpdate = False
     if not shouldUpdate:
         # print('indexHoldingInfo.csv 存在... 是否需要在线更新?[Y/N]')
         # choice = str(input()).upper()
         # # 这里只要不是 Y 都不更新了,防止过多查询聚宽
         # if choice != 'Y':
         # shouldUpdate = False
         self.result_df = pd.read_csv(cachFile, sep='\t')
         self.result_df = self.result_df.rename(
             columns=self.inputRenameColumns)
         #print('日盈亏:{0} 元'.format(round(self.result_df.daily_gain.sum(), 2)))
     else:
         # 登录
         auth('13810650842', '123456a')
         print(u'聚宽数据API:{0}'.format(get_query_count()))
         self.result_df = self.generateDataFrameCSVFile()
     # 申万指数 json
     with open(os.path.join(self.pm.configPath, u'indexIndustryInfo.json'),
               'r',
               encoding='utf-8') as f:
         self.swIndexInfos = json.loads(f.read())
     self.result_df = self.result_df.rename(columns=self.inputRenameColumns)
     self.generateEchartsModels(self.result_df)
     self.generateJSObjectFile(
         '全家')  # 这里暂时没有使用 strategyName 作为输出标识符,后面应该想想更好的办法
     # 打开
     if sys.platform.startswith('win'):
         os.startfile(
             os.path.join(self.pm.echartsPath, u'FamilyStockIndustry.html'))
Ejemplo n.º 28
0
 def intelligentMatchHeader(self, text):
     if self.isSupposeToBeHeaderText(text):
         print(u'\n\n[Attention] 监测到疑似 Header 数据')
     pm = pathManager()
     # 尝试匹配且慢
     if u'x-sign' in text and self.isSupposeToBeHeaderText(text):
         print(u'[Success] 成功匹配到网站 Header:且慢')
         result = tkinter.messagebox.askokcancel(
             '成功匹配“且慢”', '要把剪切板上的内容覆盖到 qieman_klq.txt 吗?')
         if result == True:
             filepath = os.path.join(pm.configPath, u'requestHeader',
                                     u'qieman_klq.txt')
             print(filepath)
             with open(filepath, 'w', encoding=u'utf-8') as f:
                 f.write(text)
         else:
             print(result)
         return
     # 尝试匹配广发基金
     if u'/mapi/account/assets/summary' in text and self.isSupposeToBeHeaderText(
             text):
         print(u'[Success] 成功匹配到网站 Header:广发基金')
         result = tkinter.messagebox.askokcancel(
             '成功匹配“广发基金”', '要把剪切板上的内容覆盖到 guangfa_klq.txt 吗?')
         if result == True:
             filepath = os.path.join(pm.configPath, u'requestHeader',
                                     u'guangfa_klq.txt')
             print(filepath)
             with open(filepath, 'w', encoding=u'utf-8') as f:
                 f.write(text)
         else:
             print(result)
         return
     # 尝试匹配雪球
     if u'u=2812376209' in text and self.isSupposeToBeHeaderText(text):
         print(u'[Success] 成功匹配到网站 Header:雪球')
         result = tkinter.messagebox.askokcancel(
             '成功匹配“雪球”', '要把剪切板上的内容覆盖到 xueqiu_klq.txt 吗?')
         if result == True:
             filepath = os.path.join(pm.configPath, u'requestHeader',
                                     u'xueqiu_klq.txt')
             print(filepath)
             with open(filepath, 'w', encoding=u'utf-8') as f:
                 f.write(text)
         else:
             print(result)
         return
     # 尝试匹配蛋卷基金 - 康力泉
     if u'gr_user_id=07a8b8b8-e04f-4bfa-b6bd-3492bb42b3a6' in text and self.isSupposeToBeHeaderText(
             text):
         print(u'[Success] 成功匹配到网站 Header:蛋卷基金 - 康力泉')
         result = tkinter.messagebox.askokcancel(
             '成功匹配“蛋卷基金 - 康力泉”', '要把剪切板上的内容覆盖到 danjuan_klq.txt 吗?')
         if result == True:
             filepath = os.path.join(pm.configPath, u'requestHeader',
                                     u'danjuan_klq.txt')
             print(filepath)
             with open(filepath, 'w', encoding=u'utf-8') as f:
                 f.write(text)
         else:
             print(result)
         return
     # 尝试匹配随手记 - 康力泉
     if u':path\t/account/account.do' in text and self.isSupposeToBeHeaderText(
             text):
         print(u'[Success] 成功匹配到网站 Header:随手记 - 康力泉')
         result = tkinter.messagebox.askokcancel(
             '成功匹配“随手记 - 康力泉”', '要把剪切板上的内容覆盖到 sui_klq.txt 吗?')
         if result == True:
             filepath = os.path.join(pm.configPath, u'requestHeader',
                                     u'sui_klq.txt')
             print(filepath)
             with open(filepath, 'w', encoding=u'utf-8') as f:
                 f.write(text)
         else:
             print(result)
         return
Ejemplo n.º 29
0
 def __init__(self):
     self.pm = pathManager()
     self.prepareTimePeriod()
     self.run()
     pass
Ejemplo n.º 30
0
    def __init__(self, strategy='a'):
        self.strategy = strategy  # 默认 A 策略,即康力泉(不含现金和冻结资金)
        # 拿取最新基金净值
        self.navManager = fundNavManager()
        # 拿一下最新的资产分类配置
        assetCategoryManager().generateFundCategoryJsonFile()
        # 拿取最新指数值
        self.headerManager = requestHeaderManager()
        self.indexValueInfo = indexValueInfo()
        self.indexValueInfo.update()
        # 根据策略生成对于的变量配置参数
        if self.strategy == 'a':
            self.filenames = [
                u'danjuan_螺丝钉.txt', u'danjuan_钉钉宝365.txt',
                u'qieman_10万补充ETF计划.txt', u'qieman_我的S定投计划.txt',
                u'tiantian_康力泉.txt', u'huatai_康力泉.txt', u'huabao_康力泉.txt',
                u'guangfa_支付宝.txt'
            ]
            self.excelFilePathExt = u'康力泉权益类'
            self.echartsJSFilePathExt = u'康力泉'
            self.pm = pathManager(strategyName=u'康力泉')
            self.echartsFile = u'KLQPortfolio.html'
            self.filepaths = []
            for root, dirs, files in os.walk(self.pm.holdingOutputPath,
                                             topdown=False):
                for name in files:
                    if name in self.filenames:
                        self.filepaths.append(os.path.join(root, name))
        elif self.strategy == 'b':
            self.filenames = [
                u'danjuan_母螺丝钉.txt', u'danjuan_父螺丝钉.txt', 'danjuan_母钉钉宝90.txt',
                u'danjuan_母钉钉宝365.txt', u'danjuan_父钉钉宝90.txt',
                u'danjuan_父钉钉宝365.txt', u'tiantian_李淑云.txt', 'cash_父母.txt'
            ]
            self.excelFilePathExt = u'父母'
            self.echartsJSFilePathExt = u'父母'
            self.pm = pathManager(strategyName=u'父母')
            self.echartsFile = u'ParentPortfolio.html'
            self.filepaths = []
            for root, dirs, files in os.walk(self.pm.holdingOutputPath,
                                             topdown=False):
                for name in files:
                    if name in self.filenames:
                        self.filepaths.append(os.path.join(root, name))
        elif self.strategy == 'c':
            self.filenames = [
                u'danjuan_螺丝钉.txt', u'danjuan_钉钉宝365.txt',
                u'qieman_10万补充ETF计划.txt', u'qieman_我的S定投计划.txt',
                u'tiantian_康力泉.txt', u'huatai_康力泉.txt', u'huabao_康力泉.txt',
                u'guangfa_支付宝.txt', u'cash_康力泉.txt', u'freeze_康力泉.txt'
            ]
            self.excelFilePathExt = u'康力泉整体'
            self.echartsJSFilePathExt = u'康力泉'
            self.pm = pathManager(strategyName=u'康力泉')
            self.echartsFile = u'KLQPortfolio.html'
            self.filepaths = []
            for root, dirs, files in os.walk(self.pm.holdingOutputPath,
                                             topdown=False):
                for name in files:
                    if name in self.filenames:
                        self.filepaths.append(os.path.join(root, name))
        elif self.strategy == 'd':
            self.filenames = [u'danjuan_螺丝钉.txt',u'danjuan_钉钉宝365.txt',u'qieman_10万补充ETF计划.txt',u'qieman_我的S定投计划.txt', u'tiantian_康力泉.txt',u'huatai_康力泉.txt',u'huabao_康力泉.txt',u'guangfa_支付宝.txt',u'cash_康力泉.txt',u'freeze_康力泉.txt'\
                ,u'danjuan_母螺丝钉.txt',u'danjuan_父螺丝钉.txt','danjuan_母钉钉宝90.txt',u'danjuan_母钉钉宝365.txt',u'danjuan_父钉钉宝90.txt',u'danjuan_父钉钉宝365.txt',u'tiantian_李淑云.txt','cash_父母.txt']
            self.excelFilePathExt = u'全家整体'
            self.echartsJSFilePathExt = u'全家'
            self.pm = pathManager(strategyName=u'全家')
            klqDir = os.path.join(os.path.dirname(self.pm.holdingOutputPath),
                                  u'康力泉')
            parentDir = os.path.join(
                os.path.dirname(self.pm.holdingOutputPath), u'父母')
            self.filepaths = []
            print(u'全家整体情况,包含如下文件:')
            for root, dirs, files in os.walk(klqDir, topdown=False):
                for name in files:
                    if name in self.filenames:
                        self.filepaths.append(os.path.join(root, name))
                        print(os.path.join(root, name))
            for root, dirs, files in os.walk(parentDir, topdown=False):
                for name in files:
                    if name in self.filenames:
                        self.filepaths.append(os.path.join(root, name))
                        print(os.path.join(root, name))
            self.echartsFile = u'FamilyPortfolio.html'

        # 持仓基金数据的本地保存路径标识
        self.fundJsonFilePathExt = self.excelFilePathExt
        self.fundCategorys = self.getFundCategorys()

        # 基金数据模型集合
        self.fundModelArray = []
        # 资产配置对象模型集合
        self.assetModelArray = []
        # 开始生成
        self.generateJsonFiles()