def get_by_name(username): user = {'username': username} doc = db.query_one('user', user) if not doc: return Response({}) return Response(_id=str(doc['_id']), username=doc['username'], password=doc['password'], realValueAll=doc['real_value_all'], profit=doc['profit'], profitPct=doc['profit_pct'])
def get(assert_info): doc = db.query_one('assert', assert_info) if not doc: return Response({}) return Response(_id=doc['_id'], dateTime=doc['date_time'], balanceEth=doc['balance_eth'], balanceBusd=doc['balance_busd'], curPriceETH=doc['cur_price_ETH'], realValueAll=doc['real_value_all'], profit=doc['profit'], profitPct=doc['profit_pct'])
def delete(): json = get_json() _id = json.get('_id', '') if _id == '': abort(400, **get_result(code=400, msg='参数错误')) account = {'_id': _id} return Response(account=account)
def get(): exchange = get_arg('exchange', '') query = {} if exchange != '': query = {'exchange': exchange} page_num = int(get_arg('pageNum', 1)) page_size = int(get_arg('pageSize', 10)) return Response(account=query, page_num=page_num, page_size=page_size)
def reg(user): username = user.get('username', '') password = user.get('password', '') u = UserModel.get_by_name(username) if u: abort(500, **get_result(code=500, msg='该用户已存在')) UserModel.insert(username, password) return Response(data={})
def login(user): username = user.get('username', '') password = user.get('password', '') u = UserModel.get_by_name(username) if not u: abort(500, **get_result(code=500, msg='账号或密码错误')) if password != u['password']: abort(500, **get_result(code=500, msg='账号或密码错误')) return Response(data=u)
def post(): json = get_json() account = { 'exchange': json.get('exchange', ''), 'desc': json.get('desc', ''), 'key': json.get('key', ''), 'secret': json.get('secret', ''), 'user_id': json.get('userId', '') } return Response(account=account)
def put(): json = get_json() _id = json.get('_id', '') if _id == '': abort(400, **get_result(code=400, msg='参数错误')) account = { '_id': _id, 'exchange': json.get('exchange', ''), 'desc': json.get('desc', ''), 'key': json.get('key', ''), 'secret': json.get('secret', ''), 'user_id': json.get('userId', '') } return Response(account=account)
def line(num, page_num, page_size): if page_num <= 0: page_num = 1 offset = (page_num - 1) * page_size data_list = db.query_search_page_sort('assert', {}, page_size, offset, 'date_time') data_arr = [] for i in range(0, len(data_list)): if i % num == 0: data_arr.append({ '_id': str(data_list[i]['_id']), 'dateTime': data_list[i]['date_time'], 'realValueAll': data_list[i]['real_value_all'], 'profit': data_list[i]['profit'], 'profitPct': data_list[i]['profit_pct'] }) return Response(data=data_arr)
def list(assert_info, page_num, page_size): total_count = db.query_count('assert', assert_info) if page_num <= 0: page_num = 1 offset = (page_num - 1) * page_size data_list = db.query_search_page('assert', assert_info, page_size, offset) data_arr = [] for i in range(0, len(data_list)): data_arr.append({ '_id': str(data_list[i]['_id']), 'dateTime': data_list[i]['date_time'], 'realValueAll': data_list[i]['real_value_all'], 'profit': data_list[i]['profit'], 'profitPct': data_list[i]['profit_pct'] }) return Response(total=total_count, data=data_arr, pageNum=page_num, pageSize=page_size)
def list(account, page_num, page_size): total_count = db.query_count('account', account) if page_num <= 0: page_num = 1 offset = (page_num - 1) * page_size data_list = db.query_search_page('account', account, page_size, offset) data_arr = [] for i in range(0, len(data_list)): data_arr.append({ '_id': str(data_list[i]['_id']), 'exchange': data_list[i]['exchange'], 'desc': data_list[i]['desc'], 'key': data_list[i]['key'], 'secret': data_list[i]['secret'], 'userId': data_list[i]['user_id'], }) return Response(total=total_count, data=data_arr, pageNum=page_num, pageSize=page_size)
def insert(assert_info): _id = db.insert_one('assert', assert_info) return Response(_id=_id)
def bind_assert(user): _id = user.get('_id', '') assert_id = user.get('assert_id', '') UserModel.bind_assert(_id, assert_id) return Response(data={})
def delete(assert_info): doc = db.remove('assert', assert_info) if not doc: return Response({}) return Response(_id=doc['_id'])
def update(assert_info): doc = db.update('assert', assert_info) if not doc: return Response({}) return Response(_id=doc['_id'])
def get(): json = get_json() assert_info = { '_id': json.get('_id', ''), } return Response(assert_info=assert_info)
def post(): json = get_json() page_num = int(json.get('pageNum', 1)) num = int(json.get('num', 2)) page_size = int(json.get('pageSize', 10)) return Response(num=num, page_num=page_num, page_size=page_size)
def update(assert_info): if not assert_info: abort(400, **get_result(code=400, msg='参数错误')) AssertInfoModel.update(assert_info) return Response(data={})
def line(num, page_num, page_size): data = AssertInfoModel.line(num, page_num, page_size) return Response(data=data)
def update(account): if not account: abort(400, **get_result(code=400, msg='参数错误')) AccountModel.update(account) return Response(data={})
def delete(account): db.delete_one('account', account) return Response({})
def insert(account): _id = db.insert_one('account', account) return Response(_id=_id)
def update(account): doc = db.update('account', account) if not doc: return Response({}) return Response(_id=doc['_id'])
def get(assert_info): if not assert_info: abort(400, **get_result(code=400, msg='参数错误')) doc = AssertInfoModel.get(assert_info) return Response(data=doc)
def list(assert_info, page_num, page_size): page = AssertInfoModel.list(assert_info, page_num, page_size) return Response(data=page)
def list(account, page_num, page_size): page = AccountModel.list(account, page_num, page_size) return Response(data=page)