API Endpoints

Endpoints de Estratégia do AlgoServer

Esta seção documenta os endpoints da API REST do AlgoServer para gerenciamento de estratégias. Toda comunicação usa JSON sobre HTTP com autenticação Basic.

Base path: api/strategy

Mapeamento rápido

  • Criar ou atualizar estratégia: POST /api/strategy/{strategyType}
  • Cálculo de duração: POST /api/strategy/duration/{strategyType}
  • Ordem manual: POST /api/strategy
  • Consultas: GET /api/strategy/all, GET /api/strategy/{id}
  • Iniciar e parar: POST /api/strategy/start/{id}, POST /api/strategy/stop/{id}
  • Cancelamento: DELETE /api/strategy/{id}, DELETE /api/strategy/all
  • Trades executados: GET /api/strategy/trades/all, GET /api/strategy/trades/{id}
  • Ordens abertas: GET /api/strategy/openOrders

Endpoints detalhados

1) Criar ou atualizar estratégia

POST /api/strategy/{strategyType}

  • Path param
    • strategyType (1..9)
  • Body
    • Strategy request (ver seção Estratégias Disponíveis)
  • Responses
    • 200 OK: sem body
    • 400 BadRequest: erro de parse ou validação
    • 401 Unauthorized
    • 500 InternalServerError (inclui emergency mode)
    • 503 ServiceUnavailable

2) Cálculo de duração

POST /api/strategy/duration/{strategyType}

  • Path param
    • strategyType (1..9), apenas tipos que suportam cálculo de duração
  • Body
    • DurationRequest
      • symbols: string[]
      • referenceSymbol: string
      • referenceQuantity: number
  • Responses
    • 200 OK: double[] (quantidades calculadas)
    • 400 BadRequest: tipo sem suporte ou request inválido
    • 500 InternalServerError
    • 503 ServiceUnavailable

3) Ordem manual

POST /api/strategy

  • Body
    • ManualOrderRequest (ver seção Estratégias Disponíveis)
  • Responses
    • 200 OK: sem body
    • 400 BadRequest
    • 401 Unauthorized
    • 500 InternalServerError
    • 503 ServiceUnavailable

4) Consultas de estratégia

Listar todas

GET /api/strategy/all

  • Responses
    • 200 OK: ImmutableStrategyInfo[]
    • 401 Unauthorized
    • 500 InternalServerError
    • 503 ServiceUnavailable

Buscar por id

GET /api/strategy/{id}

  • Path param
    • id: int
  • Responses
    • 200 OK: ImmutableStrategyInfo
    • 401 Unauthorized
    • 404 NotFound
    • 500 InternalServerError
    • 503 ServiceUnavailable

5) Iniciar e parar estratégia

Iniciar

POST /api/strategy/start/{id}

  • Path param
    • id: int
  • Responses
    • 200 OK: ImmutableStrategyInfo
    • 401 Unauthorized
    • 404 NotFound
    • 500 InternalServerError (inclui emergency mode)
    • 503 ServiceUnavailable

Parar

POST /api/strategy/stop/{id}

  • Path param
    • id: int
  • Responses
    • 200 OK: ImmutableStrategyInfo
    • 401 Unauthorized
    • 404 NotFound
    • 500 InternalServerError
    • 503 ServiceUnavailable
    • 504 GatewayTimeout

6) Cancelamento

Cancelar por id

DELETE /api/strategy/{id}

  • Path param
    • id: int
  • Responses
    • 200 OK: ImmutableStrategyInfo
    • 401 Unauthorized
    • 404 NotFound
    • 500 InternalServerError
    • 503 ServiceUnavailable
    • 504 GatewayTimeout

Cancelar todas

DELETE /api/strategy/all

  • Responses
    • 200 OK: ImmutableStrategyInfo[]
    • 401 Unauthorized
    • 500 InternalServerError
    • 503 ServiceUnavailable
    • 504 GatewayTimeout

7) Trades executados

Todas as estratégias

GET /api/strategy/trades/all

  • Responses
    • 200 OK: IEnumerable<Dictionary<string, ImmutableInstrumentTrades>>
    • 401 Unauthorized
    • 500 InternalServerError
    • 503 ServiceUnavailable

Por estratégia

GET /api/strategy/trades/{id}

  • Path param
    • id: int
  • Responses
    • 200 OK: Dictionary<string, ImmutableInstrumentTrades>
    • 401 Unauthorized
    • 404 NotFound
    • 500 InternalServerError
    • 503 ServiceUnavailable

8) Ordens abertas

GET /api/strategy/openOrders

  • Responses
    • 200 OK: OpenOrder[]
    • 401 Unauthorized
    • 500 InternalServerError
    • 503 ServiceUnavailable

Tipos de response

Os endpoints retornam os seguintes tipos principais:

  • ImmutableStrategyInfo: representação completa de uma estratégia, incluindo o request original (request), alterações numéricas (numberChanges) e alterações de texto (textChanges).
  • ImmutableInstrumentTrades: trades executados por instrumento, com totais gerais (total), totais de EDS (edsTotal), detalhamento por nível (levels) e níveis de EDS (edsLevels).
  • OpenOrder: ordem aberta no book, com campos de identificação (id, sessionId, symbol, user, strategyId) e estado atual (confirmedQuantity, confirmedPrice, pendingQuantity, pendingPrice).