openapi: 3.1.0
info:
  title: Tango Currency Conversion API
  version: "1.2"
  description: |
    Async REST API: client PUTs forex rate records (spot + average exchange
    rates with effective-date ranges) into Tango. Tango uses the rates for
    multi-currency translation across transaction, country, BU, and global
    currency tiers. Two-call pattern with gu_id polling.

    Tango accepts converted-currency rates from all applicable currencies
    *to* USD (the global currency). Conversions between non-USD currencies
    are out of scope — the client must derive USD-based ratios.
  x-direction: inbound
  x-source: Client System
  x-destination: Tango
servers:
  - url: https://api.tangoanalytics.com
    description: Production
  - url: https://testapi.tangoanalytics.com
    description: Test (SIT/UAT)
tags:
  - name: Exchange Rates
  - name: Status
paths:
  /v1/common/exchangerates:
    put:
      summary: Submit currency conversion records (async)
      operationId: putExchangeRatesBatch
      tags: [Exchange Rates]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ExchangeRateBatchRequest"
            examples:
              default:
                value:
                  records:
                    - source_currency: "USD"
                      converted_currency: "GBP"
                      spot_exchange_rate: "5.1111"
                      avg_exchange_rate: "4.111"
                      exchange_rate_date: "09/14/2020"
                      effective_from: "01/01/2020"
                      effective_to: "01/31/2020"
      responses:
        "200":
          description: Accepted for async processing.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AcceptedResponse"
  /v1/batch/status:
    get:
      summary: Poll processing status by gu_id
      operationId: getBatchStatus
      tags: [Status]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
        - in: query
          name: gu_id
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: Status payload.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/StatusResponse"
components:
  securitySchemes:
    xClientHeader: { type: apiKey, in: header, name: x-client }
    xApiKeyHeader: { type: apiKey, in: header, name: x-api-key }
  parameters:
    XClient:
      name: x-client
      in: header
      required: true
      schema: { type: string }
    XApiKey:
      name: x-api-key
      in: header
      required: true
      schema: { type: string }
  schemas:
    ExchangeRateBatchRequest:
      type: object
      required: [records]
      properties:
        records:
          type: array
          items:
            $ref: "#/components/schemas/ExchangeRateRecord"
    ExchangeRateRecord:
      type: object
      required:
        - source_currency
        - converted_currency
        - spot_exchange_rate
        - exchange_rate_date
        - effective_from
        - effective_to
      properties:
        source_currency:
          type: string
          description: 3-letter ISO currency code (e.g., `USD`).
        converted_currency:
          type: string
          description: 3-letter ISO currency code (e.g., `GBP`).
        spot_exchange_rate:
          type: number
          description: Decimal up to 38 places.
        avg_exchange_rate:
          type: number
          description: |
            Average rate used in payment / billing calculations. Decimal up
            to 38 places.
        exchange_rate_date:
          type: string
          description: "MM/DD/YYYY."
        effective_from:
          type: string
          description: "MM/DD/YYYY."
        effective_to:
          type: string
          description: "MM/DD/YYYY."
    AcceptedResponse:
      type: object
      required: [status, gu_id]
      properties:
        status: { type: string, enum: [OK, Error] }
        status_message: { type: string }
        gu_id: { type: string, format: uuid }
    StatusResponse:
      oneOf:
        - type: object
          properties:
            status: { type: string, const: PROCESSING }
        - type: object
          required: [status, total_records]
          properties:
            status: { type: string, const: COMPLETED }
            total_records: { type: integer }
            errors: { type: 'null' }
        - type: object
          required: [status, total_records, errors]
          properties:
            status: { type: string, const: ERROR }
            total_records: { type: integer }
            errors:
              type: array
              items:
                type: object
                required: [record_index, error]
                properties:
                  record_index: { type: integer }
                  record_key:
                    type: string
                    description: Semicolon/dash-joined `source_currency-converted_currency`.
                  error: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
