def api_stocks_page(*, page='1', **kw): page_index = get_page_index(page) if 'stock_code' in kw: stock_code = kw['stock_code'] if(stock_code != '' and stock_code != '0'): where_clause = 'stock_code = \'' + stock_code + '\'' else: where_clause = '1=1' else: where_clause = '1=1' num = yield from Stock.findNumber('count(id)', where=where_clause) p = Page(num, page_index) if num == 0: return dict(page=p, stocks=()) stocks = yield from Stock.findAll(where=where_clause, orderBy='occur_date desc, id desc', limit=(p.offset, p.limit)) for s in stocks: s.occur_date = str(s.occur_date)[0:10] s.stamp_tax = "%.2f" % (s.stamp_tax + s.transfer_fee + s.other_fee + s.commission + s.charge_fee) if s.type == 'T': s.type = '取出' elif s.type == 'SA': s.type = '存入' elif s.type == 'AB': s.type = '申购付款' elif s.type == 'AS': s.type = '申购退款' elif s.type == 'B': s.type = '买入' elif s.type == 'D': s.type = '红利' elif s.type == 'FP': s.type = '货币基金收益' elif s.type == 'I': s.type = '利息' elif s.type == 'S': s.type = '卖出' elif s.type == 'TD': s.type = '红利税' return dict(page=p, stocks=stocks)
def api_get_stocks(request): stocks = yield from Stock.findAll(orderBy='id desc') for s in stocks: s.occur_date = str(s.occur_date) return dict(stocks=stocks)