> ## Documentation Index
> Fetch the complete documentation index at: https://learn.breezing.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Calculate Net Gain/Loss API

> Recompute Breezing realized and unrealized net gain or loss across crypto transactions using the company's cost basis method.



## OpenAPI

````yaml POST /ngl/calculate
openapi: 3.1.0
info:
  title: Breezing Public API
  version: 1.0.0
  description: >-
    Crypto accounting API for programmatic access and AI agents. Authenticate
    with an API key using the Authorization header: `Bearer brz_...`
servers:
  - url: https://api.breezing.io/v1
security:
  - BearerAuth: []
paths:
  /ngl/calculate:
    post:
      tags:
        - Net Gain Loss
      summary: Recompute net gain/loss
      description: >-
        Recompute net gain/loss (cost basis) for the company. Long-running
        background job that walks every unlocked transaction in scope, applies
        the selected cost-basis method (average / FIFO / LIFO / HIFO), and
        writes the resulting realized/unrealized gain or loss back onto each
        transaction. Returns immediately once the jobs are queued; poll GET
        /tasks for `operation: "netGainLoss"` (or `operation:
        "netGainLossPrep1"` while a lot-based method is preparing) to monitor
        progress.


        **Duplicate-run protection:** if a `netGainLoss` or `netGainLossPrep1`
        task is already in `pending` or `progress` status for this company, this
        endpoint returns 409 CONFLICT. NEVER let two NGL recomputes run in
        parallel for the same company. The cost-basis math depends on processing
        transactions in deterministic order, and overlapping runs produce
        inconsistent values. Always call GET /tasks first.


        If `method` and `isPerWallet` are omitted, the endpoint uses the
        company's configured defaults (companies.accountingMethod and
        companies.accountingIsPerWallet).
      parameters:
        - schema:
            type: string
            description: >-
              Organization ID. Use GET /v1/companies to discover available
              org/company pairs.
            example: '1'
          required: true
          description: >-
            Organization ID. Use GET /v1/companies to discover available
            org/company pairs.
          name: orgId
          in: query
        - schema:
            type: string
            description: >-
              Company ID. Use GET /v1/companies to discover available companies
              and their access levels.
            example: '1'
          required: true
          description: >-
            Company ID. Use GET /v1/companies to discover available companies
            and their access levels.
          name: companyId
          in: query
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CalculateNglBody'
      responses:
        '200':
          description: Recompute queued
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - true
                  data:
                    type: object
                    properties:
                      started:
                        type: boolean
                        enum:
                          - true
                      method:
                        type: string
                        enum:
                          - average
                          - fifo
                          - lifo
                          - hifo
                      isPerWallet:
                        type: boolean
                      note:
                        type: string
                    required:
                      - started
                      - method
                      - isPerWallet
                      - note
                required:
                  - success
                  - data
        '400':
          description: >-
            Invalid input (e.g. isPerWallet=true without wallets, or toDate in
            an invalid format)
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                required:
                  - success
                  - error
        '401':
          description: Invalid or missing API key
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                required:
                  - success
                  - error
        '403':
          description: >-
            API key has no access to this company, has read-only access where
            write was required, or the company subscription is inactive
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                required:
                  - success
                  - error
        '409':
          description: A net gain/loss recompute is already running for this company
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                required:
                  - success
                  - error
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                required:
                  - success
                  - error
      security:
        - BearerAuth: []
components:
  schemas:
    CalculateNglBody:
      type: object
      properties:
        method:
          type: string
          enum:
            - average
            - fifo
            - lifo
            - hifo
          description: >-
            Cost-basis method. If omitted, uses the company's configured default
            (companies.accountingMethod). Changing this overrides the default
            for this run only.
        isPerWallet:
          type: boolean
          description: >-
            When true, NGL is computed separately per wallet rather than pooled
            across all wallets per token. If omitted, uses the company's
            configured default (companies.accountingIsPerWallet). Setting true
            requires `wallets` to be a non-empty array.
        tokens:
          type: array
          items:
            type: string
          description: >-
            Optional list of token symbols to include. Omit (or pass an empty
            array) to include ALL tokens. Note this is heavier and may take
            significantly longer.
        wallets:
          type: array
          items:
            type: integer
            minimum: 0
            exclusiveMinimum: true
          description: >-
            Wallet IDs to include. Required when `isPerWallet` is true. Ignored
            otherwise.
        toDate:
          type: string
          pattern: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$
          description: >-
            Optional cutoff datetime in format "YYYY-MM-DD HH:mm:ss" (e.g.
            "2025-12-31 23:59:59"). When provided, NGL is calculated as of this
            datetime, useful for period-end closes. Omit to use the current
            time.
          example: '2025-12-31 23:59:59'

````