Skip to content

Commit e522418

Browse files
committed
Freeze Swapter pagination upper time bound
Compute timeTo once before the paging loop instead of per request, so orders arriving mid-walk cannot shift the window and page boundaries and skip or duplicate rows before completion is decided.
1 parent 3b3d736 commit e522418

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/partners/swapter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ export const querySwapter = async (
135135
let previousTimestamp = new Date(latestIsoDate).getTime() - QUERY_LOOKBACK
136136
if (previousTimestamp < 0) previousTimestamp = 0
137137

138+
// Freeze the upper time bound for the whole pagination walk. Recomputing
139+
// Date.now() per page would shift the window and page boundaries if orders
140+
// arrive mid-walk, which can skip or duplicate rows before completion.
141+
const queryTimeTo = Date.now()
142+
138143
let page = 1
139144
let retry = 0
140145

@@ -152,7 +157,7 @@ export const querySwapter = async (
152157
page,
153158
items: LIMIT,
154159
timeFrom: previousTimestamp,
155-
timeTo: Date.now()
160+
timeTo: queryTimeTo
156161
})
157162
}
158163
)

0 commit comments

Comments
 (0)