feat(trading-assistant): refactor strategy creation and enhance script mode functionality

- Removed conditional rendering for the assistant guide bar.
- Simplified strategy overview and strategy list item components.
- Introduced a new modal for selecting strategy mode.
- Enhanced strategy creation modal to support script strategies with a dedicated editor.
- Updated form handling for script strategies, including validation and submission logic.
- Improved user experience with better messaging and streamlined UI components.
- Updated translations for better clarity in Chinese.
This commit is contained in:
dienakdz
2026-04-08 07:27:26 +07:00
parent 2dc29a215e
commit c3cf230104
89 changed files with 4653 additions and 1735 deletions
@@ -86,7 +86,7 @@ class DataCache:
if entry.is_expired():
del self._cache[key]
self._misses += 1
logger.debug(f"[缓存] {self.name}:{key} 已过期,删除")
logger.debug(f"[cache] {self.name}:{key} expired and was removed")
return None
# Update access order (LRU)
@@ -94,7 +94,7 @@ class DataCache:
entry.hit_count += 1
self._hits += 1
logger.debug(f"[缓存命中] {self.name}:{key} (年龄: {entry.age():.0f}s/{entry.ttl:.0f}s)")
logger.debug(f"[cache hit] {self.name}:{key} (age: {entry.age():.0f}s/{entry.ttl:.0f}s)")
return entry.data
def set(
@@ -115,7 +115,7 @@ class DataCache:
# Check capacity, perform LRU elimination
while len(self._cache) >= self.max_size:
oldest_key, _ = self._cache.popitem(last=False)
logger.debug(f"[缓存] {self.name} 容量已满,淘汰: {oldest_key}")
logger.debug(f"[cache] {self.name} reached capacity, evicted: {oldest_key}")
actual_ttl = ttl if ttl is not None else self.default_ttl
self._cache[key] = CacheEntry(
@@ -124,14 +124,14 @@ class DataCache:
ttl=actual_ttl
)
logger.debug(f"[缓存更新] {self.name}:{key} TTL={actual_ttl}s")
logger.debug(f"[cache update] {self.name}:{key} TTL={actual_ttl}s")
def delete(self, key: str) -> bool:
"""Delete cache entry"""
with self._lock:
if key in self._cache:
del self._cache[key]
logger.debug(f"[缓存] {self.name}:{key} 已删除")
logger.debug(f"[cache] {self.name}:{key} deleted")
return True
return False
@@ -140,7 +140,7 @@ class DataCache:
with self._lock:
count = len(self._cache)
self._cache.clear()
logger.info(f"[缓存] {self.name} 已清空 {count} 条记录")
logger.info(f"[cache] {self.name} cleared {count} records")
return count
def cleanup_expired(self) -> int:
@@ -154,7 +154,7 @@ class DataCache:
del self._cache[key]
if expired_keys:
logger.debug(f"[缓存] {self.name} 清理 {len(expired_keys)} 条过期记录")
logger.debug(f"[cache] {self.name} cleaned {len(expired_keys)} expired records")
return len(expired_keys)
def stats(self) -> Dict[str, Any]:
@@ -84,11 +84,11 @@ class CircuitBreaker:
# Cooling is completed and enters the half-open state
state['state'] = CircuitState.HALF_OPEN
state['half_open_calls'] = 0
logger.info(f"[熔断器] {source} 冷却完成,进入半开状态")
logger.info(f"[circuit breaker] {source} cooldown finished, entering half-open state")
return True
else:
remaining = self.cooldown_seconds - time_since_failure
logger.debug(f"[熔断器] {source} 处于熔断状态,剩余冷却时间: {remaining:.0f}s")
logger.debug(f"[circuit breaker] {source} is open, remaining cooldown: {remaining:.0f}s")
return False
if state['state'] == CircuitState.HALF_OPEN:
@@ -105,7 +105,7 @@ class CircuitBreaker:
if state['state'] == CircuitState.HALF_OPEN:
# Successful in half-open state, full recovery
logger.info(f"[熔断器] {source} 半开状态请求成功,恢复正常")
logger.info(f"[circuit breaker] {source} request succeeded in half-open state, fully recovered")
# reset state
state['state'] = CircuitState.CLOSED
@@ -126,14 +126,14 @@ class CircuitBreaker:
# Fails in half-open state and continues to fuse
state['state'] = CircuitState.OPEN
state['half_open_calls'] = 0
logger.warning(f"[熔断器] {source} 半开状态请求失败,继续熔断 {self.cooldown_seconds}s")
logger.warning(f"[circuit breaker] {source} request failed in half-open state, staying open for {self.cooldown_seconds}s")
elif state['failures'] >= self.failure_threshold:
# reaches the threshold and enters the circuit breaker
state['state'] = CircuitState.OPEN
logger.warning(f"[熔断器] {source} 连续失败 {state['failures']} 次,进入熔断状态 "
f"(冷却 {self.cooldown_seconds}s)")
logger.warning(f"[circuit breaker] {source} failed {state['failures']} times consecutively and is now open "
f"(cooldown {self.cooldown_seconds}s)")
if error:
logger.warning(f"[熔断器] 最后错误: {error}")
logger.warning(f"[circuit breaker] last error: {error}")
def get_status(self) -> Dict[str, Dict[str, Any]]:
"""Get all data source status"""
@@ -151,10 +151,10 @@ class CircuitBreaker:
if source:
if source in self._states:
del self._states[source]
logger.info(f"[熔断器] 已重置 {source} 的熔断状态")
logger.info(f"[circuit breaker] reset breaker state for {source}")
else:
self._states.clear()
logger.info("[熔断器] 已重置所有数据源的熔断状态")
logger.info("[circuit breaker] reset breaker state for all data sources")
# ============================================
@@ -62,7 +62,7 @@ class DataSourceFactory:
from app.data_sources.futures import FuturesDataSource
return FuturesDataSource()
else:
raise ValueError(f"不支持的市场类型: {market}")
raise ValueError(f"Unsupported market type: {market}")
@classmethod
def get_kline(
@@ -160,7 +160,7 @@ class PolymarketDataSource:
return None
def get_market_history(self, market_id: str, days: int = 30) -> List[Dict]:
"""获取市场历史价格数据"""
"""Get historical market price data."""
# Here you need to implement historical data acquisition logic
# Temporarily returns an empty list
return []
@@ -374,7 +374,7 @@ class PolymarketDataSource:
return []
def _get_cached_markets(self, category: str = None, limit: int = 50) -> Optional[List[Dict]]:
"""从数据库缓存读取市场数据"""
"""Read market data from the database cache."""
try:
with get_db_connection() as db:
cur = db.cursor()