增加搜索

This commit is contained in:
dekun
2026-05-19 01:10:36 +08:00
parent 4ad0ebe581
commit a5383d8ca1
3 changed files with 213 additions and 116 deletions
+27 -3
View File
@@ -12,6 +12,7 @@ app = Flask(__name__)
BASE_DIR = Path(__file__).resolve().parent
DATA_FILE = BASE_DIR / "data.json"
VALID_EXCHANGES = frozenset({"binance", "okx", "gate"})
def load_accounts():
@@ -33,16 +34,34 @@ def save_accounts(accounts):
def validate_account_payload(payload):
exchange = (payload.get("exchange") or "").strip().lower()
username = (payload.get("username") or "").strip()
api_key = (payload.get("api_key") or "").strip()
api_secret = (payload.get("api_secret") or "").strip()
if exchange not in VALID_EXCHANGES:
return None, "请选择交易所:binance / okx / gate"
if not username:
return None, "账户名称不能为空"
if not api_key:
return None, "API Key 不能为空"
if not api_secret:
return None, "API Secret 不能为空"
return {"username": username, "api_key": api_key, "api_secret": api_secret}, None
account = {
"exchange": exchange,
"username": username,
"api_key": api_key,
"api_secret": api_secret,
}
if exchange == "okx":
password = (payload.get("password") or "").strip()
if not password:
return None, "OKX 密码(Passphrase)不能为空"
account["password"] = password
return account, None
@app.route("/")
@@ -52,7 +71,13 @@ def index():
@app.route("/api/accounts", methods=["GET"])
def list_accounts():
return jsonify(load_accounts())
accounts = load_accounts()
exchange = (request.args.get("exchange") or "").strip().lower()
if exchange:
if exchange not in VALID_EXCHANGES:
return jsonify({"error": "无效交易所"}), 400
accounts = [a for a in accounts if a.get("exchange") == exchange]
return jsonify(accounts)
@app.route("/api/accounts", methods=["POST"])
@@ -80,5 +105,4 @@ def delete_account(account_id):
if __name__ == "__main__":
# 0.0.0.0:本机 + 局域网均可访问(如 http://192.168.1.100:5200
app.run(host="0.0.0.0", port=5200, debug=False)