Spaces:
Running
Running
Fix Alpaca 500 internal error by adding 3x retry mechanism and preventing UI screen locks
Browse files
external/Quant.ai/assets/index-CrPbYtGZ.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
external/Quant.ai/backend/app/broker/alpaca_adapter.py
CHANGED
|
@@ -30,25 +30,31 @@ class AlpacaAdapter:
|
|
| 30 |
|
| 31 |
def get_account_summary(self) -> Dict:
|
| 32 |
"""
|
| 33 |
-
Fetch broker account details.
|
| 34 |
-
Returns:
|
| 35 |
-
Dict containing cash, equity, buying power, and account status.
|
| 36 |
"""
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
def get_open_positions(self) -> List[Dict]:
|
| 54 |
"""
|
|
|
|
| 30 |
|
| 31 |
def get_account_summary(self) -> Dict:
|
| 32 |
"""
|
| 33 |
+
Fetch broker account details with retry for Alpaca server 500 glitches.
|
|
|
|
|
|
|
| 34 |
"""
|
| 35 |
+
import time
|
| 36 |
+
last_err = None
|
| 37 |
+
for attempt in range(3):
|
| 38 |
+
try:
|
| 39 |
+
account = self.client.get_account()
|
| 40 |
+
return {
|
| 41 |
+
"success": True,
|
| 42 |
+
"account_number": account.account_number,
|
| 43 |
+
"status": account.status,
|
| 44 |
+
"currency": account.currency,
|
| 45 |
+
"cash": float(account.cash),
|
| 46 |
+
"portfolio_value": float(account.portfolio_value),
|
| 47 |
+
"buying_power": float(account.buying_power),
|
| 48 |
+
"multiplier": float(account.multiplier),
|
| 49 |
+
"shorting_enabled": account.shorting_enabled,
|
| 50 |
+
"equity": float(account.equity),
|
| 51 |
+
"initial_margin": float(account.initial_margin),
|
| 52 |
+
"maintenance_margin": float(account.maintenance_margin),
|
| 53 |
+
}
|
| 54 |
+
except Exception as e:
|
| 55 |
+
last_err = e
|
| 56 |
+
time.sleep(0.4)
|
| 57 |
+
raise last_err
|
| 58 |
|
| 59 |
def get_open_positions(self) -> List[Dict]:
|
| 60 |
"""
|
external/Quant.ai/frontend/src/components/BrokerPanel.tsx
CHANGED
|
@@ -69,7 +69,9 @@ export function BrokerPanel() {
|
|
| 69 |
setAccount(accJson);
|
| 70 |
setErrorMsg(null);
|
| 71 |
} else {
|
| 72 |
-
|
|
|
|
|
|
|
| 73 |
}
|
| 74 |
|
| 75 |
// 2. Fetch positions
|
|
|
|
| 69 |
setAccount(accJson);
|
| 70 |
setErrorMsg(null);
|
| 71 |
} else {
|
| 72 |
+
if (!account) {
|
| 73 |
+
setErrorMsg(accJson.error || "无法获取 Alpaca 账户信息,请检查 Keys 配置。");
|
| 74 |
+
}
|
| 75 |
}
|
| 76 |
|
| 77 |
// 2. Fetch positions
|
external/Quant.ai/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>frontend</title>
|
| 8 |
-
<script type="module" crossorigin src="/assets/index-
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-DCSOhC_L.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
|
|
|
| 5 |
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>frontend</title>
|
| 8 |
+
<script type="module" crossorigin src="/assets/index-CrPbYtGZ.js"></script>
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-DCSOhC_L.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
quant.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>frontend</title>
|
| 8 |
-
<script type="module" crossorigin src="/assets/index-
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-DCSOhC_L.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
|
|
|
| 5 |
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>frontend</title>
|
| 8 |
+
<script type="module" crossorigin src="/assets/index-CrPbYtGZ.js"></script>
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-DCSOhC_L.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
quant/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>Quant.ai Trading Terminal</title>
|
| 8 |
-
<script type="module" crossorigin src="/assets/index-
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-DCSOhC_L.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
|
|
|
| 5 |
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>Quant.ai Trading Terminal</title>
|
| 8 |
+
<script type="module" crossorigin src="/assets/index-CrPbYtGZ.js"></script>
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-DCSOhC_L.css">
|
| 10 |
</head>
|
| 11 |
<body>
|