HaasOnline Partner API (v1)

Download OpenAPI specification:Download

HaasOnline Support: [email protected]

API for managing trading bots, signals, and users. Integrate HaasOnline's advanced trading automation into your exchange platform.

Backtests

Execute a backtest simulation

Simulates a trading bot against historical market data to evaluate performance before risking real funds.

How it works:

  1. Submit bot configuration (same settings used for live bots)
  2. Specify time range for historical simulation
  3. Receive backtest ID immediately
  4. Poll /bots/backtest/{id}/status for progress updates
  5. Retrieve results from /bots/backtest/{id}/results when complete

Performance metrics include:

  • Profit/Loss, ROI, fees
  • Win rate, profit factor
  • Sharpe ratio, Sortino ratio
  • Maximum drawdown
  • Order and position statistics

Time range limits:

  • Must have price history data available for the selected period
  • Longer periods take more time to execute
  • Use recent data for best accuracy (market conditions change)

Backtest configuration:

  • Uses your actual account balance (not unlimited funds)
  • Queries your live exchange settings (position mode, margin mode, leverage)
  • Orders fill when price touches limit (fillWhenTouched=true, faster backtests)
  • Simulates with your exact trading configuration for realistic results
Authorizations:
ApiKey
Request Body schema: application/json

Backtest configuration including bot type, settings, and time range

userId
string or null

User ID who owns the backtest

type
string (WhiteLabelScriptType)
Enum: "spot_grid" "futures_grid" "spot_dollar_cost_averaging" "futures_dollar_cost_averaging" "webhook"

Type of trading bot script

exchangeId
string or null

Exchange ID (must match user's exchange)

settings
any or null

Bot settings/configuration

startUnix
integer <int32>

Backtest start time (Unix timestamp in seconds)

endUnix
integer <int32>

Backtest end time (Unix timestamp in seconds)

Responses

Request samples

Content type
application/json
{
  • "userId": "user_abc123",
  • "type": "spot_grid",
  • "exchangeId": "BINANCE",
  • "settings": {
    },
  • "startUnix": 1704067200,
  • "endUnix": 1706745600
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Get backtest execution status

Retrieves the current execution status and progress of a running or completed backtest.

Backtest states:

  • loading_script: Loading bot script and validating configuration
  • loading_data: Loading historical price data from database
  • executing: Running simulation (progress indicates percentage complete)
  • completed: Backtest finished successfully, results available
  • failed: Backtest encountered an error (check message for details)
  • cancelled: Backtest was cancelled by user

Polling recommendations:

  • Poll every 2-5 seconds during execution
  • Stop polling when state is completed, failed, or cancelled
  • Short backtests (<1 hour) complete in seconds
  • Long backtests (weeks/months) may take several minutes
Authorizations:
ApiKey
path Parameters
backtestId
required
string

Backtest identifier returned from POST /bots/backtest

Responses

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Get backtest results

Retrieves comprehensive backtest results including performance metrics, statistics, and logs.

Only available when backtest state is 'completed'.

Results include:

Summary:

  • Realized profit/loss
  • Return on investment (ROI)
  • Total fees paid
  • Market price change during period

Performance metrics:

  • Profit factor: Total wins ÷ total losses
  • Sharpe ratio: Risk-adjusted returns
  • Sortino ratio: Downside risk-adjusted returns
  • Maximum drawdown: Largest peak-to-trough decline
  • Win percentage: Profitable trades ÷ total trades

Order statistics:

  • Total orders placed
  • Fill rates
  • Average open time

Position statistics:

  • Winning vs losing positions
  • Average profit per position
  • Position margins

Execution logs:

  • Bot decision logs
  • Order placement/fill events
  • Error messages (if any)

Interpreting results:

  • ROI > 0: Strategy was profitable
  • Win % > 50%: More winning than losing trades
  • Profit factor > 1: Wins larger than losses
  • Sharpe > 1: Good risk-adjusted returns
  • Max drawdown: Maximum loss exposure
Authorizations:
ApiKey
path Parameters
backtestId
required
string

Backtest identifier

Responses

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Get complete backtest execution logs

Retrieves the complete execution log from a backtest run as structured log entries.

Only available when backtest state is 'completed'.

Each log entry includes:

  • lineNumber: Sequential line number
  • timestamp: Unix timestamp when log was created
  • severity: Log level ("info", "trade", "warning", "error", "custom")
  • color: RGBA color value for custom severity logs
  • message: Cleaned log message content

Log contents include:

  • Bot initialization and configuration
  • Signal generation events
  • Order placement and fill events
  • Position open/close events
  • Error messages and warnings
  • Performance milestones

Use cases:

  • Debugging bot behavior
  • Understanding trading decisions
  • Analyzing order execution
  • Investigating errors or unexpected results
  • Filtering logs by severity level

Note: Unlike the /results endpoint which returns only the first 50 log entries, this endpoint returns the complete log history for detailed analysis.

Authorizations:
ApiKey
path Parameters
backtestId
required
string

Backtest identifier

Responses

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "string",
  • "data": [
    ]
}

Get backtest positions

Retrieves all positions opened during the backtest simulation with complete order details.

Only available when backtest state is 'completed'.

Each position includes:

  • Position GUID, ID, direction (Long/Short)
  • Open/close timestamps
  • Average entry and exit prices
  • Position size and leverage
  • Complete list of entry orders (prices, amounts, fees, execution times)
  • Complete list of exit orders (prices, amounts, fees, execution times)
  • Realized profit/loss and ROI
  • Performance metrics (max drawdown, highest/lowest profit)

Use cases:

  • Analyzing individual position performance
  • Understanding entry/exit timing
  • Reviewing order execution details
  • Calculating custom metrics per position
Authorizations:
ApiKey
path Parameters
backtestId
required
string

Backtest identifier

Responses

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "string",
  • "data": [
    ]
}

