@@ -116,6 +116,37 @@ def strategy_run_history_key(
116116 )
117117
118118
119+ def strategy_run_claim_key (
120+ * , account : str , strategy_profile : str , run_period : str ,
121+ ) -> str :
122+ """Permanent live claim key; a failed/unknown submission must remain blocked."""
123+ return (
124+ f"strategy-runs/claims/{ safe_key (account )} /{ safe_key (strategy_profile )} /"
125+ f"{ safe_key (run_period )} .json"
126+ )
127+
128+
129+ def claim_live_strategy_run (
130+ * , store : GcsStateStore , account : str , strategy_profile : str ,
131+ run_period : str , now : datetime | None = None ,
132+ ) -> bool :
133+ """Acquire the durable pre-order claim using object-store create-if-absent."""
134+ payload = {
135+ "stage" : "PENDING_SUBMISSION" ,
136+ "account" : account ,
137+ "strategy_profile" : strategy_profile ,
138+ "run_period" : run_period ,
139+ "as_of" : (now or utcnow ()).isoformat (),
140+ "no_order_submitted" : True ,
141+ }
142+ return store .create_json (
143+ strategy_run_claim_key (
144+ account = account , strategy_profile = strategy_profile , run_period = run_period ,
145+ ),
146+ payload ,
147+ )
148+
149+
119150def read_latest_strategy_run_state (
120151 * ,
121152 store : GcsStateStore ,
0 commit comments