On this page7
  1. At a glance
  2. Scoring a possible match
  3. Why the threshold is 7
  4. Is spending speeding up?
  5. Details that keep the numbers honest
  6. Signing requests to a bank
  7. Hiring someone to turn business problems into tools?

Part of my work on TFI Wallet. By Mohammad Javad Dastouri, full-stack and AI engineer.

How TFI Wallet decides that a bank line and a CRM record are the same money, and how it measures whether spending is speeding up.

At a glance

Area
Data and forecasting
My role
Lead engineer and architect: sole designer and implementer
Built with
Node.js 22, MySQL 8, Wise Bank API, RSA/SHA-256 signing
Area
Data and forecasting
My role
Lead engineer and architect: sole designer and implementer
Built with
Node.js 22, MySQL 8, Wise Bank API, RSA/SHA-256 signing

Scoring a possible match

The two sides never agree exactly, so every candidate pair gets points on four signals.

  • Order code

    Condition
    Identical on both sides
    Points
    +5
  • Amount

    Condition
    Difference under 0.01
    Points
    +4
  • Date

    Condition
    Same day, within 3 days, within 10 days
    Points
    +3, +2, +1
  • Counterparty

    Condition
    Fuzzy text match
    Points
    +2
  • Order code

    Condition
    Identical on both sides
    Points
    +5
  • Amount

    Condition
    Difference under 0.01
    Points
    +4
  • Date

    Condition
    Same day, within 3 days, within 10 days
    Points
    +3, +2, +1
  • Counterparty

    Condition
    Fuzzy text match
    Points
    +2

An exact order code outranks an exact amount, because identical amounts recur constantly while an order code is close to unique. Each bank line keeps its top 3 candidates.

Why the threshold is 7

A pair needs 7 of 14 points to be proposed as a match. No single signal gets there, and neither do date and counterparty alone. It takes an order code plus one more signal, or an exact amount plus a near-exact date.

That leaves one known risk: two unrelated payments of the same amount on the same day score exactly 7. So a score only proposes a match, and a person signs it off.

Exceptions matter as much as matches. A bank line with no internal record is unrecorded spend. An internal record with no bank line was booked but never cleared. The engine labels both for an accountant to see.

Is spending speeding up?

Velocity is average USD spent per day across the chosen window. Acceleration is measured three ways, because each one fails differently.

  • Half split

    Computation
    Mean of the recent half minus mean of the older half
    Detects
    Sustained change
    Weak on
    Shape within each half
  • Slope

    Computation
    Least-squares regression over daily spend
    Detects
    Gradual drift
    Weak on
    A single outlier day
  • Latest against average

    Computation
    Last active day minus window mean
    Detects
    A sudden spike
    Weak on
    Sparse data
  • Half split

    Computation
    Mean of the recent half minus mean of the older half
    Detects
    Sustained change
    Weak on
    Shape within each half
  • Slope

    Computation
    Least-squares regression over daily spend
    Detects
    Gradual drift
    Weak on
    A single outlier day
  • Latest against average

    Computation
    Last active day minus window mean
    Detects
    A sudden spike
    Weak on
    Sparse data

The three signs are summed into one call: up, down or flat. The raw figures stay visible, because disagreement between them is itself a signal that the spending is irregular.

Details that keep the numbers honest

  • Zero days count

    A wallet that spent on three days of a thirty-day window has a low velocity. Averaging only active days would overstate it tenfold.

  • The latest day looks back

    The latest-day method looks back to the last real spending day, so a quiet day does not read as a sharp slowdown.

  • Source time zones

    Spend is counted on the local day each record was made, not by server time.

  • Dormant wallets

    A wallet last paid months ago looked like "no spend". The "all" window now follows each wallet's own activity. Found in production and fixed the next day.

  • Zero days count

    A wallet that spent on three days of a thirty-day window has a low velocity. Averaging only active days would overstate it tenfold.

  • The latest day looks back

    The latest-day method looks back to the last real spending day, so a quiet day does not read as a sharp slowdown.

  • Source time zones

    Spend is counted on the local day each record was made, not by server time.

  • Dormant wallets

    A wallet last paid months ago looked like "no spend". The "all" window now follows each wallet's own activity. Found in production and fixed the next day.

Signing requests to a bank

The bank client works across Wise API v1, v3 and v4. Wise protects high-risk endpoints, such as balance statements and transfer funding, with a 2FA challenge an API token cannot pass. The client answers it over the API.

  1. Call the protected endpoint.

  2. Wise answers 403 with a one-time token.

  3. Sign that token with an RSA private key, SHA-256.

  4. Retry the same request with the token and the signature.

  1. Call the protected endpoint.

  2. Wise answers 403 with a one-time token.

  3. Sign that token with an RSA private key, SHA-256.

  4. Retry the same request with the token and the signature.

Hiring someone to turn business problems into tools?

Tell me about the role, or go back to the project: the platform this engineering runs in.

Section
Data and forecasting
Updated
November 9, 2026
Reading time
3 min read

Hiring for this kind of work?

Tell me about the role and I will reply by email.

Discuss a role with me