根据市场获取对应的触发时间,并设置环境变量
(market: str)
| 182 | return None |
| 183 | |
| 184 | def get_trigger_time_for_market(market: str) -> str: |
| 185 | """根据市场获取对应的触发时间,并设置环境变量""" |
| 186 | # 设置环境变量 |
| 187 | os.environ['CONTEST_TRADE_MARKET'] = market |
| 188 | |
| 189 | # 根据市场获取触发时间 |
| 190 | if market == "CN-Stock": |
| 191 | # A股市场使用当前交易日 |
| 192 | return get_trigger_time() |
| 193 | elif market == "US-Stock": |
| 194 | # 美股市场使用美东时区时间 |
| 195 | from datetime import datetime, timezone, timedelta |
| 196 | |
| 197 | try: |
| 198 | # 尝试使用 pytz 获取美东时区 |
| 199 | import pytz |
| 200 | eastern_tz = pytz.timezone('America/New_York') |
| 201 | now = datetime.now(eastern_tz) |
| 202 | console.print(f"🇺🇸 [cyan]使用美东时区: {now.strftime('%Y-%m-%d %H:%M:%S %Z')}[/cyan]") |
| 203 | except ImportError: |
| 204 | # 如果没有 pytz,使用简单的时区计算(考虑夏令时) |
| 205 | from datetime import datetime |
| 206 | import time |
| 207 | |
| 208 | # 检查是否为夏令时(简化版本:3月第二个周日到11月第一个周日) |
| 209 | now_utc = datetime.now(timezone.utc) |
| 210 | is_dst = time.daylight and time.localtime().tm_isdst > 0 |
| 211 | |
| 212 | if is_dst: |
| 213 | # 夏令时 EDT = UTC-4 |
| 214 | offset_hours = -4 |
| 215 | tz_name = "EDT" |
| 216 | else: |
| 217 | # 标准时间 EST = UTC-5 |
| 218 | offset_hours = -5 |
| 219 | tz_name = "EST" |
| 220 | |
| 221 | eastern_tz = timezone(timedelta(hours=offset_hours)) |
| 222 | now = now_utc.astimezone(eastern_tz) |
| 223 | console.print(f"🇺🇸 [cyan]使用美东时区: {now.strftime('%Y-%m-%d %H:%M:%S')} {tz_name}[/cyan]") |
| 224 | |
| 225 | return now.strftime("%Y-%m-%d %H:%M:%S") |
| 226 | else: |
| 227 | return None |
| 228 |
no test coverage detected