From ddabc744f24b389f6d383fe3e8f0169a2fccd903 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 11 Jun 2025 14:23:13 +0000 Subject: [PATCH] chore: Update alphaworx_zen_hk_live init.py to query new secret I decided to put all alphaworx api keys in one secret. It's easier this way. --- .../alphaworx_zen_hk_live/init_env.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/app_sparkd/configurations/alphaworx_zen_hk_live/init_env.py b/src/app_sparkd/configurations/alphaworx_zen_hk_live/init_env.py index 5f9d3549a..8c050f527 100644 --- a/src/app_sparkd/configurations/alphaworx_zen_hk_live/init_env.py +++ b/src/app_sparkd/configurations/alphaworx_zen_hk_live/init_env.py @@ -35,8 +35,8 @@ def update_env_file(path, env_vars: dict): def get_secret(): - secret_name = "alphaworx-binance-api-keys" - region_name = "ap-northeast-1" + secret_name = "alphaworx_api_keys" + region_name = "us-east-1" profile_name = "bts-ap-northeast-1" session = Session(profile_name=profile_name) client = session.client( @@ -77,10 +77,19 @@ def _run(): exit(1) secret = json.loads(secret_str) env_vars = {} - if "api-key" in secret: - env_vars["BINANCE_API_KEY"] = secret["api-key"] - if "secret-key" in secret: - env_vars["BINANCE_SECRET_KEY"] = secret["secret-key"] + + def set_env_var(key_name: str, *json_path): + try: + val = secret[json_path[0]] + for p in json_path[1:]: + val = val[p] + env_vars[key_name] = val + print(f"Set {key_name}={val} ({'.'.join(json_path)})") + except KeyError: + print(f"Failed to set {key_name}= ({'.'.join(json_path)})") + + set_env_var("BINANCE_API_KEY", "binance", "prod", "api_key") + set_env_var("BINANCE_SECRET_KEY", "binance", "prod", "secret_key") update_env_file(f"{this_dir}/.env.local", env_vars)