Cancel a running backtest

Cancels a running backtest simulation.

Behavior:

  • Stops execution immediately
  • No results will be saved
  • Cannot cancel completed backtests
  • Safe to call even if backtest already finished (will return success)

Use cases:

  • User changed their mind
  • Need to modify settings and restart
  • Backtest taking too long
  • Found error in configuration
Authorizations:
ApiKey
path Parameters
backtestId
required
string

Backtest identifier to cancel

Responses

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": true
}

Bots

Get all bots across all users

Retrieves a paginated list of all trading bots across all users in your partner account.

Authorizations:
ApiKey
Request Body schema: application/json

Pagination parameters

limit
integer <int32>

Maximum number of bots to return per page. Use -1 for default (10,000). Valid range: -1 or 1-10,000.

nextPageId
string or null

Opaque pagination token from previous response. Omit for first page.

Responses

Request samples

Content type
application/json
{
  • "limit": 5,
  • "nextPageId": ""
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Get bots for a specific user

Retrieves a paginated list of trading bots for a specific user.

Authorizations:
ApiKey
Request Body schema: application/json

User ID and pagination parameters

userId
required
string non-empty

The unique identifier of the user whose bots to retrieve

limit
integer <int32>

Maximum number of bots to return per page. Use -1 for default (10,000). Valid range: -1 or 1-10,000.

nextPageId
string or null

Opaque pagination token from previous response. Omit for first page.

Responses

Request samples

Content type
application/json
{
  • "userId": "50e3b09c-b4fc-4ba4-9c84-1fed830ab506",
  • "limit": 10,
  • "nextPageId": ""
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Get a specific bot by ID

Retrieves details for a specific trading bot by bot ID and user ID.

Authorizations:
ApiKey
Request Body schema: application/json

User ID and bot ID

userId
required
string non-empty
botId
required
string non-empty

Responses

Request samples

Content type
application/json
{
  • "userId": "d9bd8028-a594-4828-8edb-e37a35d39dad",
  • "botId": "6dafad4e364449c9906296aab8eff2f7"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Create a new trading bot

Creates and starts a new trading bot for the specified user with the provided configuration.

Authorizations:
ApiKey
Request Body schema: application/json

Bot configuration including user ID, script type, and settings

userId
string or null

The user ID who will own this bot

type
string (WhiteLabelScriptType)
Enum: "spot_grid" "futures_grid" "spot_dollar_cost_averaging" "futures_dollar_cost_averaging" "webhook"

Type of trading bot script

settings
any or null

Bot configuration settings. Structure varies by bot type. Use /scripts/script endpoint to get available settings for each type.

masterBotId
string or null

Optional: Master bot ID if this bot should follow updates from a master bot (for copy trading)

Responses

Request samples

Content type
application/json
{
  • "userId": "f873b314-f165-45a0-b658-d15ff37d529a",
  • "type": "spot_grid",
  • "settings": {
    },
  • "masterBotId": null
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Edit an existing bot's settings

Updates the settings of an existing trading bot. Note: Copied bots cannot be edited directly.

Authorizations:
ApiKey
Request Body schema: application/json

Bot ID, user ID, and new settings to apply

userId
string or null
botId
string or null
settings
any or null

Responses

Request samples

Content type
application/json
{
  • "userId": "4aca37d0-c3ab-482a-b479-e421ec74805b",
  • "botId": "7d7e643ac399492c8adf1add09316abb",
  • "settings": {
    }
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": true
}

Copy an existing bot to another user

Creates a copy of an existing bot for another user on the same exchange.

Follow Updates Behavior:

  • When followUpdates=true: Creates a 'follower' copy that automatically receives settings updates when the master bot is edited via /bots/edit. The copied bot's masterBotId will be set to the source bot ID. Follower bots cannot be edited directly - edits must be made to the master bot.
  • When followUpdates=false: Creates an independent copy that does not receive updates from the source bot. The copied bot's masterBotId will be empty. Independent copies can be edited separately via /bots/edit.

Master Bot Tracking:

  • The source bot's 'cloned' count increases by 1 (always)
  • The source bot's 'followers' count increases by 1 (only if followUpdates=true)

Requirements:

  • Target user must exist and be connected to the same exchange as the source bot
  • Source bot cannot itself be a follower copy (must copy the original master bot)
  • Settings overrides are optional and will be merged with the source bot's settings
Authorizations:
ApiKey
Request Body schema: application/json

Source bot ID, target user ID, optional settings overrides, and follow updates flag

userId
required
string non-empty

The target user ID who will receive the bot copy

botId
required
string non-empty

The source bot ID to copy from

followUpdates
required
boolean

Whether the copied bot should follow updates from the source bot. When true, the copy becomes a "follower" that automatically receives settings updates when the master bot is edited via /bots/edit. When false, the copy is independent and can be edited separately.

settings
required
any

Optional settings to override in the copy. These settings will be merged with the source bot's settings. Use /scripts/script endpoint to see available settings for the bot type.

Responses

Request samples

Content type
application/json
{
  • "userId": "user_f6g7h8i9j0",
  • "botId": "bot_x1y2z3a4b5",
  • "followUpdates": true,
  • "settings": {
    }
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Start a stopped trading bot

Reactivates a previously stopped bot. The bot must exist and be in stopped status.

Authorizations:
ApiKey
Request Body schema: application/json

Bot ID to start

botId
required
string non-empty

The unique identifier of the bot to start

Responses

Request samples

Content type
application/json
{
  • "botId": "7d7e643ac399492c8adf1add09316abb"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": true
}

Stop a trading bot

Stops a running trading bot and deactivates it. The bot configuration and history are preserved and can be reactivated later. All open orders will be cancelled.

Authorizations:
ApiKey
Request Body schema: application/json

Bot ID to stop

botId
required
string non-empty

The unique identifier of the bot to stop

Responses

Request samples

Content type
application/json
{
  • "botId": "895aef7fe5eb4b368ece3d4e65729769"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": true
}

Preview bot orders

Calculates and returns the orders that would be created when starting a bot, without actually creating the bot or placing any orders. Currently supported: Grid bots only (spot_grid, futures_grid). Other bot types will return an error. IMPORTANT: This preview is an estimate based on current market conditions. Actual order prices and quantities may differ when the bot is created due to price movements, fee changes, or market volatility. Use this preview as a planning tool, not a guarantee of exact order placement.

Authorizations:
ApiKey
Request Body schema: application/json

Bot configuration for preview

userId
required
string non-empty
exchangeId
required
string non-empty
type
required
string (WhiteLabelScriptType)
Enum: "spot_grid" "futures_grid" "spot_dollar_cost_averaging" "futures_dollar_cost_averaging" "webhook"

Type of trading bot script

settings
required
any

Responses

Request samples

Content type
application/json
{
  • "userId": "string",
  • "exchangeId": "string",
  • "type": "spot_grid",
  • "settings": null
}

Response samples

Content type
application/json
{ }

Delete a trading bot

Permanently deletes a trading bot and removes it from the system. This action cannot be undone. All bot configuration and history will be lost.

Authorizations:
ApiKey
Request Body schema: application/json

Bot ID to delete

botId
required
string non-empty

The unique identifier of the bot to delete

Responses

Request samples

Content type
application/json
{
  • "botId": "d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": true
}

Get bot orders

Retrieves all open orders for a specific bot.

Authorizations:
ApiKey
Request Body schema: application/json

User ID and bot ID

botId
required
string non-empty

The unique identifier of the bot

Responses

Request samples

Content type
application/json
{
  • "botId": "6dafad4e364449c9906296aab8eff2f7"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": [
    ]
}

Get bot execution logs

Retrieves a paginated list of execution log messages for a specific bot.

Authorizations:
ApiKey
Request Body schema: application/json

User ID, bot ID, and pagination parameters

botId
required
string non-empty

The unique identifier of the bot

limit
integer <int32>

Maximum number of log entries to return per page. Use -1 for default (10,000). Valid range: -1 or 1-10,000.

nextPageId
string or null

Opaque pagination token from previous response. Omit for first page.

offset
integer <int32>

Number of log entries to skip from the beginning (for backwards pagination)

Responses

Request samples

Content type
application/json
{
  • "botId": "895aef7fe5eb4b368ece3d4e65729769",
  • "limit": 100,
  • "nextPageId": "",
  • "offset": 0
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Get bot open positions

Retrieves all currently open positions for a specific bot. No pagination needed as this is real-time data.

Authorizations:
ApiKey
Request Body schema: application/json

User ID and bot ID

botId
required
string non-empty

The unique identifier of the bot

Responses

Request samples

Content type
application/json
{
  • "botId": "6dafad4e364449c9906296aab8eff2f7"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": [
    ]
}

Get bot closed positions

Retrieves a paginated list of closed positions for a specific bot.

Authorizations:
ApiKey
Request Body schema: application/json

User ID, bot ID, and pagination parameters

botId
required
string non-empty

The unique identifier of the bot

limit
integer <int32>

Maximum number of positions to return per page. Use -1 for default (10,000). Valid range: -1 or 1-10,000.

nextPageId
string or null

Opaque pagination token from previous response. Omit for first page.

Responses

Request samples

Content type
application/json
{
  • "botId": "18c561aa5a9c4e54af24fb8c21a2040a",
  • "limit": 50,
  • "nextPageId": ""
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Get orders for a specific position

Retrieves all enter and exit orders for a specific position.

Authorizations:
ApiKey
Request Body schema: application/json

User ID, bot ID, and position ID

botId
required
string non-empty

The unique identifier of the bot

positionId
required
string non-empty

The unique identifier of the position

Responses

Request samples

Content type
application/json
{
  • "botId": "bedc8bb485514565b64a728fc0886a95",
  • "positionId": "pos_abc123xyz789"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Info

Get supported exchanges

Retrieves a list of cryptocurrency exchanges that are enabled for your partner account.

Authorizations:
ApiKey

Responses

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": [
    ]
}

Get available trading markets

Retrieves all available trading pairs (markets) across the exchanges enabled for your partner account.

Authorizations:
ApiKey

Responses

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": [
    ]
}

Scripts

Get all available trading bot scripts

Retrieves a list of all available trading bot scripts (e.g., Grid Bot, DCA Bot, etc.).

Authorizations:
ApiKey

Responses

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": [
    ]
}

