update code and fix bugs
This commit is contained in:
@@ -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}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user