def history_by_code(code): start, end = params('start', 'end') data = stock_cli.daily(ts_code=parse_code(code), start_date=parse_time(start), end_date=parse_time(end)) data = sorted(data.to_dict('record'), key=lambda d: d['trade_date']) return render_ok(data)
def stock(): data = stock_cli.query( 'stock_basic', exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date') return render_ok(data.to_dict('record'))
def stock_by_code(code): data = stock_cli.query( 'stock_basic', exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date') stock = list( filter(lambda stock: stock['symbol'] == code, data.to_dict('record')))[0] return render_ok(stock)
def login(): username = request.json['username'] password = request.json['password'] error = None user = User.get_or_none(User.username == username) if user is None: error = 'Incorrect username.' elif not check_password_hash(user.password, password): error = 'Incorrect password.' if error is None: session.clear() session['user_id'] = user.id return render_ok() return render_err(error)
def register(): username = request.json['username'] password = request.json['password'] error = None if not username: error = 'Username is required.' elif not password: error = 'Password is required.' elif User.get_or_none(User.username == username) is not None: error = 'User {} is already registered.'.format(username) if error is None: User.create(username=username, password=generate_password_hash(password)).save() return render_ok() return render_err(error)
def logout(): session.clear() return render_ok()
def load_stock(): from app.tasks.stock_tasks import load_stock load_stock.apply_async() return render_ok()
def load_stock_history(): from app.tasks.stock_tasks import load_stock_history load_stock_history.apply_async() return render_ok()