Get detailed information about a specific script

Retrieves detailed information about a specific trading bot script, including all configurable settings and parameters.

Authorizations:
ApiKey
Request Body schema: application/json

Script type identifier

type
string (WhiteLabelScriptType)
Enum: "spot_grid" "futures_grid" "spot_dollar_cost_averaging" "futures_dollar_cost_averaging" "webhook"

Type of trading bot script

Responses

Request samples

Content type
application/json
{
  • "type": "spot_grid"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Signals

Get signal information by token

Retrieves information about a trading signal using its token.

Authorizations:
ApiKey
Request Body schema: application/json

Signal token

signalToken
string or null

Responses

Request samples

Content type
application/json
{
  • "signalToken": "webhook_token_abc123xyz"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Push a trading signal to webhook bots

Sends a trading signal to all webhook-based trading bots listening for the specified signal token.

Required Fields:

  • signalToken (string): The webhook token identifier
  • action (string): Trading action - CASE-SENSITIVE, must be lowercase
  • amount (decimal): Trade amount
  • timestamp (integer): Unix timestamp

Valid Action Values (case-sensitive):

  • "buy" - Open a long position or add to existing long
  • "sell" - Close long position or open short position
  • "enter_long" - Explicitly enter a long position
  • "exit_long" - Explicitly exit a long position
  • "enter_short" - Explicitly enter a short position
  • "exit_short" - Explicitly exit a short position

Optional Fields:

  • price (decimal): Limit price for the order
  • investmentType (string): "base", "contract", "quote", "margin", "percentage_wallet", "percentage_position"
  • maxLag (integer): Maximum acceptable delay in seconds

Important Notes:

  • The action field is case-sensitive - uppercase values like "BUY" will fail
  • The API accepts any signalToken without validating if it corresponds to an active webhook bot
  • Signals are stored for 7 days regardless of whether any bots are listening
Authorizations:
ApiKey
Request Body schema: application/json

Signal data to send to webhook-based bots

signal
required
any

Trading signal object containing the signal token, action, amount, and timestamp. Required fields: signalToken (string), action (string, lowercase only), amount (decimal), timestamp (integer). Valid action values (case-sensitive, must be lowercase): "buy", "sell", "enter_long", "exit_long", "enter_short", "exit_short". Optional fields: price (decimal), investmentType (string), maxLag (integer).

Responses

Request samples

Content type
application/json
{
  • "signal": {
    }
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": true
}

Users

Get all users

Retrieves a paginated list of all users in your partner account.

Authorizations:
ApiKey
Request Body schema: application/json

Pagination parameters

limit
integer <int32>
nextPageId
string or null

Responses

Request samples

Content type
application/json
{
  • "limit": 5,
  • "nextPageId": ""
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Get a specific user by ID

Retrieves details for a specific user by user ID.

Authorizations:
ApiKey
Request Body schema: application/json

User ID

userId
required
string non-empty

Responses

Request samples

Content type
application/json
{
  • "userId": "696c712e-346b-4631-9df8-38fe59211493"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": {
    }
}

Create a new user

Creates a new user in your partner account with exchange API credentials.

Authorizations:
ApiKey
Request Body schema: application/json

User details including email, exchange, and API credentials

exchangeId
required
string non-empty

The exchange identifier (e.g., BINANCE, BYBIT, BITMEX)

publicKey
required
string non-empty

The exchange API public key. Use "sim" for simulated/paper trading accounts.

secretKey
required
string non-empty

The exchange API secret key

extraKey
string or null

Optional passphrase or extra key required by some exchanges (e.g., KuCoin)

exchangeUserId
string or null

Optional exchange user ID for tracking or identifying the user on the exchange platform

Responses

Request samples

Content type
application/json
{
  • "exchangeId": "BITMEX",
  • "publicKey": "your-api-public-key",
  • "secretKey": "your-api-secret-key",
  • "extraKey": "",
  • "exchangeUserId": ""
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": "696c712e-346b-4631-9df8-38fe59211493"
}

Delete a user

Deletes a user from your partner account. The user must not have any active bots - stop and delete all bots before deleting the user.

Authorizations:
ApiKey
Request Body schema: application/json

User ID to delete

userId
required
string non-empty

Responses

Request samples

Content type
application/json
{
  • "userId": "696c712e-346b-4631-9df8-38fe59211493"
}

Response samples

Content type
application/json
{
  • "isSuccess": true,
  • "code": 0,
  • "message": "",
  • "data": true
}