def api(): uid = _apikeyvalidate(g.db,request.args.get('key', 0)) if uid == 0: abort(404) type = request.args.get('t', 0) if type == 'A': #add order contract_id = request.args.get('cid', 0,type=int) b_s = request.args.get('bs', 0) point = request.args.get('pt', 0) lots = request.args.get('lt', 0,type=int) res = _add_order(g.db,uid,contract_id,b_s,point,lots,'S') return jsonify(res) elif type == 'C': #cancel order orderid = request.args.get('oid', 0) res = _cancel_order(g.db,uid,orderid) return jsonify(res) elif type == 'O': #get orderlist res = _update_user(g.db,{'user_id':uid},['orders']) return jsonify(res) elif type == 'U': #Update server contract_id = request.args.get('cid', 0,type=int) _update_contract(g.db,contract_id,'D') return jsonify({'category':'suc'}) else: abort(404)
def trade(): if 'user_id' not in session: return redirect(url_for('home')) if request.method == 'POST': #---Add order--- res = _add_order(g.db,session['user_id'],long(request.form['contract_id']),request.form['b_s'], request.form['point'], request.form['lots']) session['bs'] = request.form['b_s'] flash(res['msg'],res['category']) if res['category'] == 'suc': if 'Deal' in res['msg']: _update_contract(g.db,request.form['contract_id'],'D') else: _update_contract(g.db,request.form['contract_id'],'C') return redirect(url_for('trade',c=request.form['contract_id'])) else: co = request.args.get('co', 0,type=int) contract_id = request.args.get('c', 0, type=int) if co >= 1: #Cancel order res = _cancel_order(g.db,session['user_id'],co) flash(res['msg'],res['category']) _update_contract(g.db,contract_id,'C') return redirect(url_for('trade',c=contract_id)) else: g.u = _update_user(g.db,session,[]) if contract_id == 0 and 'latestcont' in session: contract_id = session['latestcont'] return render_template('trade.html',default_cid = contract_id )