Пример #1
0
    def get_active_sale_department(self):
        current_day = date_time_util.get_date(0)
        count = "500"
        # 查询当日活跃营业部
        url = crawl_html_url.east_money_active_sale_department.format(count,current_day,current_day)
        data = requests.get(url)
        data.encoding = "GBK"
        sales_department = json.loads(data.text[15:])["data"]
        # 遍历每个营业部买卖股票
        for sale_department in sales_department:
            department_code = sale_department["YybCode"]
            stocks = sale_department["SName"]
            if stocks == '':
                continue
            stock_arry = json.loads(stocks)

            #查询改营业部下 每个股票的资金流入
            stock = requests.get(
                crawl_html_url.east_money_active_sale_department_trade_stock_money.format(len(stock_arry),department_code))
            stock.encoding = "GBK"
            single_stocks_capital = json.loads(stock.text[13:])["data"]
            for stock_capital in single_stocks_capital:
                param = []
                param.append(stock_capital["SalesName"])
                param.append(stock_capital["SalesCode"])
                param.append(stock_capital["SName"])
                param.append(stock_capital["SCode"])
                param.append(stock_capital["TDate"])
                param.append(stock_capital["CTypeDes"])
                param.append( 0 if stock_capital["BMoney"] == '' else stock_capital["BMoney"])
                param.append(0 if stock_capital["SMoney"] == '' else stock_capital["SMoney"])
                param.append(0 if stock_capital["PBuy"] == '' else stock_capital["PBuy"])
                self.capital_dao.add_sale_department_trade(param)
Пример #2
0
 def save_other_strategy_choose(self, stock_info):
     strategy_id = str(stock_info[4]) + ","
     stock_info[4] = "," + strategy_id
     stock_info.append(date_time_util.get_date(0))
     sql = "insert into trade_strategy_record (stock_name,stock_code,current_price,current_rate,strategy_category ,`create_date`) \
           value (%s,%s,%s,%s,%s,%s)  ON DUPLICATE KEY UPDATE  strategy_category = CONCAT(strategy_category,'" + strategy_id + "');"
     self.mysqlService.insert(sql, stock_info)
Пример #3
0
def get_today_two_limit_up():

    pool = mysql_pool.sql_pool()
    today = date_time_util.get_date(0)
    today = "2020-05-15"
    print(today)
    sql = "select stock_name,stock_code from stock_limit_up_analyse where continuous_time = 2  and stock_name not like '%ST%'and create_date = '" + today + "'"
    res = pool.selectMany(sql)

    return res
Пример #4
0
 def get_tiger_list(self):
     today = date_time_util.get_date(0)
     data = requests.get(crawl_html_url.east_monet_tiger_list.format(today))
     data.encoding = "gbk"
     stock_names = json.loads(data.text[15:])["data"]
     for stock in stock_names:
         param = []
         param.append(stock["SCode"])
         param.append(stock["SName"])
         param.append(stock["JD"])
         param.append(stock["ClosePrice"])
         param.append(stock["Chgradio"])
         param.append(stock["Bmoney"])
         param.append(0 if stock["JmMoney"] == '' else stock["JmMoney"])
         param.append(0 if stock["Smoney"] == '' else stock["Smoney"])
         param.append(stock["ZeMoney"])
         param.append(stock["Turnover"])
         param.append(stock["JmRate"])
         param.append(stock["Dchratio"])
         param.append(stock["Ltsz"])
         param.append(stock["Ctypedes"])
         param.append(date_time_util.get_date(0))
         self.capital_dao.add_tiger_list(param)
Пример #5
0
 def save_stock_strategy_record(self,stock_code,data):
     record = []
     data = data.split(",")
     record.append(stock_code)
     record.append(self.redis.hget(redis_key_constants.stock_name_code_mapping,stock_code))
     record.append(date_time_util.get_date(0))
     record.append(data[crawl_html_url.open_price_index])
     record.append(data[crawl_html_url.low_price_index])
     record.append(data[crawl_html_url.high_price_index])
     record.append(data[crawl_html_url.close_price_index])
     record.append(0)
     sql = "insert ignore into trade_strategy_track_record (area_stock_code,stock_name,`current_date`,open_price,high_price,low_price,close_price,close_rate) \
            value (%s,%s,%s,%s,%s,%s,%s,%s) "
     self.mysqlService.insert(sql,record)
Пример #6
0
    def save_strategy_choose(self, data, stock_code, strategy_id):
        strategy_id = str(strategy_id) + ","
        stock_info = []
        stock_info.append(
            self.redis.hget(redis_key_constants.stock_name_code_mapping,
                            stock_code))
        stock_info.append(stock_code)
        stock_info.append(data.split(",")[crawl_html_url.close_price_index])
        stock_info.append(0)
        stock_info.append("," + strategy_id)
        stock_info.append(date_time_util.get_date(0))

        sql = "insert into trade_strategy_record (stock_name,stock_code,current_price,current_rate,strategy_category ,`create_date`) \
                 value (%s,%s,%s,%s,%s,%s)  ON DUPLICATE KEY UPDATE  strategy_category = CONCAT(strategy_category,'" + strategy_id + "');"

        self.mysqlService.insert(sql, stock_info)
        """保存数据到策略跟踪表"""
        self.stock_strategy_record_dao.save_stock_strategy_record(
            stock_code, data)
Пример #7
0
def logger_init():
    # 第一步,创建一个logger
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)  # Log等级总开关
    # 第二步,创建一个handler,用于写入日志文件
    logfile = date_time_util.get_date(0) + '-log.txt'
    # fh = logging.FileHandler(logfile, mode='a') # open的打开模式这里可以进行参考
    fh = TimedRotatingFileHandler(filename=logfile, when="D", interval=1)
    fh.setLevel(logging.DEBUG)  # 输出到file的log等级的开关

    # 第三步,再创建一个handler,用于输出到控制台
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)  # 输出到console的log等级的开关
    # 第四步,定义handler的输出格式
    formatter = logging.Formatter(
        "%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s"
    )
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)
    # 第五步,将logger添加到handler里面
    logger.addHandler(fh)
    logger.addHandler(ch)