def announcement(): locals()['type_to_cn'] = type_to_cn nav = 'announcement' tab = 'raw' type_ = request.args.get('type', '') typecn = type_to_cn(type_) exchange = request.args.get('exchange', '') page = int(request.args.get('page', 1) or 1) limit = 50 skip = limit * (page - 1) cond = {} if type_: cond['type_'] = type_ if exchange: cond['exchange'] = exchange total = Announcement.count(cond) pagination = Pagination(page, limit, total) exchanges = list(sorted(list(e.abbr for e in Exchange.query()))) types = ['offer', 'result', 'stock'] announcements = list( Announcement.query(cond, sort=[('updated_at', -1)], skip=skip, limit=limit)) for a in announcements: a.typecn = type_to_cn(a.type_) ex = Exchange.query_one(sort=[('updated_at', -1)]) updated_at = None if not ex else ex.updated_at return render_template('frontend/announcement.html', **locals())
def trade_account(): nav = 'accounts' tab = 'trade_account' investor = request.args.get('investor', '') exchange = request.args.get('exchange', '') add_investor = request.args.get('add_investor', '') add_exchange = request.args.get('add_exchange', '') bank = request.args.get('bank', '') investor = Investor.query_one({'_id': investor}) exchange = Exchange.query_one({'abbr': exchange}) user = current_user._id trade_accounts = TradeAccount.user_accounts(user) if investor: trade_accounts = [ta for ta in trade_accounts if ta.investor == investor._id] if exchange: trade_accounts = [ta for ta in trade_accounts if ta.exchange == exchange.abbr] if bank: trade_accounts = [ta for ta in trade_accounts if ta.bank == bank] investors = Investor.user_investors(user) exchanges = sorted(list(Exchange.query()), key=lambda x: x.abbr) exchange_list = [{'text': e.abbr, 'value': e.abbr} for e in exchanges] investor_list = [{'text': i.name, 'value': i.name} for i in investors] investor_banks = {i.name: sorted([ba.bank for ba in i.bank_accounts]) for i in investors} exchange_banks = {conf['abbr']: sorted(conf['opening']['bank']) for conf in CONFS} bank_exchanges = {} for ex, banks in exchange_banks.items(): for b in banks: if b not in bank_exchanges: bank_exchanges[b] = [] bank_exchanges[b].append(ex) investor_exchanges = { invesotr: sorted(set(sum( [bank_exchanges[b] for b in banks], []))) for invesotr, banks in investor_banks.items() } avail_investors = set(ta.investor for ta in trade_accounts) avail_exchanges = set(ta.exchange for ta in trade_accounts) avail_banks = set(ta.bank for ta in trade_accounts) investors = [i for i in investors if i._id in avail_investors] exchanges = [e for e in exchanges if e.abbr in avail_exchanges] thebanks = sorted(list(avail_banks)) account_positions = {ta._id: sorted([p.to_dict() for p in ta.position], key=lambda p: p['symbol']) for ta in trade_accounts} account_moneys = {ta._id: ta.money.to_dict() if ta.money else {} for ta in trade_accounts} account_order_status = {ta._id: sorted([o.to_dict() for o in ta.order_status], key=lambda o: o['order']) for ta in trade_accounts} account_orders = {ta._id: sorted([o.to_dict() for o in ta.orders], key=lambda o: o['symbol']) for ta in trade_accounts} return render_template('user/trade_account.html', **locals())
def trade_account(): nav = 'accounts' tab = 'trade_account' investor = request.args.get('investor', '') exchange = request.args.get('exchange', '') add_investor = request.args.get('add_investor', '') add_exchange = request.args.get('add_exchange', '') bank = request.args.get('bank', '') investor = Investor.query_one({'_id': investor}) exchange = Exchange.query_one({'abbr': exchange}) user = current_user._id trade_accounts = TradeAccount.user_accounts(user) if investor: trade_accounts = [ ta for ta in trade_accounts if ta.investor == investor._id ] if exchange: trade_accounts = [ ta for ta in trade_accounts if ta.exchange == exchange.abbr ] if bank: trade_accounts = [ta for ta in trade_accounts if ta.bank == bank] investors = Investor.user_investors(user) exchanges = sorted(list(Exchange.query()), key=lambda x: x.abbr) exchange_list = [{'text': e.abbr, 'value': e.abbr} for e in exchanges] investor_list = [{'text': i.name, 'value': i.name} for i in investors] investor_banks = { i.name: sorted([ba.bank for ba in i.bank_accounts]) for i in investors } exchange_banks = { conf['abbr']: sorted(conf['opening']['bank']) for conf in CONFS } bank_exchanges = {} for ex, banks in exchange_banks.items(): for b in banks: if b not in bank_exchanges: bank_exchanges[b] = [] bank_exchanges[b].append(ex) investor_exchanges = { invesotr: sorted(set(sum([bank_exchanges[b] for b in banks], []))) for invesotr, banks in investor_banks.items() } avail_investors = set(ta.investor for ta in trade_accounts) avail_exchanges = set(ta.exchange for ta in trade_accounts) avail_banks = set(ta.bank for ta in trade_accounts) investors = [i for i in investors if i._id in avail_investors] exchanges = [e for e in exchanges if e.abbr in avail_exchanges] thebanks = sorted(list(avail_banks)) account_positions = { ta._id: sorted([p.to_dict() for p in ta.position], key=lambda p: p['symbol']) for ta in trade_accounts } account_moneys = { ta._id: ta.money.to_dict() if ta.money else {} for ta in trade_accounts } account_order_status = { ta._id: sorted([o.to_dict() for o in ta.order_status], key=lambda o: o['order']) for ta in trade_accounts } account_orders = { ta._id: sorted([o.to_dict() for o in ta.orders], key=lambda o: o['symbol']) for ta in trade_accounts } return render_template('user/trade_account.html', **locals())