Commit c7efa11
committed
Fix: untracked broker positions + 0 DTE display
Two related fixes that surfaced from a real trade through the platform
that ended up tagged 'External broker position':
1. Position-cache semantics. _fetch_broker_positions used to return
fresh=True on cache hits, which caused the destructive cleanup loop
in get_position_details to delete tracked positions whenever the
cache happened to be older than the position's creation. Symptom:
open a position via the platform, broker fills it, position written
to our DB, next /api/position poll deletes it because the cached
broker snapshot (5s old) didn't see it yet. The position then shows
as 'External broker position' because it exists at broker but not
in our DB. Renamed the flag to just_fetched and only set it True on
actual broker fetches, not cache hits.
2. Auto-import untracked broker option positions. Even with the cache
fix, any future bug class that breaks position-creation would leave
the user with unmanageable positions. Now: when get_position_details
sees an option position at the broker that isn't in our DB, it
self-imports it as a tracked position with conservative defaults
(no SL/TP, dte=0). User can drag SL/TP pills on the chart to
attach exits.
3. DTE display polish in PositionTracker. position.dte || 'N/A' was
conflating 'missing dte' with 'dte=0', so 0 DTE positions (a primary
use case) showed 'N/A'. Swapped to ?? so only null/undefined falls
back. Real 0 now displays as 0.
Verified:
- Auto-import test: untracked broker option appears, no 'External
broker position' tag, X close button visible.
- Cache test: 4/4 cases pass — first call just_fetched=True, cache hit
just_fetched=False (the fix), TTL expiry re-fetches, broker failure
serves stale with just_fetched=False.1 parent 1cd2a32 commit c7efa11
2 files changed
Lines changed: 70 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
65 | 78 | | |
66 | 79 | | |
67 | 80 | | |
68 | 81 | | |
69 | 82 | | |
70 | | - | |
| 83 | + | |
71 | 84 | | |
72 | 85 | | |
73 | 86 | | |
| |||
83 | 96 | | |
84 | 97 | | |
85 | 98 | | |
86 | | - | |
87 | | - | |
88 | 99 | | |
89 | 100 | | |
90 | 101 | | |
| |||
1055 | 1066 | | |
1056 | 1067 | | |
1057 | 1068 | | |
1058 | | - | |
1059 | | - | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
1063 | 1074 | | |
1064 | 1075 | | |
1065 | 1076 | | |
1066 | | - | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
1070 | 1081 | | |
1071 | 1082 | | |
1072 | 1083 | | |
1073 | 1084 | | |
1074 | 1085 | | |
1075 | 1086 | | |
1076 | 1087 | | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
1077 | 1130 | | |
1078 | 1131 | | |
1079 | 1132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| |||
0 commit comments