ReMe/reme/steps/proactive/data_connectors/tencent_quotes.py
jinliyl ae55e2e570
Some checks are pending
CI / Python packages / Build and verify distributions (push) Waiting to run
CI / Python quality / GitHub Actions (push) Waiting to run
CI / Python quality / Pre-commit (push) Waiting to run
CI / Python tests / Hermes embedded - ubuntu-latest (push) Waiting to run
CI / Python tests / Hermes embedded - windows-latest (push) Waiting to run
CI / Python tests / Unit Tests - py3.11 (push) Waiting to run
CI / Python tests / Unit Tests - py3.12 (push) Waiting to run
CI / Python tests / Unit Tests - py3.13 (push) Waiting to run
CI / Python tests / Unit Tests - py3.14 (push) Waiting to run
CI / ReMe Studio / Studio checks (push) Waiting to run
CI / Windows / CLI smoke - py3.11 (push) Waiting to run
Deploy / Documentation / Build documentation (push) Waiting to run
Deploy / Documentation / deploy (push) Blocked by required conditions
Security / CodeQL / Analyze javascript-typescript (push) Waiting to run
Security / CodeQL / Analyze python (push) Waiting to run
feat!: split proactive runtimes and add Studio backend management (#776)
* refactor(proactive)!: separate runtime ownership and unify delivery

* refactor(proactive): finish runtime and Studio migration

* test(proactive): make scheduled skip coverage deterministic

* refactor(studio): unify navigation and notebook resource loading

* feat(studio): edit workspace documents and update proactive task names

* refactor(studio): simplify task settings and navigation

* feat(studio): secure and supervise backend settings

* feat(studio): unify workbench timelines and refine desktop updates

Use shared timeline panes for notebook, memory, and resources. Add Todo creation ordering, persist companion visibility, and align desktop update handling and release artifacts.

Recheck editor file versions at read and publication boundaries. Retry reminder detail requests from the resource view.

* fix(studio): support unsigned GitHub preview releases

* fix: verify container state and isolate proactive view errors

Mount private supervisor state in Docker smoke tests and verify token and settings persistence. Exercise Studio startup with a loopback-only model fixture, and exclude packaged desktop output from Docker contexts.

Keep Remy subscriptions and healthy tasks available when an individual task has an invalid workspace path or session history.

* fix(home): align candidate Docker context exclusions

* chore(deps): update openai-codex dependency to v0.172.0

- Bump openai-codex from version 0.169.0 to 0.172.0 in pyproject.toml
- Keep other dependencies unchanged
- Ensure compatibility with latest openai-codex features and fixes

* fix(daemon): discover parent dotenv and isolate listeners

Restore parent-directory environment discovery in workers while retaining system precedence. Partition the default supervisor profile and lock by the configured bind address and port.
2026-11-25 21:33:16 +08:00

75 lines
2.9 KiB
Python

"""Collect spot gold, WTI crude oil futures, or the Nasdaq Composite from Tencent."""
from datetime import datetime
import re
from zoneinfo import ZoneInfo
import httpx
from ._finance import QuoteCollectorStep
from ....core.registry import R
from ....schema.finance import MarketQuote
_URL = "https://qt.gtimg.cn/"
_SHANGHAI = ZoneInfo("Asia/Shanghai")
_NEW_YORK = ZoneInfo("America/New_York")
_INSTRUMENTS = {
"gold": ("hf_XAU", "XAUUSD", "XAU/USD spot gold in USD per troy ounce"),
"oil": ("hf_CL", "CL", "WTI crude oil futures in USD per barrel"),
"nasdaq": ("us.IXIC", "IXIC", "Nasdaq Composite in index points"),
}
@R.register("tencent_quotes_step")
class TencentQuotesStep(QuoteCollectorStep):
"""Collect one independently scheduled instrument from Tencent."""
quote_model = MarketQuote
def __init__(self, instrument: str, **kwargs):
super().__init__(**kwargs)
self.ticker, self.symbol, label = _INSTRUMENTS[instrument]
self.source = f"{instrument}_quotes"
self.filename = f"{instrument}.jsonl"
self.description = (
f"{label} from Tencent. Read {self.filename}; change_percent is relative to previous close. "
"Use quoted_at and collected_at for freshness."
)
def fetch_quote(self, client: httpx.Client) -> MarketQuote:
data = self.request(client, _URL, params={"q": self.ticker})
received_at = self.received_at()
match = re.fullmatch(rf'v_{re.escape(self.ticker)}="([^"\r\n]*)";', data.decode("gb18030").strip())
if not match:
raise ValueError(f"Tencent returned no quote for {self.ticker}")
if self.symbol == "IXIC":
fields = match[1].split("~")
if len(fields) < 31 or fields[2] != ".IXIC":
raise ValueError("Tencent returned an incomplete Nasdaq Composite quote")
price, previous_close = float(fields[3]), float(fields[4])
quoted_at = datetime.fromisoformat(fields[30]).replace(tzinfo=_NEW_YORK)
else:
fields = match[1].split(",")
if len(fields) < 13:
raise ValueError(f"Tencent returned an incomplete quote for {self.ticker}")
price, previous_close = float(fields[0]), float(fields[7])
quoted_at = datetime.fromisoformat(f"{fields[12]}T{fields[6]}").replace(tzinfo=_SHANGHAI)
if previous_close == 0:
raise ValueError(f"Invalid previous close for {self.ticker}")
return MarketQuote(
symbol=self.symbol,
price=price,
previous_close=previous_close,
change_percent=round((price - previous_close) / abs(previous_close) * 100, 4),
quoted_at=quoted_at,
collected_at=received_at,
)
@staticmethod
def changed(quote, previous):
return quote.quoted_at >= previous.quoted_at and (quote.price, quote.previous_close) != (
previous.price,
previous.previous_close,
)