Menu

Syncing MetaTrader trades to a web app: 5 bugs that taught us idempotency
📰

Syncing MetaTrader trades to a web app: 5 bugs that taught us idempotency

DEV Community: nextjs·Edgelog·9 days ago
#yUjQeMeW
#devtonextjs#devto#dev#every#journal
Reading 0:00
15s threshold

We build Edgelog, a free trading journal for forex and crypto traders. The feature people care about most is the boring one: you install a small Expert Advisor in MT4 or MT5, and your closed trades show up in the journal without copying anything by hand.

It sounds simple. A script reads closed deals and POSTs them to an API. In practice it took us a lot of versions to get it right, and almost every bug came back to the same lesson: assume every message can arrive twice, late, or never.

Here are the five that hurt the most.

1. "Send each trade once" is not a strategy

Our first version sent a deal when MetaTrader told us a trade had closed, and remembered that it had sent it. Then terminals restarted, VPSs lost their connection for an hour, and the same deal got sent again from a fresh session. Or it didn't get sent at all.

The fix was to stop trying to send things exactly once and make sending twice harmless.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.