Thanhanh9/Test / okx_main.py
download
raw
1.71 kB
import ccxt
from flask import Flask, request, jsonify
import ccxt
import json
app = Flask(__name__)
# Khởi tạo kết nối với OKX
exchange = ccxt.okx({
'apiKey': '4b64bb89-d6ca-483f-92c6-6b46f84cdf8b',
'secret': 'EA624782850EE9A1D985FB0888F68C90',
'password': 'Vertivvncy2026@',
'enableRateLimit': True,
})
# QUAN TRỌNG: Chuyển sang chế độ Demo (Paper Trading)
exchange.set_sandbox_mode(True)
# Kiểm tra số dư tài khoản Demo
balance = exchange.fetch_balance()
print(f"Số dư USDT Demo: {balance['total']['USDT']}")
@app.route('/webhook', methods=['POST'])
def webhook():
# Nhận dữ liệu JSON từ TradingView
data = request.json
print(f"Nhận tín hiệu: {data}")
# Kiểm tra Passphrase (để bảo mật, tránh người lạ gửi lệnh vào server của bạn)
if data.get('passphrase') != 'RSI_SYSTEM_123':
return "Sai Passphrase", 403
symbol = data.get('ticker') # Ví dụ: XAUt/USDT
side = data.get('action') # buy hoặc sell
amount = data.get('quantity') # Số lượng
try:
# Thực hiện lệnh thị trường (Market Order)
order = exchange.create_order(
symbol=symbol,
type='market',
side=side,
amount=amount
)
print(f"Đặt lệnh thành công: {order['id']}")
return jsonify({"status": "success", "order_id": order['id']})
except Exception as e:
print(f"Lỗi đặt lệnh: {e}")
return jsonify({"status": "error", "message": str(e)}), 500
if __name__ == '__main__':
# Chạy server ở port 80 (hoặc 2000)
app.run(host='0.0.0.0', port=2000)

Xet Storage Details

Size:
1.71 kB
·
Xet hash:
e38351f4578e3078f317f0c8dda6c9a997b75d888d0e4af2e0f0da80785d6325

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.