level2 Strategies API
Endpoints for managing user trading strategies, including creation, retrieval, updating, deployment, and deletion of automated trading strategies built with the Level2 visual strategy builder.
Endpoints for managing user trading strategies, including creation, retrieval, updating, deployment, and deletion of automated trading strategies built with the Level2 visual strategy builder.
openapi: 3.1.0
info:
title: Level2 Strategy Builder Backtesting Strategies API
description: The Level2 Strategy Builder API provides programmatic access to market data, technical analysis, and trading strategy capabilities offered by the Level2 platform (by Bytemine Technologies Ltd.). It includes endpoints for retrieving candlestick pattern detection, ticker trend analysis, historical OHLC (Open-High-Low-Close) data, similar stock discovery, and company fundamental summaries. These endpoints power the Level2 visual no-code strategy builder used by over 50,000 traders to create, backtest, and deploy automated trading strategies without writing code.
version: 1.0.0
contact:
name: Level2 Support
url: https://www.trylevel2.com
termsOfService: https://www.trylevel2.com/terms-and-conditions
servers:
- url: https://app.bytemine.io/api
description: Primary API Server
- url: https://valhalla.bytemine.workers.dev
description: Market Data Server
security:
- apiKeyPath: []
tags:
- name: Strategies
description: Endpoints for managing user trading strategies, including creation, retrieval, updating, deployment, and deletion of automated trading strategies built with the Level2 visual strategy builder.
paths:
/broker/users/{userId}/strategies:
get:
operationId: listUserStrategies
summary: List user strategies
description: Retrieves all trading strategies associated with the specified broker user. Returns both active and inactive strategies created through the Level2 visual strategy builder.
tags:
- Strategies
parameters:
- $ref: '#/components/parameters/userId'
- name: status
in: query
required: false
description: Filter strategies by their current status.
schema:
type: string
enum:
- active
- inactive
- deployed
- draft
- name: limit
in: query
required: false
description: Maximum number of strategies to return per page.
schema:
type: integer
minimum: 1
maximum: 100
default: 25
- name: offset
in: query
required: false
description: Number of strategies to skip for pagination.
schema:
type: integer
minimum: 0
default: 0
responses:
'200':
description: Strategies retrieved successfully
content:
application/json:
schema:
$ref: '#/components/schemas/StrategyListResponse'
'401':
description: Unauthorized - invalid or missing bearer token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: User not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
operationId: createUserStrategy
summary: Create a user strategy
description: Creates a new trading strategy for the specified broker user. The strategy is initialized in draft status and can be configured with trading rules, conditions, and parameters using the strategy definition format from the Level2 visual builder.
tags:
- Strategies
parameters:
- $ref: '#/components/parameters/userId'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateStrategyRequest'
responses:
'201':
description: Strategy created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/StrategyResponse'
'400':
description: Invalid strategy definition
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized - invalid or missing bearer token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: User not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/broker/users/{userId}/strategies/{strategyId}:
get:
operationId: getUserStrategy
summary: Get a user strategy
description: Retrieves the full details of a specific trading strategy including its configuration, status, performance metrics, and deployment state.
tags:
- Strategies
parameters:
- $ref: '#/components/parameters/userId'
- $ref: '#/components/parameters/strategyId'
responses:
'200':
description: Strategy retrieved successfully
content:
application/json:
schema:
$ref: '#/components/schemas/StrategyResponse'
'401':
description: Unauthorized - invalid or missing bearer token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Strategy or user not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
put:
operationId: updateUserStrategy
summary: Update a user strategy
description: Updates an existing trading strategy for the specified user. This endpoint can modify the strategy definition, parameters, and metadata. It can also be used to soft-delete or restore a strategy by updating its status.
tags:
- Strategies
parameters:
- $ref: '#/components/parameters/userId'
- $ref: '#/components/parameters/strategyId'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateStrategyRequest'
responses:
'200':
description: Strategy updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/StrategyResponse'
'400':
description: Invalid strategy definition
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized - invalid or missing bearer token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Strategy or user not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
operationId: deleteUserStrategy
summary: Delete a user strategy
description: Deletes or soft-deletes a user's trading strategy. Once deleted, the strategy is deactivated and any live deployments are stopped. Depending on configuration, the strategy may be recoverable through an update operation.
tags:
- Strategies
parameters:
- $ref: '#/components/parameters/userId'
- $ref: '#/components/parameters/strategyId'
responses:
'200':
description: Strategy deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/StrategyResponse'
'401':
description: Unauthorized - invalid or missing bearer token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Strategy or user not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/broker/users/{userId}/strategies/{strategyId}/deploy:
post:
operationId: deployUserStrategy
summary: Deploy a user strategy
description: Deploys a trading strategy for live execution through the user's connected TradeStation brokerage account. The strategy must be in an active or draft state and have a valid configuration. Once deployed, the strategy will monitor market conditions and execute trades automatically based on its defined rules.
tags:
- Strategies
parameters:
- $ref: '#/components/parameters/userId'
- $ref: '#/components/parameters/strategyId'
requestBody:
required: false
content:
application/json:
schema:
$ref: '#/components/schemas/DeployStrategyRequest'
responses:
'200':
description: Strategy deployed successfully
content:
application/json:
schema:
$ref: '#/components/schemas/StrategyResponse'
'400':
description: Strategy cannot be deployed in its current state
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized - invalid or missing bearer token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Strategy or user not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/broker/users/{userId}/strategies/{strategyId}/stop:
post:
operationId: stopUserStrategy
summary: Stop a deployed strategy
description: Stops a currently deployed trading strategy, halting all automated trade execution. The strategy returns to an active state and can be redeployed later. Any open positions created by the strategy are not automatically closed.
tags:
- Strategies
parameters:
- $ref: '#/components/parameters/userId'
- $ref: '#/components/parameters/strategyId'
responses:
'200':
description: Strategy stopped successfully
content:
application/json:
schema:
$ref: '#/components/schemas/StrategyResponse'
'400':
description: Strategy is not currently deployed
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized - invalid or missing bearer token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Strategy or user not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
components:
schemas:
DeployStrategyRequest:
type: object
description: Optional deployment configuration for a strategy being activated for live trading.
properties:
paperTrading:
type: boolean
description: Whether to deploy in paper trading mode (simulated) rather than live trading. Defaults to false.
default: false
StrategyResponse:
type: object
description: Response containing full strategy details including configuration, status, and performance information.
properties:
id:
type: string
description: The unique strategy identifier
userId:
type: string
description: The owner user identifier
name:
type: string
description: The strategy name
description:
type: string
description: The strategy description
instrument:
type: string
description: The primary instrument ticker symbol
instrumentType:
type: string
description: The instrument type
enum:
- stock
- option
- future
timeframe:
type: string
description: The primary chart timeframe
status:
type: string
description: The current strategy status
enum:
- draft
- active
- deployed
- inactive
definition:
$ref: '#/components/schemas/StrategyDefinition'
createdAt:
type: string
format: date-time
description: Timestamp when the strategy was created
updatedAt:
type: string
format: date-time
description: Timestamp when the strategy was last updated
deployedAt:
type: string
format: date-time
description: Timestamp when the strategy was last deployed
RiskManagement:
type: object
description: Risk management configuration for the strategy including stop loss, take profit, and trailing stop settings.
properties:
stopLoss:
type: number
format: float
description: Stop loss percentage or absolute value
stopLossType:
type: string
description: Whether stop loss is a percentage or absolute price
enum:
- percentage
- absolute
takeProfit:
type: number
format: float
description: Take profit percentage or absolute value
takeProfitType:
type: string
description: Whether take profit is a percentage or absolute price
enum:
- percentage
- absolute
trailingStop:
type: number
format: float
description: Trailing stop distance percentage
maxPositions:
type: integer
description: Maximum number of concurrent open positions
minimum: 1
StrategyCondition:
type: object
description: A single condition in a trading strategy, representing a comparison between indicators, price values, or other market data points.
properties:
id:
type: string
description: Unique identifier for this condition
indicator:
type: string
description: The technical indicator or data source for the left side of the condition (e.g., SMA, RSI, MACD, Price)
parameters:
type: object
description: Parameters for the indicator (e.g., period length, source field)
additionalProperties: true
operator:
type: string
description: The comparison operator
enum:
- crosses_above
- crosses_below
- greater_than
- less_than
- equals
compareValue:
description: The value or indicator to compare against (right side of condition)
oneOf:
- type: number
- type: string
- type: object
logicalOperator:
type: string
description: How this condition combines with the next condition in the list
enum:
- AND
- OR
PositionConfig:
type: object
description: Position sizing and order configuration for the strategy.
properties:
side:
type: string
description: The trade direction
enum:
- long
- short
- both
orderType:
type: string
description: The order type used for entries
enum:
- market
- limit
- stop
quantity:
type: number
format: float
description: The number of shares or contracts per trade
quantityType:
type: string
description: Whether quantity is shares, contracts, or a dollar amount
enum:
- shares
- contracts
- dollars
StrategyListResponse:
type: object
description: Paginated list of user strategies.
properties:
strategies:
type: array
description: List of strategy objects
items:
$ref: '#/components/schemas/StrategyResponse'
total:
type: integer
description: Total number of strategies matching the filter
limit:
type: integer
description: Maximum number of results per page
offset:
type: integer
description: Current offset for pagination
ErrorResponse:
type: object
description: Standard error response for broker API requests.
properties:
error:
type: string
description: A human-readable error message
code:
type: string
description: A machine-readable error code
details:
type: object
description: Additional error details when available
additionalProperties: true
CreateStrategyRequest:
type: object
description: Request body for creating a new trading strategy. Includes the strategy metadata and its visual builder definition.
required:
- name
- instrument
properties:
name:
type: string
description: A human-readable name for the strategy
maxLength: 200
description:
type: string
description: A description of what the strategy does
maxLength: 2000
instrument:
type: string
description: The ticker symbol of the primary instrument this strategy trades
example: AAPL
instrumentType:
type: string
description: The type of financial instrument
enum:
- stock
- option
- future
timeframe:
type: string
description: The primary chart timeframe for the strategy
enum:
- 1m
- 5m
- 15m
- 30m
- 1h
- 4h
- 1d
definition:
$ref: '#/components/schemas/StrategyDefinition'
StrategyDefinition:
type: object
description: The visual strategy builder definition containing entry conditions, exit conditions, and risk management rules created through the Level2 drag-and-drop interface.
properties:
entryConditions:
type: array
description: List of conditions that must be met to trigger a trade entry
items:
$ref: '#/components/schemas/StrategyCondition'
exitConditions:
type: array
description: List of conditions that trigger trade exits
items:
$ref: '#/components/schemas/StrategyCondition'
riskManagement:
$ref: '#/components/schemas/RiskManagement'
position:
$ref: '#/components/schemas/PositionConfig'
UpdateStrategyRequest:
type: object
description: Request body for updating an existing trading strategy.
properties:
name:
type: string
description: Updated name for the strategy
maxLength: 200
description:
type: string
description: Updated description
maxLength: 2000
instrument:
type: string
description: Updated ticker symbol
instrumentType:
type: string
description: Updated instrument type
enum:
- stock
- option
- future
timeframe:
type: string
description: Updated chart timeframe
enum:
- 1m
- 5m
- 15m
- 30m
- 1h
- 4h
- 1d
status:
type: string
description: Updated strategy status. Set to inactive to soft-delete, or active to restore a soft-deleted strategy.
enum:
- active
- inactive
- draft
definition:
$ref: '#/components/schemas/StrategyDefinition'
parameters:
userId:
name: userId
in: path
required: true
description: The unique identifier of the broker user on the Level2 platform.
schema:
type: string
strategyId:
name: strategyId
in: path
required: true
description: The unique identifier of the trading strategy.
schema:
type: string
securitySchemes:
apiKeyPath:
type: apiKey
in: query
name: api_key
description: API key passed as a path parameter in the URL. Obtain your API key from the Level2 platform dashboard.
externalDocs:
description: Level2 API Documentation
url: https://guide.bytemine.io/technical-documentation/api-documentation