Egis Dev – 12/02
Theme: Determinism, Hedge Mode Reality, and Admin Cohesion
Today was one of those “systems maturity” days — less about building new features, more about confronting edge cases and tightening the contract between Egis and reality (Binance).
1️⃣ Hedge Mode Wasn’t “Just a Setting”
The biggest battle today was the recurring Binance error:
Order’s position side does not match user’s setting (-4061)
At first, it looked like a simple parameter bug.
But the deeper lesson was this:
In Hedge Mode, side is not enough.
In One-way mode, BUY / SELL is sufficient.
In Hedge Mode, every order must explicitly declare:
- positionSide (LONG / SHORT)
- correct side
- correct intent (OPEN vs CLOSE)
- correct reduceOnly semantics
The breakthrough was separating trade intent from exchange parameters:
| Concept | Meaning |
|---|---|
| Direction | LONG / SHORT (what position we’re operating on) |
| Action | OPEN / CLOSE |
| Exchange Params | side + positionSide + reduceOnly |
That separation made entry orders work.
Then SL/TP exposed that we hadn’t fully aligned the protective order builder with the same intent logic.
Lesson:
In Hedge Mode, every order — entry, SL, TP — must be mapped from the same intent model.
No shortcuts. No “derive from side”.
2️⃣ Evidence-First Debugging Changed Everything
Instead of guessing, we:
- Created a dedicated binance-order-debug.log
- Logged:
- direction
- action
- side
- positionSide
- reduceOnly
- payload
- raw Binance error
This was crucial.
Once the ENTRY order succeeded but SL/TP failed, the logs immediately showed the mismatch pattern.
That reinforced a core Egis principle:
Never fix blind.
Log first. Observe. Then act.
Egis is becoming less “code-first” and more evidence-first.
3️⃣ Exchange Architecture Evolution
We formalized exchange identity:
- Renamed existing Binance → Binance Demo
- Added Binance Real
- Single adapter, environment switched by exchange key
- Removed legacy paper exchange completely
This is more than naming.
It moves Egis from:
implicit environment (.env-based behavior)
to:
explicit exchange identity at the domain level.
That’s a structural upgrade.
Now exchange is:
- A first-class entity
- Persisted
- Deterministic
- Testable
4️⃣ Admin UX Maturity
Several Admin improvements today:
- Global Exchange filter
- Fixed /undefined?exchange= routing bug
- Removed legacy “P” option (Paper ghost)
- Moved exchange dropdown next to logo
- Made filter persistent across:
- Page navigation
- Logout/login
This turned the Exchange filter into a true global scope controller instead of a cosmetic dropdown.
Key insight:
Global filters must be server-authoritative.
Client state alone is not durable enough.
We moved toward:
- DB-backed user preference
- Deterministic resolution order:
- Query param
- User preference
- Default = all
That’s system thinking, not UI thinking.
5️⃣ A Bigger Bug: DB vs Binance Truth
We discovered positions 195 and 196:
- Closed in Egis
- Still open on Binance
That is dangerous.
It exposed a deeper philosophical rule:
Egis must never mark a position CLOSED unless Binance is actually flat.
Possible root patterns we’re now investigating:
- Marking closed on order placement instead of fill
- Close order failed but DB transaction committed
- Hedge leg misinterpretation during sync
- Partial closure edge case
We designed a new debug command:
egis:debug:position-consistency {id}
This is huge.
It formalizes reconciliation between:
- DB truth
- Exchange truth
That’s infrastructure maturity.
What I Learned Today
- Hedge Mode forces explicit modeling.You cannot “infer” safely.
- Intent must exist before parameters.Domain logic > exchange mapping.
- Logging is architecture.Debug logs are not temporary hacks — they are operational safety nets.
- Global filters are state machines.If not server-backed, they will drift.
- Never declare something closed until reality confirms it.
Strategic Reflection
Today felt like Egis crossed a line:
From:
“It works if everything behaves.”
To:
“It works even when reality disagrees.”
That’s the difference between a prototype and a system.
And systems are what scale.
