Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,28 +1,14 @@
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
-
import
|
| 5 |
-
import sys
|
| 6 |
-
|
| 7 |
-
# FORCE L'INSTALLATION DE LA VERSION MODERNE
|
| 8 |
-
try:
|
| 9 |
-
import hyperliquid
|
| 10 |
-
# On vérifie si on a la bonne version, sinon on force l'update
|
| 11 |
-
from hyperliquid.exchange import Exchange
|
| 12 |
-
print("Hyperliquid moderne détecté.")
|
| 13 |
-
except (ImportError, ModuleNotFoundError):
|
| 14 |
-
print("Version obsolète ou absente. Installation de hyperliquid==1.2.2...")
|
| 15 |
-
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "hyperliquid==1.2.2", "eth-account"])
|
| 16 |
-
from hyperliquid.exchange import Exchange
|
| 17 |
-
from eth_account import Account
|
| 18 |
-
print("Installation de la version 1.2.2 réussie !")
|
| 19 |
-
|
| 20 |
from eth_account import Account
|
|
|
|
| 21 |
app = FastAPI()
|
| 22 |
|
| 23 |
@app.get("/")
|
| 24 |
def home():
|
| 25 |
-
return {"status": "online", "
|
| 26 |
|
| 27 |
@app.post("/webhook")
|
| 28 |
async def handle_webhook(request: Request):
|
|
@@ -31,10 +17,10 @@ async def handle_webhook(request: Request):
|
|
| 31 |
data = json.loads(body)
|
| 32 |
|
| 33 |
pk = os.getenv("HL_PRIVATE_KEY")
|
|
|
|
|
|
|
|
|
|
| 34 |
account = Account.from_key(pk)
|
| 35 |
-
|
| 36 |
-
# On importe ici car l'installation vient d'avoir lieu
|
| 37 |
-
from hyperliquid.exchange import Exchange
|
| 38 |
exchange = Exchange(account, "https://api.hyperliquid.xyz")
|
| 39 |
|
| 40 |
action = data.get("action")
|
|
@@ -45,6 +31,8 @@ async def handle_webhook(request: Request):
|
|
| 45 |
return exchange.market_open(symbol, True, size, None, {"fixed": True})
|
| 46 |
elif action == "sell":
|
| 47 |
return exchange.market_open(symbol, False, size, None, {"fixed": True})
|
|
|
|
|
|
|
| 48 |
|
| 49 |
return {"status": "received", "data": data}
|
| 50 |
except Exception as e:
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
+
from hyperliquid.exchange import Exchange
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from eth_account import Account
|
| 6 |
+
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
@app.get("/")
|
| 10 |
def home():
|
| 11 |
+
return {"status": "online", "message": "Sentinel V1 est prêt (Source GitHub)"}
|
| 12 |
|
| 13 |
@app.post("/webhook")
|
| 14 |
async def handle_webhook(request: Request):
|
|
|
|
| 17 |
data = json.loads(body)
|
| 18 |
|
| 19 |
pk = os.getenv("HL_PRIVATE_KEY")
|
| 20 |
+
if not pk:
|
| 21 |
+
return {"error": "Secret HL_PRIVATE_KEY manquant"}
|
| 22 |
+
|
| 23 |
account = Account.from_key(pk)
|
|
|
|
|
|
|
|
|
|
| 24 |
exchange = Exchange(account, "https://api.hyperliquid.xyz")
|
| 25 |
|
| 26 |
action = data.get("action")
|
|
|
|
| 31 |
return exchange.market_open(symbol, True, size, None, {"fixed": True})
|
| 32 |
elif action == "sell":
|
| 33 |
return exchange.market_open(symbol, False, size, None, {"fixed": True})
|
| 34 |
+
elif action == "close":
|
| 35 |
+
return exchange.market_close(symbol)
|
| 36 |
|
| 37 |
return {"status": "received", "data": data}
|
| 38 |
except Exception as e:
|