Skip to content

improve: [codex] Set Binance recvWindow by endpoint#3159

Open
nicholaspai wants to merge 13 commits intomasterfrom
npai/codex/binance-server-time-sync
Open

improve: [codex] Set Binance recvWindow by endpoint#3159
nicholaspai wants to merge 13 commits intomasterfrom
npai/codex/binance-server-time-sync

Conversation

@nicholaspai
Copy link
Copy Markdown
Member

@nicholaspai nicholaspai commented Apr 6, 2026

What changed

  • removed the custom Binance server-time synchronizer from getBinanceApiClient()
  • introduced a simple endpoint-level recvWindow policy in src/utils/BinanceUtils.ts
  • route signed read-only calls through shared helpers with recvWindow = 60000
  • route signed write-state calls through shared helpers with recvWindow = 5000
  • updated Binance call sites in the rebalancer, finalizer, and bridge adapters to use those helpers
  • added focused tests that pin the read/write recvWindow behavior

Why

The original goal is narrow: avoid Binance -1021 INVALID_TIMESTAMP / recvWindow errors without adding unnecessary complexity.

After reviewing the signed Binance calls in this repo, the cleanest policy is:

  • signed writes should stay tight, because we do not want delayed accepted requests to submit state-changing actions much later than intended
  • signed reads can tolerate a much larger validity window, because a delayed accepted request still returns current server data at processing time

That means we do not need a custom client-side time synchronizer here.

Policy

  • write-state endpoints: recvWindow = 5000
    • market order()
    • withdraw()
  • signed read/setup endpoints: recvWindow = 60000
    • tradeFee()
    • depositAddress()
    • allOrders()
    • accountCoins() / capital/config/getall
    • depositHistory()
    • withdrawHistory()
    • withdraw quota reads

Notes

This is still not a substitute for keeping the host clock reasonably synced. A larger recvWindow helps with stale timestamps, but it does not fix the case where the local clock is ahead of Binance.

Validation

  • yarn test test/BinanceUtils.ts
  • yarn eslint src/utils/BinanceUtils.ts src/rebalancer/adapters/binance.ts src/adapter/bridges/BinanceCEXBridge.ts src/adapter/bridges/BinanceCEXNativeBridge.ts src/adapter/l2Bridges/BinanceCEXBridge.ts src/adapter/l2Bridges/BinanceCEXNativeBridge.ts src/finalizer/utils/binance.ts test/BinanceUtils.ts
  • yarn build

@nicholaspai nicholaspai changed the title [codex] Sync Binance API requests to server time improve: [codex] Sync Binance API requests to server time Apr 6, 2026
@nicholaspai nicholaspai changed the title improve: [codex] Sync Binance API requests to server time improve: [codex] Cache Binance server time offset Apr 6, 2026
@nicholaspai nicholaspai marked this pull request as ready for review April 6, 2026 19:19
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1c0a2697f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@nicholaspai
Copy link
Copy Markdown
Member Author

@codex

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1923e0077

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@nicholaspai nicholaspai marked this pull request as draft April 7, 2026 20:14
@nicholaspai nicholaspai changed the title improve: [codex] Cache Binance server time offset improve: [codex] Set Binance recvWindow by endpoint Apr 7, 2026
@nicholaspai nicholaspai marked this pull request as ready for review April 7, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant