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

# Get affiliate traffic and sales by period

> Requires an affiliate API key. Returns clicks, visitors, sign-ups, purchasers, orders, revenue, and commission in UTC day, week, or month buckets, matching the Analytics tab. `start` and `end` select the whole UTC days that contain them, both inclusive. The range is clamped to the day you joined and to today. Day and week grouping cover at most 400 days; a longer range returns `400` with code `range_too_large`. A range with more than 5,000 sales returns `400` with code `too_many_sales`.



## OpenAPI

````yaml /openapi.yaml get /v1/affiliate/stats
openapi: 3.1.0
info:
  title: MyFundedPerps API (Beta)
  version: 1.0.0
  description: >-
    The developer API is in beta. Breaking changes may be introduced at any
    time. Programmatic access to MyFundedPerps paper-trading challenge accounts.
    API trades use the same real order books and simulated execution engine as
    the web trading interface. Every response carries an `X-Request-Id` header
    for support and log correlation.
  contact:
    url: https://myfundedperpetuals.com/contact
servers:
  - url: https://developers.myfundedperpetuals.com
    description: Live
  - url: https://sandbox.myfundedperpetuals.com
    description: Sandbox (test keys and sandbox accounts only)
security:
  - bearerAuth: []
  - bearerAuth: []
    partnerKey: []
tags:
  - name: General
  - name: Authentication
  - name: Accounts
  - name: Markets
  - name: Positions
  - name: Orders
  - name: Fills
  - name: Strategy Orders
  - name: Price Alerts
  - name: Affiliate
paths:
  /v1/affiliate/stats:
    get:
      tags:
        - Affiliate
      summary: Get affiliate traffic and sales by period
      description: >-
        Requires an affiliate API key. Returns clicks, visitors, sign-ups,
        purchasers, orders, revenue, and commission in UTC day, week, or month
        buckets, matching the Analytics tab. `start` and `end` select the whole
        UTC days that contain them, both inclusive. The range is clamped to the
        day you joined and to today. Day and week grouping cover at most 400
        days; a longer range returns `400` with code `range_too_large`. A range
        with more than 5,000 sales returns `400` with code `too_many_sales`.
      operationId: getAffiliateStats
      parameters:
        - name: start
          in: query
          description: Unix timestamp in milliseconds. Defaults to 29 days before `end`.
          schema:
            type: integer
            minimum: 0
        - name: end
          in: query
          description: Unix timestamp in milliseconds. Defaults to now.
          schema:
            type: integer
            minimum: 0
        - name: grouping
          in: query
          schema:
            type: string
            enum:
              - day
              - week
              - month
            default: day
        - name: campaign_id
          in: query
          description: Limit figures to one campaign from `GET /v1/affiliate/campaigns`.
          schema:
            type: string
            maxLength: 64
      responses:
        '200':
          description: Figures per bucket.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: '#/components/schemas/AffiliateStats'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/AffiliateNotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
        '503':
          $ref: '#/components/responses/AffiliateDataPreparing'
