openapi: 3.0.3
info:
  title: Trading Partner API
  description: This document defines the RESTful endpoints forTrading Partner API
  version: 1.0.0


tags:
  - name: public
    description: All sessionless routes
  - name: protected
    description: All routes accessible only with session token
  - name: user
    description: All user routes
  - name: alert
    description: All alert routes
  - name: paid
    description: only accessible with paid subscription
servers:
  - url: 'http://127.0.0.1:{port}{basePath}'
    description: "Local API server"
    variables:
      port:
        enum:
          - '11000'
        default: '11000'
      basePath:
        enum:
          - ''
        default: ''

paths:
  /api/v1/statistics:
    get:
      tags:
        - public
      summary: "Get statistics from last 24H"
      responses:
        "200":
          $ref: "#/components/responses/statisticsResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"

  /api/v1/users/subscription:
    patch:
      tags:
        - protected
        - user
      summary: "update user subscription"
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/subscriptionRequest"
      responses:
        "204":
          description: "The subscription was successfully updated"
        "400":
          $ref: "#/components/responses/badRequestResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "403":
          $ref: "#/components/responses/forbiddenResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
    get:
      tags:
        - protected
        - user
      summary: "User subscription"
      security:
        - bearerAuth: []
      responses:
        "200":
          $ref: "#/components/responses/userSubscriptionResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "403":
          $ref: "#/components/responses/forbiddenResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
  /api/v1/users/info:
    get:
      tags:
        - protected
        - user
      summary: "User information"
      security:
        - bearerAuth: []
      responses:
        "200":
          $ref: "#/components/responses/userInformationResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
    put:
      tags:
        - protected
        - user
      summary: "Update user information"
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/userInformation"
      responses:
        "204":
          description: OK Update
        "400":
          $ref: "#/components/responses/badRequestResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "409":
          $ref: "#/components/responses/conflictResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
  /api/v1/users/preferences:
    get:
      tags:
        - protected
        - user
      summary: "User preferences"
      security:
        - bearerAuth: []
      responses:
        "200":
          $ref: "#/components/responses/userPreferencesResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
    put:
      tags:
        - protected
        - user
      summary: "Update user preferences"
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/userPreferences"
      responses:
        "204":
          description: OK Update
        "400":
          $ref: "#/components/responses/badRequestResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
  /api/v1/users/cards:
    get:
      tags:
        - protected
        - user
      summary: "Get user cards"
      security:
        - bearerAuth: [ ]
      responses:
        "200":
          $ref: "#/components/responses/userCardsResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
  /api/v1/users/cards/{cardId}:
    patch:
      tags:
        - protected
        - user
      summary: "Patch user card"
      security:
        - bearerAuth: [ ]
      parameters:
        - name: cardId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/userCardPatchRequest"
      responses:
        "200":
          $ref: "#/components/responses/userCardResponse"
        "400":
          $ref: "#/components/responses/badRequestResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
    delete:
      tags:
        - protected
        - user
      summary: "Delete user card"
      security:
        - bearerAuth: [ ]
      parameters:
        - name: cardId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: "No Content"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"

  /api/v1/users/login:
    post:
      tags:
        - public
        - user
      summary: "user login"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/userLoginRequest"
      responses:
        "200":
          $ref: "#/components/responses/userLoginResponse"
        "400":
          $ref: "#/components/responses/badRequestResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "403":
          $ref: "#/components/responses/forbiddenResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"

  /api/v1/alerts:
    get:
      tags:
        - protected
        - alert
        - paid
      summary: "Get alerts stream"
      description: |
        Establishes an SSE connection to receive alerts based on user preferences.
      security:
        - bearerAuth: []
      responses:
        "200":
          $ref: "#/components/responses/alertsStreamResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "402":
          $ref: "#/components/responses/paymentRequiredResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
  /api/v1/alerts/closed:
    get:
      tags:
        - protected
        - alert
      summary: "get closed alerts"
      description: |
        Only the alerts from the last 15 minutes are returned.
        Free users only get the closure of winning alerts.
        Free users can only request this API every 15mn.
      security:
        - bearerAuth: []
      responses:
        "200":
          $ref: "#/components/responses/closedAlertsResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "429":
          $ref: "#/components/responses/tooManyRequestsResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
  /api/v1/alerts/statistics:
    get:
      tags:
        - protected
        - alert
      summary: "Get user alerts statistics"
      security:
        - bearerAuth: []
      parameters:
        - name: from
          in: query
          required: false
          schema:
            type: string
            format: date
        - name: to
          in: query
          required: false
          schema:
            type: string
            format: date
      responses:
        "200":
          $ref: "#/components/responses/statisticsResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"
  /api/v1/alerts/history:
    get:
      tags:
        - protected
        - alert
      summary: "Get alerts history"
      security:
        - bearerAuth: []
      parameters:
        - name: page
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: size
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            default: 10
        - name: from
          in: query
          required: false
          schema:
            type: string
            format: date
        - name: to
          in: query
          required: false
          schema:
            type: string
            format: date
        - name: ticker
          in: query
          required: false
          schema:
            type: string
        - name: instrument
          in: query
          required: false
          schema:
            type: string
            enum:
              - "CRYPTOCURRENCIES"
              - "FOREX"
              - "INDICES"
              - "COMMODITIES"
              - "FUTURES"
              - "STOCKS"
        - name: status
          in: query
          required: false
          schema:
            type: string
            enum:
              - "ONMARK"
              - "ONGOING"
              - "WON"
              - "LOST"
              - "ABORTED"
        - name: orderBy
          in: query
          required: false
          schema:
            type: string
            enum:
              - "ticker"
              - "instrument"
              - "figureTime"
              - "gain"
              - "status"
              - "closedAt"
              - "startedAt"
              - "accessDate"
            default: accessDate
        - name: orderDirection
          in: query
          required: false
          schema:
            type: string
            enum:
              - "asc"
              - "desc"
            default: desc
      responses:
        "200":
          $ref: "#/components/responses/alertsHistoryResponse"
        "400":
          $ref: "#/components/responses/badRequestResponse"
        "401":
          $ref: "#/components/responses/unauthorizedResponse"
        "404":
          $ref: "#/components/responses/notFoundResponse"
        "500":
          $ref: "#/components/responses/internalErrorResponse"

