Beispiel #1
0
def trade_account_apply_status():
    account_id = request.form.get('account_id')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            result = apply_status(ta)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            return jsonify(status=200, apply_status=result)
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #2
0
def trade_account_apply_status():
    account_id = request.form.get('account_id')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            result = apply_status(ta)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            return jsonify(status=200, apply_status=result)
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #3
0
def trade_account_list_offers():
    account_id = request.form.get('account_id')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            offers = list_offers(ta)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            return jsonify(status=200, offers=offers)
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #4
0
def trade_account_list_offers():
    account_id = request.form.get('account_id')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            offers = list_offers(ta)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            return jsonify(status=200, offers=offers)
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #5
0
def trade_account_withdraw_apply():
    account_id = request.form.get('account_id')
    applyid = request.form.get('applyid')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            withdraw_apply(ta, applyid)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            return jsonify(status=200, reason='撤单已提交')
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #6
0
def trade_account_withdraw_apply():
    account_id = request.form.get('account_id')
    applyid = request.form.get('applyid')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            withdraw_apply(ta, applyid)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            return jsonify(status=200, reason='撤单已提交')
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #7
0
def trade_account_apply_offer():
    account_id = request.form.get('account_id')
    symbol = request.form.get('symbol')
    quantity = int(request.form.get('quantity'))
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            r, err = apply_offer(ta, symbol, quantity)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            return jsonify(status=200, reason=str(err))
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #8
0
def trade_account_apply_offer():
    account_id = request.form.get('account_id')
    symbol = request.form.get('symbol')
    quantity = int(request.form.get('quantity'))
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            r, err = apply_offer(ta, symbol, quantity)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            return jsonify(status=200, reason=str(err))
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #9
0
def trade_account_withdraw():
    account_id = request.form.get('account_id')
    order = request.form.get('order')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            r, err = withdraw(ta, order)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            if r:
                return jsonify(status=200, reason='撤单成功')
            else:
                return jsonify(status=400, reason=err)
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #10
0
def trade_account_withdraw():
    account_id = request.form.get('account_id')
    order = request.form.get('order')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            r, err = withdraw(ta, order)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            if r:
                return jsonify(status=200, reason='撤单成功')
            else:
                return jsonify(status=400, reason=err)
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #11
0
def trade_account_transfer():
    account_id = request.form.get('account_id')
    inout = request.form.get('inout')
    amount = float(request.form.get('amount') or 0)
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            r, err = transfer(ta, inout, amount)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            if r:
                return jsonify(status=200, reason='出入金已提交')
            else:
                return jsonify(status=400, reason=err)
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #12
0
def trade_account_transfer():
    account_id = request.form.get('account_id')
    inout = request.form.get('inout')
    amount = float(request.form.get('amount') or 0)
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            r, err = transfer(ta, inout, amount)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            if r:
                return jsonify(status=200, reason='出入金已提交')
            else:
                return jsonify(status=400, reason=err)
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #13
0
def trade_account_update_quote():
    account_id = request.form.get('account_id')
    symbol = request.form.get('symbol')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            qd = quote_detail(ta, symbol)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            return jsonify(status=200,
                           price=qd['price'],
                           highest=qd['highest'],
                           lowest=qd['lowest'],
                           asks=qd['asks'],
                           bids=qd['bids'])
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #14
0
def trade_account_update_quote():
    account_id = request.form.get('account_id')
    symbol = request.form.get('symbol')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            qd = quote_detail(ta, symbol)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            return jsonify(status=200,
                           price=qd['price'],
                           highest=qd['highest'],
                           lowest=qd['lowest'],
                           asks=qd['asks'],
                           bids=qd['bids'])
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #15
0
def trade_account_order():
    account_id = request.form.get('account_id')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        type_ = request.form.get('type_')
        symbol = request.form.get('symbol')
        price = float(request.form.get('price'))
        quantity = int(request.form.get('quantity'))
        try:
            r, err = order(ta, type_, symbol, price, quantity)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            if r:
                return jsonify(status=200, reason='下单成功')
            else:
                return jsonify(status=400, reason=err)
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #16
0
def trade_account_order():
    account_id = request.form.get('account_id')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        type_ = request.form.get('type_')
        symbol = request.form.get('symbol')
        price = float(request.form.get('price'))
        quantity = int(request.form.get('quantity'))
        try:
            r, err = order(ta, type_, symbol, price, quantity)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))
        else:
            if r:
                return jsonify(status=200, reason='下单成功')
            else:
                return jsonify(status=400, reason=err)
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #17
0
def trade_account_change_password():
    exchanges = request.form.getlist('exchanges[]')
    login_names = request.form.getlist('login_names[]')
    new_login_password = request.form.get('new_login_password')
    # TODO: add new_money_password support
    errors = []
    for ex, name in zip(exchanges, login_names):
        ta = TradeAccount.query_one({'exchange': ex, 'login_name': name})
        pwd = ta.login_password
        t = Trader(ex, name, pwd)
        t.change_password(new_login_password)
        if t.last_error:
            errors.append([ex, name, t.last_error])
        else:
            ta.login_password = new_login_password
            ta.upsert()
    if errors:
        log.exception(str(errors))
        return jsonify(status=500, reason='部分账号修改失败', details=errors)
    else:
        return jsonify(status=200, reason='')
Beispiel #18
0
def trade_account_refresh_status():
    account_id = request.form.get('account_id')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            update_trade_account(ta)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500, reason=str(e))

        return jsonify(
            status=200,
            position=sorted([p.to_dict() for p in ta.position],
                            key=lambda p: p['symbol']),
            money=ta.money.to_dict(),
            orders=sorted([o.to_dict() for o in ta.orders],
                          key=lambda o: o['symbol']),
            order_status=sorted([o.to_dict() for o in ta.order_status],
                                key=lambda o: o['symbol']),
        )
    else:
        return jsonify(status=500, reason='账号未找到')
Beispiel #19
0
def trade_account_change_password():
    exchanges = request.form.getlist('exchanges[]')
    login_names = request.form.getlist('login_names[]')
    new_login_password = request.form.get('new_login_password')
    # TODO: add new_money_password support
    errors = []
    for ex, name in zip(exchanges, login_names):
        ta = TradeAccount.query_one({'exchange': ex,
                                     'login_name': name})
        pwd = ta.login_password
        t = Trader(ex, name, pwd)
        t.change_password(new_login_password)
        if t.last_error:
            errors.append([ex, name, t.last_error])
        else:
            ta.login_password = new_login_password
            ta.upsert()
    if errors:
        log.exception(str(errors))
        return jsonify(status=500,
                       reason='部分账号修改失败',
                       details=errors)
    else:
        return jsonify(status=200, reason='')
Beispiel #20
0
def trade_account_refresh_status():
    account_id = request.form.get('account_id')
    ta = TradeAccount.query_one({'_id': account_id})
    if ta:
        try:
            update_trade_account(ta)
        except Exception as e:
            log.exception(str(e))
            return jsonify(status=500,
                           reason=str(e))

        return jsonify(status=200,
                       position=sorted([p.to_dict() for p in ta.position],
                                       key=lambda p: p['symbol']),
                       money=ta.money.to_dict(),
                       orders=sorted([o.to_dict() for o in ta.orders],
                                     key=lambda o: o['symbol']),
                       order_status=sorted([o.to_dict()
                                            for o in ta.order_status],
                                           key=lambda o: o['symbol']),
                       )
    else:
        return jsonify(status=500,
                       reason='账号未找到')