update code and fix bugs

This commit is contained in:
Kunthawat Greethong
2026-01-08 12:30:31 +07:00
parent e7487af624
commit 143f2567c7
3 changed files with 238 additions and 88 deletions

View File

@@ -290,9 +290,22 @@ def scrape_investing_gold_price(page):
def export_to_csv(df, future_price=0.0):
output_path = CSV_OUTPUT_PATH
with open(output_path, "w") as f:
f.write("date,future_price\n")
f.write(f"{datetime.now().strftime('%Y-%m-%d')},{future_price}\n")
with open(output_path, "w", encoding="utf-8") as f:
f.write("Type,Strike,OI\n")
call_df = df[df["Type"] == "CALL"] if len(df) > 0 else pd.DataFrame()
put_df = df[df["Type"] == "PUT"] if len(df) > 0 else pd.DataFrame()
if len(call_df) > 0:
for _, row in call_df.iterrows():
f.write(f"CALL,{row['Strike']:.1f},{row['OI']}\n")
if len(put_df) > 0:
for _, row in put_df.iterrows():
f.write(f"PUT,{row['Strike']:.1f},{row['OI']}\n")
f.write("\n[Price]\n")
f.write(f"FuturePrice,{future_price}\n")
logger.info(f"Exported OI data and price to {output_path}")