Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions BinomoAPI/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def to_payload(self, ref: int, created_at: Optional[int] = None, join_ref: Optio
# expire_at must be aligned to the next candle boundary (in seconds)
now_seconds = int(now)
expire_at = now_seconds - (now_seconds % self.duration_seconds) + self.duration_seconds

while (expire_at - now) < 30:
expire_at += self.duration_seconds
Comment on lines +76 to +78
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Dead-time check may be insufficient for small duration_seconds; use a loop and a named constant.

The single if only guarantees expire_at - now_seconds >= 30 when duration_seconds >= 30. _place_option (BinomoAPI/api.py:843) only validates duration_seconds > 0, so a caller passing e.g. duration_seconds=15 can still end up with expire_at - now_seconds in the dead-time window after a single adjustment (worst case ~2·duration < 30), causing the same deal_expire_at rejection this PR intends to fix.

Also, the 30 literal is the broker's freeze period and appears unexplained; promoting it to a module-level constant (and optionally validating a minimum duration_seconds upstream) makes intent explicit and keeps the logic robust.

🛠️ Suggested refactor
+# Broker's pre-expiry freeze window ("dead time"): trades whose expiry falls
+# within this many seconds of 'now' are rejected with 'deal_expire_at'.
+DEAD_TIME_SECONDS = 30
+
@@
-        # expire_at must be aligned to the next candle boundary (in seconds)
-        now_seconds = int(now)
-        expire_at = now_seconds - (now_seconds % self.duration_seconds) + self.duration_seconds
-
-        if (expire_at - now_seconds) < 30:
-            expire_at += self.duration_seconds
+        # expire_at must be aligned to the next candle boundary (in seconds)
+        now_seconds = int(now)
+        expire_at = now_seconds - (now_seconds % self.duration_seconds) + self.duration_seconds
+
+        # Push past the broker's dead-time window; loop in case duration < DEAD_TIME_SECONDS.
+        while (expire_at - now_seconds) < DEAD_TIME_SECONDS:
+            expire_at += self.duration_seconds
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@BinomoAPI/models.py` around lines 76 - 78, Replace the single if-adjustment
with a loop that repeatedly adds self.duration_seconds to expire_at until
expire_at - now_seconds >= FREEZE_PERIOD_SECONDS, and introduce a module-level
constant (e.g., FREEZE_PERIOD_SECONDS = 30) to replace the magic 30; also
consider adding validation in _place_option to ensure duration_seconds >= 1 (or
a sensible lower bound) so callers cannot pass extremely small durations that
require many iterations. Ensure you update the check that currently reads
(expire_at - now_seconds) < 30 to use FREEZE_PERIOD_SECONDS and a while loop so
the adjustment is correct for any self.duration_seconds.


return {
"topic": "bo",
Expand Down