Trading API
Track status
Follow a trade or withdrawal until it settles: poll it, or stream live updates.
Submitting returns an id plus a statusUrl and an eventsUrl. Both give
the same object: status, a final flag, and, while it’s pending, a
human-readable step.
status | Meaning | Final |
|---|---|---|
pending | Submitted and in progress. step says what’s happening. | No |
completed | Done. receive (swaps) or amount (withdrawals) shows what arrived. | Yes |
failed | Didn’t go through. reason says why. A failed swap’s funds come back on their own, and it then turns refunded. | Swaps: no. Withdrawals: yes |
refunded | A failed swap’s funds are back in your balance. | Yes |
cancelled | A withdrawal was cancelled and its funds returned. | Yes |
Stop when final is true. Most trades settle in seconds; withdrawals take
about a minute, and a few minutes on Ethereum.
Poll
let status;
do {
await new Promise((resolve) => setTimeout(resolve, 2000));
status = await (await fetch(trade.statusUrl)).json();
} while (!status.final);Stream
The /events routes are server-sent events. Each message is the full status
object. The first one is the current status, so a late or reconnecting client
never misses the outcome. The stream closes after the final status.
curl -N https://api.gum.ag/app/v1/swap/<id>/eventsIn a browser, EventSource reconnects for you:
const events = new EventSource(trade.eventsUrl);
events.onmessage = (event) => {
const status = JSON.parse(event.data);
console.log(status.status, status.step ?? "");
if (status.final) events.close();
};In Node, read the stream and reconnect when it drops:
const API = "https://api.gum.ag/app/v1";
const url = `${API}/swap/${process.argv[2]}/events`;
for (;;) {
try {
const response = await fetch(url);
const decoder = new TextDecoder();
let buffer = "";
for await (const chunk of response.body) {
buffer += decoder.decode(chunk, { stream: true });
let end = buffer.indexOf("\n\n");
while (end >= 0) {
const data = buffer
.slice(0, end)
.split("\n")
.filter((line) => line.startsWith("data: "))
.map((line) => line.slice(6))
.join("\n");
buffer = buffer.slice(end + 2);
end = buffer.indexOf("\n\n");
if (!data) continue;
const status = JSON.parse(data);
console.log(status.status, status.step ?? "");
if (status.final) process.exit(0);
}
}
} catch {
// The connection dropped; reconnect below.
}
await new Promise((resolve) => setTimeout(resolve, 3000));
}Use /withdraw/{id}/events the same way for withdrawals.
Deposits
GET /v1/deposits/{address}/events streams deposits as they reach your
account: one message when a deposit is seen, another when it’s credited. It’s
live only, so open it before you send funds. To find past deposits, use
GET /v1/history/{address}?type=deposit.
curl -N https://api.gum.ag/app/v1/deposits/<address>/events