Exemple #1
0
def snapshot():
    stocks = polling()
    print(stocks)
    stock_list = []
    for stock in stocks:
        stock_list.append({'code': stock['code'], 'name': stock['name'],
                           'amount': stock['amount'],
                           'current': stock['current'], 'percentage': stock['percentage'],
                           'change': stock['change'] or 0})

    from portfolio.models import Portfolio
    from datetime import date
    date = get_date(str(date.today()))
    print('date***{}'.format(date))
    p = Portfolio(list=stock_list)
    p.compute()
    Portfolio.objects(date=date).update_one(list=p.list, market_value=p.market_value, total=p.total,
                                            net_asset=p.net_asset, cost=p.cost, cost_history=p.cost_history,
                                            cost_zs=p.cost_zs, cost_ht1=p.cost_ht1, cost_ht2=p.cost_ht2,
                                            cost_ht1_real=p.cost_ht1_real, cost_ht2_real=p.cost_ht2_real,
                                            position_ratio=p.position_ratio, financing=p.financing,
                                            lever=p.lever, cash=p.cash, profit=p.profit,
                                            profit_ratio=p.profit_ratio, profit_today=p.profit_today,
                                            profit_ratio_today=p.profit_ratio_today,
                                            upsert=True)
    result = Portfolio.objects.get(date=date)
    if result:
        print('result list***{}'.format(result.list))
        return result
    else:
        return None
Exemple #2
0
def snapshot():
    stocks = polling()
    print(stocks)
    stock_list = []
    for stock in stocks:
        stock_list.append({
            'code': stock['code'],
            'name': stock['name'],
            'amount': stock['amount'],
            'current': stock['current'],
            'percentage': stock['percentage'],
            'change': stock['change'] or 0
        })

    from portfolio.models import Portfolio
    from datetime import date
    date = get_date(str(date.today()))
    print('date***{}'.format(date))
    p = Portfolio(list=stock_list)
    p.compute()
    Portfolio.objects(date=date).update_one(
        list=p.list,
        market_value=p.market_value,
        total=p.total,
        net_asset=p.net_asset,
        cost=p.cost,
        cost_history=p.cost_history,
        cost_zs=p.cost_zs,
        cost_ht1=p.cost_ht1,
        cost_ht2=p.cost_ht2,
        cost_ht1_real=p.cost_ht1_real,
        cost_ht2_real=p.cost_ht2_real,
        position_ratio=p.position_ratio,
        financing=p.financing,
        lever=p.lever,
        cash=p.cash,
        profit=p.profit,
        profit_ratio=p.profit_ratio,
        profit_today=p.profit_today,
        profit_ratio_today=p.profit_ratio_today,
        upsert=True)
    result = Portfolio.objects.get(date=date)
    if result:
        print('result list***{}'.format(result.list))
        return result
    else:
        return None