first commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""可选:手动回填到期结算 / 历史指数。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
os.chdir(ROOT)
|
||||
|
||||
from apps.worker.settle import backfill_settlements
|
||||
from packages.config import get_settings
|
||||
from packages.db import Repository
|
||||
|
||||
|
||||
def main() -> int:
|
||||
s = get_settings()
|
||||
repo = Repository(s.db_path)
|
||||
try:
|
||||
result = backfill_settlements(
|
||||
repo,
|
||||
underlying=s.underlying,
|
||||
index_inst_id=s.index_inst_id,
|
||||
)
|
||||
print(result)
|
||||
return 0 if not result["errors"] else 1
|
||||
finally:
|
||||
repo.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,43 @@
|
||||
"""冒烟:拉一次 OKX 指数 + 选 ATM 并打印(不强制写库)。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
os.chdir(ROOT)
|
||||
|
||||
from apps.collector.okx_rest import OkxRestClient
|
||||
from apps.collector.selectors import rows_to_contracts, select_atm_pair
|
||||
from packages.config import get_settings
|
||||
from packages.domain import option_leverage
|
||||
|
||||
|
||||
def main() -> int:
|
||||
s = get_settings()
|
||||
with OkxRestClient(base_url=s.okx_base_url, proxy=s.okx_proxy or None) as client:
|
||||
idx = client.fetch_index_ticker(s.index_inst_id)
|
||||
print(f"index {s.index_inst_id} = {idx}")
|
||||
raw = client.fetch_option_instruments(s.option_inst_family)
|
||||
contracts = rows_to_contracts(raw)
|
||||
print(f"live contracts = {len(contracts)}")
|
||||
pair = select_atm_pair(contracts, index_px=float(idx or 0), min_hours=s.min_option_hours)
|
||||
if not pair:
|
||||
print("no ATM pair")
|
||||
return 1
|
||||
print(
|
||||
f"ATM expiry={pair.expiry_ymd} strike={pair.strike} "
|
||||
f"C={pair.call_inst_id} P={pair.put_inst_id}"
|
||||
)
|
||||
for side, inst in (("C", pair.call_inst_id), ("P", pair.put_inst_id)):
|
||||
ask, bid, *_ = client.fetch_books(inst)
|
||||
lev = option_leverage(float(idx), ask)
|
||||
print(f" {side}: ask={ask} bid={bid} leverage={lev}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user