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

# Get historical deals

> Returns executed deals (fills) in a Unix epoch time range via `mt5.history_deals_get()`. Each position generates two deals: one on open (entry=0) and one on close (entry=1). The closing deal's `profit` field is stored raw in Supabase (USC for cent accounts — not converted to USD).



## OpenAPI

````yaml https://terminal-api.novosky.tech/roboforex/main/openapi.json get /history/deals
openapi: 3.0.3
info:
  description: >-
    Self-hosted HTTP REST API bridging the NOVOSKY trading bot to a MetaTrader 5
    terminal. All bot-to-broker communication goes through this service.
    Authentication is required on all endpoints except `GET /ping`.
  title: MT5 HEADLESS
  version: 1.0.0
servers:
  - url: /
security:
  - bearerAuth: []
tags:
  - description: Health, latency, and error diagnostics
    name: System
  - description: MT5 terminal lifecycle and server time
    name: Terminal
  - description: Broker server time and UTC offset detection
    name: Time
  - description: Live balance, equity, and margin
    name: Account
  - description: Symbol specs, ticks, and OHLCV rates
    name: Symbols
  - description: Open position management
    name: Positions
  - description: Pending order placement and management
    name: Orders
  - description: Closed deals and historical orders
    name: History
paths:
  /history/deals:
    get:
      tags:
        - History
      summary: Get historical deals
      description: >-
        Returns executed deals (fills) in a Unix epoch time range via
        `mt5.history_deals_get()`. Each position generates two deals: one on
        open (entry=0) and one on close (entry=1). The closing deal's `profit`
        field is stored raw in Supabase (USC for cent accounts — not converted
        to USD).
      operationId: get_history_deals
      parameters:
        - description: Start of range as Unix epoch
          in: query
          name: from
          required: true
          schema:
            example: 1777800000
            type: integer
        - description: End of range as Unix epoch
          in: query
          name: to
          required: true
          schema:
            example: 1777900000
            type: integer
        - description: Filter by symbol (optional)
          in: query
          name: symbol
          required: false
          schema:
            example: BTCUSD
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                items:
                  $ref: '#/components/schemas/DealResponse'
                type: array
          description: Historical deals
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Missing or invalid from/to parameters
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Missing or invalid Bearer token
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: MT5 not initialized
components:
  schemas:
    DealResponse:
      additionalProperties: true
      description: A closed deal from trade history.
      properties:
        comment:
          example: novosky
          type: string
        commission:
          example: -0.05
          type: number
        entry:
          description: 0=entry (open), 1=exit (close), 2=reversal.
          example: 1
          type: integer
        magic:
          example: 20250101
          type: integer
        order:
          description: Linked order ticket.
          example: 123456789
          type: integer
        position_id:
          example: 123456789
          type: integer
        price:
          example: 95200
          type: number
        profit:
          description: >-
            Profit in raw account currency (USC for cent accounts — NOT
            converted to USD).
          example: 200
          type: number
        swap:
          example: -0.12
          type: number
        symbol:
          example: BTCUSD
          type: string
        ticket:
          example: 111111111
          type: integer
        time:
          description: Deal execution time as Unix epoch.
          example: 1777879100
          type: integer
        type:
          description: 0=BUY, 1=SELL, 2=BALANCE, 3=CREDIT.
          example: 1
          type: integer
        volume:
          example: 0.01
          type: number
      type: object
    ErrorResponse:
      additionalProperties: true
      description: MT5 error payload returned on non-2xx responses.
      properties:
        message:
          example: Invalid stops
          type: string
        retcode:
          description: MT5 error code (e.g. 10014 = invalid stops, 10018 = market closed).
          example: 10014
          type: integer
      type: object
  securitySchemes:
    bearerAuth:
      description: Set `API_TOKEN` in `.env` to match the token configured on the server.
      scheme: bearer
      type: http

````