Beispiel #1
0
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)
Beispiel #2
0
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'))
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
def logout():
    session.clear()
    return render_ok()
Beispiel #7
0
def load_stock():
    from app.tasks.stock_tasks import load_stock
    load_stock.apply_async()
    return render_ok()
Beispiel #8
0
def load_stock_history():
    from app.tasks.stock_tasks import load_stock_history
    load_stock_history.apply_async()
    return render_ok()