Skip to content

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;
    }
  }
}
  • amount is a decimal string, positive in, negative out.
  • action can also be credit, bonus, charge, correction, commission, dividend, tax.
  • A refusal (trade.no_money, trade.disabled) is a normal answer with status: "rejected", not an exception.
  • With the confirm_actions right, first get a confirm_token from staff.confirmations.create(...) and send confirm_token + confirm_code.
  • The account's terminals see the change at once as a balance socket event.