Skip to content

Commit

Permalink
🐞 fix: 锁定akshare版本,增加价格获取入口
Browse files Browse the repository at this point in the history
  • Loading branch information
henrycs committed Nov 16, 2023
1 parent fb928a6 commit fa7ffeb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 85 deletions.
5 changes: 1 addition & 4 deletions omega/akshareprice/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import cfg4py

from omega.akshareprice.datasync import init_redis_connection
from omega.akshareprice.job import start_cron_task, start_cron_task_idx
from omega.akshareprice.job import start_cron_task
from omega.config import get_config_dir

cfg = cfg4py.get_instance()
Expand Down Expand Up @@ -37,9 +37,6 @@ def run(action: str):
if action == "stock":
loop.run_until_complete(start_cron_task())
loop.run_forever()
elif action == "index":
loop.run_until_complete(start_cron_task_idx())
loop.run_forever()
else:
logger.info("action: %s not supported", action)

Expand Down
79 changes: 0 additions & 79 deletions omega/akshareprice/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,71 +86,6 @@ async def start_cron_task():
scheduler.start()


def load_cron_task_idx(scheduler):
scheduler.add_job(
fetch_idx_price_from_akshare,
"cron",
hour=9,
minute=25,
second=10,
name="fetch_index_price_task",
)

scheduler.add_job(
fetch_idx_price_from_akshare,
"cron",
hour=9,
minute="30-59",
second="*/5",
name="fetch_index_price_task",
)
scheduler.add_job(
fetch_idx_price_from_akshare,
"cron",
hour=10,
second="*/5",
name="fetch_index_price_task",
)
scheduler.add_job(
fetch_idx_price_from_akshare,
"cron",
hour=11,
minute="0-29",
second="*/5",
name="fetch_index_price_task",
)
scheduler.add_job(
fetch_idx_price_from_akshare,
"cron",
hour=11,
minute=30,
second=10,
name="fetch_index_price_task",
)

scheduler.add_job(
fetch_idx_price_from_akshare,
"cron",
hour="13-14",
second="*/5",
name="fetch_index_price_task",
)
scheduler.add_job(
fetch_idx_price_from_akshare,
"cron",
hour=15,
minute=0,
second=10,
name="fetch_index_price_task",
)


async def start_cron_task_idx():
scheduler = AsyncIOScheduler(timezone="Asia/Shanghai")
load_cron_task_idx(scheduler)
scheduler.start()


def get_akshare_data_em():
try:
all_secs = ak.stock_zh_a_spot_em()
Expand Down Expand Up @@ -229,20 +164,6 @@ async def fetch_price_from_akshare():
logger.info("%s side: %s", running_mode, now)
await process_stock_price()

return True


async def fetch_idx_price_from_akshare():
# cfg = cfg4py.get_instance()
running_mode = "server"

now = datetime.datetime.now()
if now.weekday() >= 5: # 周末不运行
return True

seconds = now.second
_seq_num = seconds / 5

if _seq_num % 4 == 0: # running at 0, 20, 40
logger.info("%s side for index: %s", running_mode, now)
await process_index_price()
Expand Down
17 changes: 17 additions & 0 deletions omega/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ async def start_logger():
print("Omega logger process started ...")


async def start_realprice_stock():
print("prepare to start Omega real price process for stock ...")

subprocess.Popen(
[
sys.executable,
"-m",
"omega.akshareprice.app",
"stock",
],
stdout=subprocess.DEVNULL,
)

print("Omega stock price process started ...")


async def import_local_data():
print("正在初始化系统数据...")

Expand Down Expand Up @@ -145,6 +161,7 @@ def main():
"webservice": run(start_webservice),
"logger": run(start_logger),
"importdata": run(import_local_data),
"stock_price": run(start_realprice_stock),
}
)

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ include = [
"tests/*"
]

version = "2.0.0a8"
version = "2.0.0a9"

[tool.poetry.dependencies]
python=">=3.8,<3.9"
Expand Down Expand Up @@ -83,8 +83,9 @@ mike = { version="^1.1.2", optional=true}
freezegun = {version = "^1.2.1", optional = true}
zarr = "^2.13.3"
sanic = "^22.9.1"
akshare = "^1.8.27"
akshare = ">=1.8,<1.9"
retry = "^0.9.2"
urllib3 = ">=1.26.14,<2.0"

[tool.poetry.extras]
test = [
Expand Down

0 comments on commit fa7ffeb

Please sign in to comment.