示例#1
0
def get_result_fund_lst(fund_data, sort_key='assessment'):
    result_lst = []
    percent_for_buy = select_field('low', 'index_line', {'id': 4})
    percent_for_sell = select_field('high', 'index_line', {'id': 4})
    for data_dic in fund_data:
        time.sleep(3)
        fund_increase_dic = change_fund_increase_dic(data_dic['code_id'],
                                                     data_dic['name'])
        if data_dic['worth_to_buy'] and (
                fund_increase_dic['assessment_worth'] <
            (data_dic['worth_to_buy'] * percent_for_buy)):
            fund_increase_dic[
                'fund_name'] = '【买买买】' + fund_increase_dic['fund_name']
            excute_sql(
                """update fund_info set useful='9' where code_id='%s';""" %
                (str(data_dic['code_id'])))

        if data_dic['worth_to_sell'] and (
                fund_increase_dic['assessment_worth'] >
            (data_dic['worth_to_sell'] * percent_for_sell)):
            fund_increase_dic[
                'fund_name'] = '【卖卖卖】' + fund_increase_dic['fund_name']

        fund_increase_dic.pop('code_id')
        fund_increase_dic.pop('three_month')
        fund_increase_dic.pop('six_month')
        fund_increase_dic.pop('one_year')
        fund_increase_dic.pop('three_year')
        fund_increase_dic.pop('assessment_worth')
        result_lst.append(fund_increase_dic)
    sorted_result_lst = sorted(result_lst, key=operator.itemgetter(sort_key))
    return sorted_result_lst
示例#2
0
def specil_strategy(mode='low'):
    low_assessment = select_field('low', 'index_line', {'id': 3})
    high_assessment = select_field('high', 'index_line', {'id': 3})
    my_fund = select_my_fund(mode='fund')
    assessment_result = get_result_fund_lst(fund_data=my_fund,
                                            sort_key='assessment')
    if mode == 'low':
        if assessment_result[0]['assessment'] <= low_assessment: return True
        else: return False
    elif mode == 'high':
        if assessment_result[-1]['assessment'] >= high_assessment: return True
        else: return False
    else:
        return False
示例#3
0
def avg_content(days=select_field('content', 's_content', {'id': 5})):
    res = get_avg_index_last_days(days)
    content = '''
    最近 {somedays} 天的平均值:{avg}
    最小值:{min}   最大值:{max}
    
    '''.format(avg=res['AVG'], min=res['MIN'], max=res['MAX'], somedays=days)
    print(content)
    return content
示例#4
0
def compare_3000_history_value(index_value,
                               days=select_field('content', 's_content',
                                                 {'id': 2})):
    offset = float(select_field('content', 's_content', {'id': 4}))
    sql = "select yesterday_end from shanghai_index order by update_time desc limit %s;" % str(
        days)
    r = selects(sql)
    print("yesterday_end: " + str(r))
    flag = True
    if (index_value - offset) > float(r[0]['yesterday_end']):
        flag = False
    else:
        for dic in r:
            if index_value > float(dic['yesterday_end']):
                flag = False
    # 如果一天内猛跌70点
    if float(r[0]['yesterday_end']) - index_value >= 70:
        flag = True
    # 如果两天内猛跌120点
    if float(r[1]['yesterday_end']) - index_value >= 120:
        flag = True
    print("compare_3000_history_value Flag: " + str(flag))
    return flag
示例#5
0
def send_email_notice(index_value, content):
    low_index1 = select_field('low', 'index_line', {'id': 1})
    high_index1 = select_field('high', 'index_line', {'id': 1})
    low_index2 = select_field('low', 'index_line', {'id': 2})
    high_index2 = select_field('high', 'index_line', {'id': 2})
    index_value_float = float(index_value)

    if (index_value_float < low_index2 and specil_strategy(mode='low')) or (
            index_value_float < low_index1
            and compare_3000_history_value(index_value_float)):
        subject = '快来【买入】基金啦!今日上证指数低谷 = %s!' % str(index_value_float)
        send_mail(subject, content)
        print(index_value + " < %s send email success" % str(low_index1))
    elif (index_value_float > high_index2 and specil_strategy(mode='high')
          ) or (index_value_float > high_index1
                and compare_4000_history_value(index_value_float)):
        subject = '快来【卖出】基金啦!今日上证指数趋于高峰 > %s!' % str(index_value_float)
        send_mail(subject, content)
        print(index_value + " > %s send email success" % str(high_index1))
    elif '买' in content[2] or '卖' in content[2]:
        subject = '快来快来,某基金呼喊你'
        send_mail(subject, content)
        print('快来快来,某基金呼喊你')
示例#6
0
def compare_4000_history_value(index_value,
                               days=select_field('content', 's_content',
                                                 {'id': 2})):
    sql = "select yesterday_end from shanghai_index order by update_time desc limit %s;" % str(
        days)
    r = selects(sql)
    print("yesterday_end: " + str(r))
    flag = True
    for dic in r:
        if index_value < float(dic['yesterday_end']):
            flag = False
    # 如果一天内猛涨120点
    if index_value - float(r[0]['yesterday_end']) >= 120:
        flag = True
    # 如果两天内猛涨200点
    if index_value - float(r[0]['yesterday_end']) >= 200:
        flag = True
    print("compare_4000_history_value Flag: " + str(flag))
    return flag
示例#7
0
def strategy_content():
    content = '''
    ===============================
%s
    ''' % select_field('content', 's_content', {'id': 3})
    return content