auto_trade_sys/update_atr_config.py
薇薇安 d97363e3d4 1
2026-02-14 01:27:47 +08:00

53 lines
2.2 KiB
Python

import sys
import os
# Add project root to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from backend.database.connection import db
def update_atr_config():
print("Updating ATR configuration...")
# 1. Update ATR_STOP_LOSS_MULTIPLIER
sql_check = "SELECT config_value FROM global_strategy_config WHERE config_key = 'ATR_STOP_LOSS_MULTIPLIER'"
try:
rows = db.execute_query(sql_check)
if rows:
print(f"Current ATR_STOP_LOSS_MULTIPLIER: {rows[0]['config_value']}")
sql_update = "UPDATE global_strategy_config SET config_value = '0.5' WHERE config_key = 'ATR_STOP_LOSS_MULTIPLIER'"
db.execute_update(sql_update)
print("Updated ATR_STOP_LOSS_MULTIPLIER to 0.5")
else:
sql_insert = "INSERT INTO global_strategy_config (config_key, config_value, config_type, category) VALUES ('ATR_STOP_LOSS_MULTIPLIER', '0.5', 'float', 'risk')"
db.execute_update(sql_insert)
print("Created ATR_STOP_LOSS_MULTIPLIER: 0.5")
except Exception as e:
print(f"Error updating ATR_STOP_LOSS_MULTIPLIER: {e}")
import traceback
traceback.print_exc()
# 2. Ensure USE_ATR_STOP_LOSS is True
try:
sql_check_use = "SELECT config_value FROM global_strategy_config WHERE config_key = 'USE_ATR_STOP_LOSS'"
rows_use = db.execute_query(sql_check_use)
if rows_use:
if rows_use[0]['config_value'] != 'true':
sql_update_use = "UPDATE global_strategy_config SET config_value = 'true' WHERE config_key = 'USE_ATR_STOP_LOSS'"
db.execute_update(sql_update_use)
print("Enabled USE_ATR_STOP_LOSS")
else:
sql_insert_use = "INSERT INTO global_strategy_config (config_key, config_value, config_type, category) VALUES ('USE_ATR_STOP_LOSS', 'true', 'boolean', 'risk')"
db.execute_update(sql_insert_use)
print("Created USE_ATR_STOP_LOSS: true")
except Exception as e:
print(f"Error updating USE_ATR_STOP_LOSS: {e}")
print("Database update complete.")
if __name__ == "__main__":
update_atr_config()