components:
  schemas:
    AffiliateStats:
      type: object
      required:
        - start
        - end
        - grouping
        - traffic_updated_at
        - buckets
      properties:
        start:
          type: number
          description: First UTC day covered
          in Unix milliseconds.: null
        end:
          type: number
          description: End of the last UTC day covered (exclusive), in Unix milliseconds.
        grouping:
          type: string
          enum:
            - day
            - week
            - month
        traffic_updated_at:
          type:
            - number
            - 'null'
          description: >-
            When traffic figures were last updated. Traffic can trail by up to
            this long.
        buckets:
          type: array
          items:
            $ref: '#/components/schemas/AffiliateStatsBucket'
    AffiliateStatsBucket:
      type: object
      required:
        - start
        - end
        - clicks
        - visitors
        - signups
        - purchasers
        - orders
        - revenue
        - commission
      properties:
        start:
          type: number
          description: Unix timestamp in milliseconds.
        end:
          type: number
          description: Exclusive end
          in Unix milliseconds.: null
        clicks:
          type:
            - integer
            - 'null'
          description: Null before click tracking began.
        visitors:
          type:
            - integer
            - 'null'
        signups:
          type:
            - integer
            - 'null'
        purchasers:
          type: integer
          description: Distinct customers who bought in this bucket.
        orders:
          type: integer
        revenue:
          type: number
          description: Order value in USD.
        commission:
          type: number
          description: Pending and approved commission in USD, excluding reversals.
    ErrorEnvelope:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/Error'
    Error:
      type: object
      required:
        - code
        - message
        - request_id
      properties:
        code:
          type: string
        message:
          type: string
        request_id:
          type: string
          format: uuid
        details:
          type: array
          description: >-
            Present on request-validation failures, with one entry per invalid
            field so a request can be fixed in one pass.
          items:
            $ref: '#/components/schemas/ValidationIssue'
    ValidationIssue:
      type: object
      required:
        - field
        - issue
      properties:
        field:
          type: string
          description: >-
            Wire name of the offending request field, such as `size` or
            `operations[2].price`. The value `body` refers to the whole payload.
        issue:
          type: string
  responses:
    BadRequest:
      description: >-
        Invalid request. Validation failures list every offending field in
        `error.details`.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Unauthorized:
      description: Missing, invalid, or revoked API key, or an invalid partner key.
      headers:
        WWW-Authenticate:
          schema:
            type: string
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Forbidden:
      description: The API key is valid but does not allow this operation.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    AffiliateNotFound:
      description: >-
        The key's owner is not an active affiliate. Affiliate keys stop working
        while an affiliate account is suspended.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    RateLimited:
      description: >-
        The per-IP request limit, a partner budget, or an account-wide operation
        budget is exhausted.
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
        X-RateLimit-Limit:
          $ref: '#/components/headers/RateLimitLimit'
        X-RateLimit-Scope:
          $ref: '#/components/headers/RateLimitScope'
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    AffiliateDataPreparing:
      description: >-
        Affiliate figures are briefly unavailable while they are rebuilt. Retry
        after the delay.
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
  headers:
    RequestId:
      description: Stable identifier for support and log correlation.
      schema:
        type: string
        format: uuid
    RetryAfter:
      description: Seconds to wait before retrying.
      schema:
        type: integer
        minimum: 1
    RateLimitLimit:
      description: >-
        Requests per minute allowed by the request budget that ran out. Sent on
        request-budget 429s; account-wide operation budget 429s omit it.
      schema:
        type: integer
        minimum: 1
    RateLimitScope:
      description: >-
        Which request budget ran out: `ip` for the per-address limit, `api_key`
        for a partner's per-trader-key budget, or `partner` for a partner's
        combined budget. Sent on request-budget 429s; account-wide operation
        budget 429s omit it.
      schema:
        type: string
        enum:
          - ip
          - api_key
          - partner
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: MyFundedPerps API key
      description: >-
        API key beginning with `fp_live_` (live keys, served at
        developers.myfundedperpetuals.com) or `fp_test_` (test keys, served at
        sandbox.myfundedperpetuals.com). A key presented on the other host is
        rejected with `401` and a message naming the correct host. Affiliate API
        keys are `fp_live_` keys created on the Affiliates page: they read only
        the `/v1/affiliate` endpoints and get `403` with code
        `insufficient_scope` on every other authenticated endpoint. Every other
        key gets the same `403` on `/v1/affiliate`.
    partnerKey:
      type: apiKey
      in: header
      name: X-MFP-Partner-Key
      description: >-
        Optional partner key beginning with `mfp_partner_`, issued by
        MyFundedPerps to platforms that call the live API on behalf of many
        traders. Send it beside the trader's own `fp_live_` key: the request is
        then counted against the partner's budgets instead of the per-address
        limit. It grants no access on its own. An unknown, malformed, or revoked
        partner key returns `401` with code `invalid_partner_key`. The header is
        ignored on the sandbox host and on requests without a live trader key.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.