Appearance
Deposits and withdrawals
ts
/** Deposit (positive amount) or withdrawal (negative). Safe to retry: the request_id is kept. */
export async function moveMoney(login: number, amount: string, comment: string) {
const request_id = crypto.randomUUID();
for (let attempt = 0; ; attempt++) {
try {
const r = await staff.accounts.balance(login, { request_id, action: "balance", amount, comment });
// Refusals are normal answers, not errors.
if (r.status === "rejected") return { ok: false as const, code: r.code };
return { ok: true as const, deals: r.deals };
} catch (e) {
// Network lost: repeat with the same request_id to learn the first answer.
if (e instanceof NoviqaError || attempt === 2) throw e;
}
}
}amountis a decimal string, positive in, negative out.actioncan also becredit,bonus,charge,correction,commission,dividend,tax.- A refusal (
trade.no_money,trade.disabled) is a normal answer withstatus: "rejected", not an exception. - With the
confirm_actionsright, first get aconfirm_tokenfromstaff.confirmations.create(...)and sendconfirm_token+confirm_code. - The account's terminals see the change at once as a
balancesocket event.