components:
  schemas:
    subscriptionRequest:
      type: object
      required:
        - automaticRenewal
      properties:
        automaticRenewal:
          type: boolean
          description: "Automatic renewal enabled"
    userSubscription:
      type: object
      required:
        - subscription
        - balance
        - automaticRenewal
      properties:
        subscription:
          type: string
          description: "Subscription type"
          enum:
            - FREE
            - FULL
        balance:
          type: integer
          format: uint64
          description: "Balance"
          minimum: 0
        automaticRenewal:
          type: boolean
          description: "Automatic renewal"
    userInformation:
      type: object
      required:
        - name
        - sector
        - address
        - zipCode
        - city
        - country
        - contact
      properties:
        name:
          type: string
          description: "Name of the company"
          minLength: 1
          maxLength: 255
        website:
          type: string
          description: "Website of the company"
          maxLength: 255
          format: uri
        sector:
          type: string
          description: "Sector of the company"
          enum:
            - Administration - civil service
            - Food industry
            - Arts and crafts
            - Associations
            - Banking - insurance - financial services
            - Wood/Paper/Cardboard/Printing
            - Public works/construction materials
            - Chemicals - plastics - packaging
            - Chemicals/Pharmaceuticals
            - Retail - mass distribution
            - Commerce/Trading/Distribution
            - Communication - marketing - information
            - Construction - building - public works
            - Culture - sports - leisure
            - Publishing/Communications/Multimedia
            - Electronics/Electricity
            - Energy
            - Education - training
            - Environment - recovery - recycling - water treatment
            - Equipment - materials for professional activities
            - Studies and consultancy
            - Manufacturing - wholesale of articles for sale
            - Management - business administration
            - Hotels - catering - tourism
            - Real estate
            - Textile industry
            - Information technology
            - IT/Telecoms
            - Design and research engineers - researchers
            - Logistics - transport
            - Machinery and equipment Automotive
            - Electrical - electronic - optical equipment
            - Mechanics - metallurgy
            - Metallurgy/Metal working
            - Ores - minerals - iron and steel
            - Legal professions
            - Health - social work
            - Business services
            - Services to individuals - communities - companies
            - Textiles/Clothing/Footwear
            - Transport/Logistics
        address:
          type: string
          description: "Address of the company"
          minLength: 1
          maxLength: 255
        zipCode:
          type: string
          description: "ZipCode of the company"
          minLength: 1
          maxLength: 10
        city:
          type: string
          description: "City of the company"
          minLength: 1
          maxLength: 255
        country:
          type: string
          description: "Country of the company"
          enum:
            - Afghanistan
            - Albania
            - Algeria
            - American Samoa
            - Andorra
            - Angola
            - Anguilla
            - Antigua and Barbuda
            - Argentina
            - Armenia
            - Aruba
            - Australia
            - Austria
            - Azerbaijan
            - Bahamas
            - Bahrain
            - Bangladesh
            - Barbados
            - Belarus
            - Belgium
            - Belize
            - Benin
            - Bermuda
            - Bhutan
            - Bolivia, Plurinational State of
            - Bosnia and Herzegovina
            - Botswana
            - Brazil
            - British Indian Ocean Territory
            - Brunei Darussalam
            - Bulgaria
            - Burkina Faso
            - Burundi
            - Cambodia
            - Cameroon
            - Canada
            - Cape Verde
            - Cayman Islands
            - Central African Republic
            - Chad
            - Chile
            - China
            - Christmas Island
            - Cocos (Keeling) Islands
            - Colombia
            - Comoros
            - Congo
            - Congo, The Democratic Republic of the
            - Cook Islands
            - Costa Rica
            - Croatia
            - Cuba
            - Cyprus
            - Czech Republic
            - Denmark
            - Djibouti
            - Dominica
            - Dominican Republic
            - Ecuador
            - Egypt
            - El Salvador
            - Equatorial Guinea
            - Eritrea
            - Estonia
            - Ethiopia
            - Falkland Islands (Malvinas)
            - Faroe Islands
            - Fiji
            - Finland
            - France
            - French Guiana
            - French Polynesia
            - Gabon
            - Gambia
            - Georgia
            - Germany
            - Ghana
            - Gibraltar
            - Greece
            - Greenland
            - Grenada
            - Guadeloupe
            - Guam
            - Guatemala
            - Guinea
            - Guinea-Bissau
            - Guyana
            - Haiti
            - Holy See (Vatican City State)
            - Honduras
            - Hong Kong
            - Hungary
            - Iceland
            - India
            - Indonesia
            - Iran
            - Iraq
            - Ireland
            - Isle of Man
            - Israel
            - Italy
            - Jamaica
            - Japan
            - Jersey
            - Jordan
            - Kazakhstan
            - Kenya
            - Kiribati
            - Korea, Democratic People's Republic of
            - Korea, Republic of
            - Kuwait
            - Kyrgyzstan
            - Lao People's Democratic Republic
            - Latvia
            - Lebanon
            - Lesotho
            - Liberia
            - Libyan Arab Jamahiriya
            - Liechtenstein
            - Lithuania
            - Luxembourg
            - Macao
            - Macedonia, The Former Yugoslav Republic of
            - Madagascar
            - Malawi
            - Malaysia
            - Maldives
            - Mali
            - Malta
            - Marshall Islands
            - Martinique
            - Mauritania
            - Mauritius
            - Mayotte
            - Mexico
            - Micronesia, Federated States of
            - Moldova, Republic of
            - Monaco
            - Mongolia
            - Montenegro
            - Montserrat
            - Morocco
            - Mozambique
            - Myanmar
            - Namibia
            - Nauru
            - Nepal
            - Netherlands
            - Netherlands Antilles
            - New Caledonia
            - New Zealand
            - Nicaragua
            - Niger
            - Nigeria
            - Niue
            - Norfolk Island
            - Northern Mariana Islands
            - Norway
            - Oman
            - Pakistan
            - Palau
            - Palestine
            - Panama
            - Papua New Guinea
            - Paraguay
            - Peru
            - Philippines
            - Pitcairn
            - Poland
            - Portugal
            - Puerto Rico
            - Qatar
            - Réunion
            - Romania
            - Russia
            - Rwanda
            - Saint Barthélemy
            - Saint Helena, Ascension and Tristan Da Cunha
            - Saint Kitts and Nevis
            - Saint Lucia
            - Saint Martin
            - Saint Pierre and Miquelon
            - Saint Vincent and the Grenadines
            - Samoa
            - San Marino
            - São Tomé and Príncipe
            - Sark Island
            - Saudi Arabia
            - Senegal
            - Serbia
            - Seychelles
            - Sierra Leone
            - Singapore
            - Slovakia
            - Slovenia
            - Solomon Islands
            - Somalia
            - South Africa
            - South Georgia and the South Sandwich Islands
            - South Korea
            - Spain
            - Sri Lanka
            - Sudan
            - Suriname
            - Svalbard and Jan Mayen
            - Swaziland
            - Sweden
            - Switzerland
            - Syrian Arab Republic
            - Taiwan, Province of China
            - Tajikistan
            - Tanzania, United Republic of
            - Thailand
            - Timor-Leste
            - Togo
            - Tokelau
            - Tonga
            - Trinidad and Tobago
            - Tunisia
            - Turkey
            - Turkmenistan
            - Turks and Caicos Islands
            - Tuvalu
            - Uganda
            - Ukraine
            - United Arab Emirates
            - United Kingdom
            - United States
            - Uruguay
            - Uzbekistan
            - Vanuatu
            - Venezuela, Bolivarian Republic of
            - Viet Nam
            - Wallis and Futuna
            - Yemen
            - Zambia
            - Zimbabwe
        contact:
          $ref: "#/components/schemas/contact"
    userPreferences:
      type: object
      required:
        - longTermStrategy
        - shortTermStrategy
        - cryptocurrencies
        - forex
        - indices
        - commodities
        - futures
        - stocks
      properties:
        longTermStrategy:
          type: boolean
          description: "user shall receive long term strategies"
        shortTermStrategy:
          type: boolean
          description: "user shall receive short term strategies"
        cryptocurrencies:
          type: boolean
          description: "user shall receive cryptocurrencies"
        forex:
          type: boolean
          description: "user shall receive forex"
        indices:
          type: boolean
          description: "user shall receive indices"
        commodities:
          type: boolean
          description: "user shall receive commodities"
        futures:
          type: boolean
          description: "user shall receive futures"
        stocks:
          type: boolean
          description: "user shall receive stocks"
    userCard:
      type: object
      required: [ id, isDefault, isValid, dsCardNumber, dsExpiryDate, dsCardBrand, issuedAt ]
      properties:
        id:
          type: string
          format: uuid
        isDefault:
          type: boolean
        isValid:
          type: boolean
        dsCardNumber:
          type: string
        dsExpiryDate:
          type: string
        dsCardBrand:
          type: string
        issuedAt:
          type: string
          format: date-time
    userCards:
      type: array
      items:
        $ref: "#/components/schemas/userCard"
    userCardPatchRequest:
      type: object
      required: [ isDefault ]
      properties:
        isDefault:
          type: boolean
    userLoginRequest:
      type: object
      required:
        - email
        - password
      properties:
        email:
          type: string
          format: email
          description: "email of the company contact"
          minLength: 1
          maxLength: 255
        password:
          type: string
          description: "Password of the company"
          minLength: 1
          maxLength: 30
    closedAlerts:
      type: array
      items:
        $ref: "#/components/schemas/closedAlert"
    closedAlert:
      type: object
      required:
        - id
        - ticker
        - instrument
        - durationStrategy
        - direction
        - start
        - target
        - stop
        - exit
        - gain
        - status
        - startedAt
        - closedAt
      properties:
        id:
          type: integer
          format: int64
          description: "ID of the alert"
        ticker:
          type: string
          description: "Ticker of the asset"
          minLength: 1
        instrument:
          type: string
          description: "Instrument of the asset"
          enum:
            - "CRYPTOCURRENCIES"
            - "FOREX"
            - "INDICES"
            - "COMMODITIES"
            - "FUTURES"
            - "STOCKS"
        durationStrategy:
          type: string
          description: "Duration of the strategy"
          enum:
            - "short"
            - "long"
        direction:
          type: string
          description: "Direction of the strategy"
          enum:
            - "BUY"
            - "SELL"
        start:
          type: number
          format: float
          description: "Start of the strategy"
        target:
          type: number
          format: float
          description: "Target of the strategy"
        stop:
          type: number
          format: float
          description: "Stop of the strategy"
        exit:
          type: number
          description: "Exit of the strategy"
        gain:
          type: number
          description: "Gain of the strategy"
        status:
          type: string
          description: "Status of the strategy"
          enum:
            - "WON"
            - "LOST"
            - "ABORTED"
        startedAt:
          type: string
          description: "Start date of the strategy"
          format: date-time
        closedAt:
          type: string
          description: "Close date of the strategy"
          format: date-time
    alertsHistory:
      type: object
      required:
        - total
        - page
        - size
        - data
      properties:
        total:
          type: integer
          description: "Total number of alerts"
        page:
          type: integer
          description: "Current page"
        size:
          type: integer
          description: "Page size"
        data:
          type: array
          items:
            $ref: "#/components/schemas/alertHistory"
    alertHistory:
      oneOf:
        - $ref: "#/components/schemas/alertHistoryStart"
        - $ref: "#/components/schemas/alertHistoryAll"
      discriminator:
        propertyName: ticker
    alertHistoryStart:
      type: object
      required:
        - id
        - ticker
        - instrument
        - durationStrategy
        - direction
        - start
        - target
        - stop
        - status
        - startedAt
        - accessDate
      properties:
        id:
          type: integer
          format: int64
          description: "ID of the alert"
        ticker:
          type: string
          description: "Ticker of the asset"
          minLength: 1
        instrument:
          type: string
          description: "Instrument of the asset"
          enum:
            - "CRYPTOCURRENCIES"
            - "FOREX"
            - "INDICES"
            - "COMMODITIES"
            - "FUTURES"
            - "STOCKS"
        durationStrategy:
          type: string
          description: "Duration of the strategy"
          enum:
            - "short"
            - "long"
        direction:
          type: string
          description: "Direction of the strategy"
          enum:
            - "BUY"
            - "SELL"
        start:
          type: number
          format: float
          description: "Start of the strategy"
        target:
          type: number
          format: float
          description: "Target of the strategy"
        stop:
          type: number
          format: float
          description: "Stop of the strategy"
        startedAt:
          type: string
          description: "Start date of the strategy"
          format: date-time
        accessDate:
          type: string
          description: "Date of user's access to the strategy"
          format: date-time
    alertHistoryClosure:
      type: object
      required:
        - id
        - ticker
        - instrument
        - durationStrategy
        - direction
        - exit
        - gain
        - status
        - closedAt
        - accessDate
      properties:
        id:
          type: integer
          format: int64
          description: "ID of the alert"
        ticker:
          type: string
          description: "Ticker of the asset"
          minLength: 1
        instrument:
          type: string
          description: "Instrument of the asset"
          enum:
            - "CRYPTOCURRENCIES"
            - "FOREX"
            - "INDICES"
            - "COMMODITIES"
            - "FUTURES"
            - "STOCKS"
        durationStrategy:
          type: string
          description: "Duration of the strategy"
          enum:
            - "short"
            - "long"
        direction:
          type: string
          description: "Direction of the strategy"
          enum:
            - "BUY"
            - "SELL"
        exit:
          type: number
          format: float
          description: "Exit of the strategy"
        gain:
          type: number
          format: float
          description: "Gain of the strategy"
        status:
          type: string
          description: "Status of the strategy"
          enum:
            - "WON"
            - "LOST"
            - "ABORTED"
        closedAt:
          type: string
          description: "Close date of the strategy"
          format: date-time
        accessDate:
          type: string
          description: "Date of user's access to the strategy"
          format: date-time
    alertHistoryAll:
      allOf:
        - $ref: "#/components/schemas/alertHistoryStart"
        - $ref: "#/components/schemas/alertHistoryClosure"
    alertEvent:
      type: object
      oneOf:
        - $ref: "#/components/schemas/alertEventOnMark"
        - $ref: "#/components/schemas/alertEventStart"
        - $ref: "#/components/schemas/alertEventAbort"
        - $ref: "#/components/schemas/alertEventClosure"
      discriminator:
        propertyName: id
    alertEventOnMark:
      type: object
      required:
        - id
        - token
        - ticker
        - instrument
        - durationStrategy
        - startedAt
        - start
        - target
        - stop
      properties:
        id:
          type: integer
          format: int64
          description: "ID of the alert"
        token:
          description: "token reserved for the alert"
          type: string
          format: uuid
        ticker:
          type: string
          description: "Ticker of the asset"
        instrument:
          type: string
          description: "Instrument of the asset"
          enum:
            - "CRYPTOCURRENCIES"
            - "FOREX"
            - "INDICES"
            - "COMMODITIES"
            - "FUTURES"
            - "STOCKS"
        durationStrategy:
          type: string
          description: "Duration of the strategy"
          enum:
            - "short"
            - "long"
        startedAt:
          type: string
          description: "Start date of the strategy"
          format: date-time
        start:
          type: number
          format: float
          description: "Start of the strategy"
        target:
          type: number
          format: float
          description: "Target of the strategy"
        stop:
          type: number
          format: float
          description: "Stop of the strategy"
    alertEventAbort:
      type: object
      required:
        - id
        - token
        - tokenState
      properties:
        id:
          type: integer
          format: int64
          description: "ID of the alert"
        token:
          description: "Consumed token for the alert"
          type: string
          format: uuid
        tokenState:
          type: string
          description: "State of the token"
          enum:
            - REIMBURSED
    alertEventStart:
      type: object
      required:
        - id
        - token
      properties:
        id:
          type: integer
          format: int64
          description: "ID of the alert"
        token:
          description: "token reserved for the alert"
          type: string
          format: uuid
    alertEventClosure:
      type: object
      required:
        - id
        - token
        - tokenState
        - exit
        - gain
        - closedAt
      properties:
        id:
          type: integer
          format: int64
          description: "ID of the alert"
        token:
          description: "Consumed token for the alert"
          type: string
          format: uuid
        tokenState:
          type: string
          description: "State of the token"
          enum:
            - CONSUMED
            - REIMBURSED
        exit:
          type: number
          format: float
          description: "Exit of the strategy"
        gain:
          type: number
          format: float
          description: "Gain of the strategy"
        closedAt:
          type: string
          description: "Close date of the strategy"
          format: date-time
    unitStats:
      type: object
      required:
        - total
        - won
        - lost
        - aborted
      properties:
        total:
          type: integer
          format: int64
          description: "Total number of alerts"
        won:
          type: integer
          format: int64
          description: "Total number of alerts won"
        lost:
          type: integer
          format: int64
          description: "Total number of alerts lost"
        aborted:
          type: integer
          format: int64
          description: "Total number of alerts aborted"
    statistics:
      type: "object"
      required:
        - forex
        - crypto
        - futures
        - stocks
        - indices
        - commodities
      properties:
        forex:
          $ref: "#/components/schemas/unitStats"
        crypto:
          $ref: "#/components/schemas/unitStats"
        futures:
          $ref: "#/components/schemas/unitStats"
        stocks:
          $ref: "#/components/schemas/unitStats"
        indices:
          $ref: "#/components/schemas/unitStats"
        commodities:
          $ref: "#/components/schemas/unitStats"
    contact:
      type: object
      required:
        - name
        - surname
        - email
        - phone
      properties:
        name:
          type: string
          description: "Name of the contact"
          minLength: 1
        surname:
          type: string
          description: "Surname of the contact"
          minLength: 1
          maxLength: 255
        email:
          type: string
          description: "Email of the contact"
          minLength: 1
          maxLength: 320
          format: email
        phone:
          type: string
          description: "Phone of the contact"
          minLength: 1
          maxLength: 15
    error:
      type: object
      required:
        - errorCode
        - message
        - description
      properties:
        errorCode:
          type: integer
        message:
          type: string
        description:
          type: string
    userAccessToken:
      type: object
      required:
        - accessToken
        - tokenType
        - expiresIn
      properties:
        accessToken:
          description: access-token to join for authenticated request
          type: string
          maxLength: 4096
        tokenType:
          description: access-token type
          type: string
        expiresIn:
          description: access-token duration
          type: number
          format: float64
        lastLogin:
          description: last login date
          type: string
          format: date-time
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
  responses:
    badRequestResponse:
      description: "Bad request"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/error"
          examples:
            INVALID_BODY:
              value:
                errorCode: 20
                message: Invalid body
            MISSING_BODY_FIELD:
              value:
                errorCode: 21
                message: Missing body field
                description: x is missing
            INVALID_BODY_FIELD:
              value:
                errorCode: 22
                message: Invalid body field
                description: x is invalid
            MISSING_PATH_PARAM:
              value:
                errorCode: 23
                message: missing path param
                description: x is missing
            INVALID_PATH_PARAM:
              value:
                errorCode: 24
                message: Invalid path param
                description: x is invalid
    unauthorizedResponse:
      description: "Unauthorized"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/error"
          examples:
            MISSING_AUTHORIZATION:
              value:
                errorCode: 10
                message: missing authorization header
                description: missing authorization header
            INVALID_AUTHORIZATION:
              value:
                errorCode: 11
                message: invalid authorization header
                description: invalid authorization header
            SESSION_EXPIRED:
              value:
                errorCode: 12
                message: session expired
                description: session expired
            WRONG_CREDENTIAL:
              value:
                errorCode: 13
                message: invalid email/password combination
                description: invalid email/password combination
    paymentRequiredResponse:
      description: "Payment required"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/error"
          examples:
            NOT_ENOUGH_CREDIT:
              value:
                errorCode: 30
                message: Not enough credit
                description: not enough credit
    forbiddenResponse:
      description: "Forbidden"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/error"
          examples:
            USER_NOT_ACTIVE:
              value:
                errorCode: 32
                message: User not active
                description: user account is not active
    conflictResponse:
      description: "Conflict"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/error"
          examples:
            USER_ALREADY_EXISTS:
              value:
                errorCode: 30
                message: User already exists
                description: email already used
            USER_ALREADY_ACTIVE:
              value:
                errorCode: 31
                message: User already active
                description: user already activated
    notFoundResponse:
      description: "Not found"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/error"
          examples:
            USER_NOT_FOUND:
              value:
                errorCode: 40
                message: User not found
                description: user not found
            TOKEN_NOT_FOUND:
              value:
                errorCode: 41
                message: Token not found
                description: token not found
    tooManyRequestsResponse:
      description: "Too many requests"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/error"
          examples:
            ONE_REQUEST_PER_15MN:
              value:
                errorCode: 50
                message: Only one request per 15mn is allowed
                description: only one request per 15mn is allowed
    internalErrorResponse:
      description: "Internal error"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/error"
          examples:
            INTERNAL_ERROR:
              value:
                errorCode: 99
                message: Internal error
                description: internal error
    statisticsResponse:
      description: Represents the response body of statistics endpoints
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/statistics"
    userLoginResponse:
      description: Represents the response body of user login endpoint
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/userAccessToken"
    userInformationResponse:
      description: Represents the response body of user information endpoint
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/userInformation"
    userPreferencesResponse:
      description: Represents the response body of user preferences endpoint
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/userPreferences"

    userCardResponse:
      description: Represent the response body ... of user card endpoint
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/userCard"
    userCardsResponse:
      description: Represents the response body ... of user cards endpoint
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/userCards"
    closedAlertsResponse:
      description: Represents the response body of user GET alerts closures endpoint
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/closedAlerts"
    alertsHistoryResponse:
      description: Represents the response body of user GET alerts history endpoint
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/alertsHistory"
    alertsStreamResponse:
      description: Alerts event stream
      content:
        text/event-stream:
          schema:
            $ref: "#/components/schemas/alertEvent"
    userSubscriptionResponse:
      description: Represents the response body of user subscription endpoint
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/userSubscription"

