refactor-sync-to-async-api-client
This rule describes how to refactor a function from obb usage to API Client logic.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
This rule describes how to refactor a function from obb usage to API Client logic.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | refactor-sync-to-async-api-client |
| description | This rule describes how to refactor a function from obb usage to API Client logic. |
This rule describes how to refactor functions that synchronously extract data from OpenBB (or similar) sources into an asynchronous, API-client-based pattern. Use this rule to standardize data extraction across the codebase.
This rule describes how to refactor functions that synchronously extract data from OpenBB (or similar) sources into an asynchronous, API-client-based pattern. Use this rule to standardize data extraction across the codebase.
obb.equity.price.historical or similar synchronous OpenBB SDK methods.async def and update all call sites to use await.OpenBBAPIClient).EquityHistoricalQueryParams).await api_client.fetch_data(...)).Add or update the following imports as needed:
from humbldata.core.standard_models.openbbapi.EquityHistoricalQueryParams import EquityHistoricalQueryParams
from humbldata.core.utils.openbb_api_client import OpenBBAPIClient
Please
QueryParams class must exist for the API route being queried (e.g., EquityHistoricalQueryParams for equity.price.historical).src/humbldata/core/standard_models/openbbapi/ folder, named according to the route (e.g., EquityHistoricalQueryParams.py).EquityHistoricalQueryParams).pydantic.BaseModel (or your project's base QueryParams class).src/humbldata/core/standard_models/openbbapi/.If you do not know the required parameters for the API route, prompt the user to provide them or to specify the OpenBB endpoint's signature.
from pydantic import BaseModel
class EquityHistoricalQueryParams(BaseModel):
symbol: str
start_date: str
end_date: str
provider: str = "yfinance"
# Add other parameters as needed
Before:
self.equity_historical_data: pl.LazyFrame = (
obb.equity.price.historical(
symbol=self.context_params.symbols,
start_date=self.context_params.start_date,
end_date=self.context_params.end_date,
provider=self.context_params.provider,
)
.to_polars()
.lazy()
)
After:
api_query_params = EquityHistoricalQueryParams(
symbol=self.context_params.symbols,
start_date=self.context_params.start_date,
end_date=self.context_params.end_date,
provider=self.context_params.provider,
)
api_client = OpenBBAPIClient()
api_client.api_query_params = api_query_params
api_response = await api_client.fetch_data(
obb_path="equity.price.historical",
api_query_params=api_query_params,
)
self.equity_historical_data = api_response.to_polars(collect=False)
symbol column as in the original logic.