Skip to content

MCP Tools Reference

This page documents all tools exposed by the TradeServer MCP server. Tools marked with No auth can be called without an API key.


System

health_check

Verifies connectivity and validates credentials. Returns ok on success.

No parameters.


HaasScript Management

list_scripts

Returns a paginated page of HaasScript records visible to the authenticated user — your own scripts plus the public community library, so the total is large on every account regardless of how many scripts you own. Each item includes SID (id), SN (name), type, dependency info, FID (folder id) and FN (resolved folder name). Covers Lua, Visual, and Command script types.

The response uses the same envelope as the other paginated tools: I is the current page, NP the next cursor (-1 when exhausted), total_count the count after filtering, and page_length the size actually applied.

Parameter Type Required Description
next_page_id integer No Pagination cursor (0 or omit for the first page)
page_length integer No Scripts per page (default 100, max 500)
name_filter string No Case-insensitive substring match on the script name (SN)
folder_id string No Only scripts in this folder id (FID)

Prefer name_filter or folder_id over paging through the whole library.


get_script

Returns a single full HaasScript record including source code and compile result.

Parameter Type Required Description
script_id string Yes Script ID hash

add_script

Creates a new HaasScript. Returns the created script record.

Parameter Type Required Description
name string Yes Script name
description string No Script description
script string Yes Lua source code (may be base64+gzip compressed)
type string Yes Script type: Lua, Visual, or Command

edit_script_source

Replaces the source code of an existing HaasScript and recompiles it.

Parameter Type Required Description
script_id string Yes Script ID hash
source_code string Yes New Lua source code
settings object No HaasScriptSettings JSON (accountId, marketTag, interval, etc.)

compile_script

Compiles a HaasScript without saving it. Returns the compile result including errors and discovered input fields. No auth required.

Parameter Type Required Description
source_code string Yes Lua source code to compile
script_type string No Script type: Lua (default) or Visual

delete_script

Permanently deletes a HaasScript. Returns true on success.

Parameter Type Required Description
script_id string Yes Script ID hash

search_haasscript_docs

Searches the HaasScript command reference — ~780 built-in commands and constants plus your own custom commands. Returns full command entries: signature, parameters, return type and category. Exact and prefix name matches rank first, then keyword matches against descriptions, categories and parameter names. An empty query with a category lists every command in that category. Results are paginated.

Parameter Type Required Description
query string Yes Command name (exact or partial, e.g. RSI) or keywords (e.g. trailing stop). May be empty only when category is given
category string No Category filter, e.g. Technical Analysis, Easy Safeties. Case- and punctuation-insensitive; an unknown value returns the list of valid categories
next_page_id integer No Pagination offset (0 or omit for first page)
page_length integer No Results per page (default 10, max 50)

Backtest Execution

execute_backtest

Runs a backtest for a HaasScript over a specified time range. Returns a backtestId string on success.

Parameter Type Required Description
backtest_id string Yes Unique backtest ID (generate a new hash)
script_id string Yes Script ID to backtest
settings object Yes HaasScriptSettings JSON
start_unix integer Yes Backtest start time (Unix timestamp, seconds)
end_unix integer Yes Backtest end time (Unix timestamp, seconds)

get_backtest_status

Returns real-time execution status for a running backtest.

Parameter Type Required Description
service_id string Yes Service ID returned when the backtest was started
backtest_id string Yes Backtest ID

get_backtest_info

Returns summary information for a completed backtest (profit, ROI, timestamps).

Parameter Type Required Description
backtest_id string Yes Backtest ID

get_backtest_runtime

Returns the full runtime state of a completed backtest including trade reports and positions.

Parameter Type Required Description
backtest_id string Yes Backtest ID

get_backtest_logs

Returns the execution log lines for a backtest.

Parameter Type Required Description
backtest_id string Yes Backtest ID

get_backtest_positions

Returns a paginated list of trade positions from a completed backtest.

Parameter Type Required Description
backtest_id string Yes Backtest ID
next_page_id integer Yes Pagination cursor (0 for first page)
page_length integer Yes Results per page

get_backtest_export_data

Returns the contents of an export file written by a script during a backtest via InitExportData/WriteExportData — the only way to read export rows over MCP. Returns raw CSV by default, or a JSON array of row objects with format=json.

Parameter Type Required Description
backtest_id string Yes Backtest ID
name string Yes Export file name as defined by InitExportData
format string No Output format: csv (default) or json
lab_id string No Parent lab ID — drills into a lab-internal backtest

get_backtest_history

Returns a paginated list of all stored backtest results.

Parameter Type Required Description
next_page_id integer Yes Pagination cursor (0 for first page)
page_length integer Yes Results per page

list_active_backtests

Returns all currently running backtest executions for the authenticated user.

No parameters.


is_script_executing

Returns the current execution state for a script (whether a backtest is running).

Parameter Type Required Description
script_id string Yes Script ID to check

cancel_backtest

Cancels a currently running backtest. Returns true on success.

Parameter Type Required Description
backtest_id string Yes Backtest ID to cancel
service_id string Yes Service ID returned when the backtest was started

delete_backtest

Permanently deletes a stored backtest result. Returns true on success.

Parameter Type Required Description
backtest_id string Yes Backtest ID to delete

Trading Bots

list_bots

Returns all trading bots for the authenticated user.

No parameters.


get_bot

Returns a single bot by ID.

Parameter Type Required Description
bot_id string Yes Bot ID hash

get_bot_runtime

Returns the current runtime state of a bot including open positions and orders.

Parameter Type Required Description
bot_id string Yes Bot ID hash

get_bot_report

Returns the performance report for a bot (Sharpe ratio, win rate, profit factor, etc.).

Parameter Type Required Description
bot_id string Yes Bot ID hash

get_bot_open_orders

Returns the currently open orders for a bot.

Parameter Type Required Description
bot_id string Yes Bot ID hash

get_bot_positions

Returns open or closed positions for a bot. Closed positions are paginated.

Parameter Type Required Description
bot_id string Yes Bot ID hash
status string No open (default) or closed
next_page_id integer No Pagination cursor for closed positions (default 0)
page_length integer No Page size for closed positions (default 50)

get_bot_logs

Returns a paginated log of bot messages.

Parameter Type Required Description
bot_id string Yes Bot ID hash
next_page_id integer Yes Pagination cursor (0 for first page)
page_length integer Yes Log lines per page
offset integer No Line offset within the page

get_bot_profits

Returns profit history for all bots over a time period.

Parameter Type Required Description
start_date integer Yes Period start (Unix timestamp, seconds)
end_date integer Yes Period end (Unix timestamp, seconds)

Exchange Accounts

list_accounts

Returns all exchange accounts (real and simulated) for the authenticated user.

No parameters.


Labs (Parameter Optimization)

Labs let you run automated parameter-space searches across a HaasScript to find optimal settings.

list_labs

Returns all lab records for the authenticated user.

No parameters.


create_lab

Creates a new lab for running parameter-space simulations on a HaasScript.

Parameter Type Required Description
script_id string Yes Script ID to use for the lab
name string Yes Lab name
account_id string Yes Exchange account ID
market string Yes Market tag (e.g. BINANCE_BTC_USDT_)
interval integer Yes Candle interval in minutes
style integer Yes Chart price plot style enum value

clone_lab

Clones an existing lab record. Returns the new lab record.

Parameter Type Required Description
lab_id string Yes Lab ID to clone
name string No Name for the cloned lab

get_lab_details

Returns the full details of a lab record including configuration and parameters.

Parameter Type Required Description
lab_id string Yes Lab ID

update_lab

Updates a lab's configuration, settings, and parameter ranges.

Parameter Type Required Description
lab_id string Yes Lab ID to update
name string Yes Lab name
type string Yes Algorithm type enum value (e.g. 0 = Random)
config object Yes UserLabConfig JSON (maxBots, maxIterations, etc.)
settings object Yes HaasScriptSettings JSON
parameters array Yes List of UserLabParameter objects defining parameter search ranges

start_lab_execution

Starts a lab execution over a time range.

Parameter Type Required Description
lab_id string Yes Lab ID to execute
start_unix integer Yes Backtest start time (Unix timestamp, seconds)
end_unix integer Yes Backtest end time (Unix timestamp, seconds)
send_email boolean No Send email notification on completion

get_lab_execution_status

Returns the current execution status of a running lab.

Parameter Type Required Description
lab_id string Yes Lab ID

get_lab_results

Returns a paginated list of backtest results for a lab.

Parameter Type Required Description
lab_id string Yes Lab ID
next_page_id integer Yes Pagination cursor (0 for first page)
page_length integer Yes Results per page

cancel_lab_execution

Cancels a running lab execution.

Parameter Type Required Description
lab_id string Yes Lab ID

delete_lab

Permanently deletes a lab record. Returns true on success.

Parameter Type Required Description
lab_id string Yes Lab ID to delete

Markets & Price Data

list_markets

Returns all available markets across all price sources. No auth required.

No parameters.


check_market_data

Returns tick data for a market over a time range. Useful for confirming data availability before running a backtest. No auth required.

Parameter Type Required Description
market string Yes Market tag (e.g. BINANCE_BTC_USDT_)
start_unix integer Yes Start time (Unix timestamp, seconds)
end_unix integer Yes End time (Unix timestamp, seconds)
interval integer Yes Candle interval in minutes

sync_market_data

Triggers a data sync for a market. No auth required.

Parameter Type Required Description
market string Yes Market tag (e.g. BINANCE_BTC_USDT_)

Wallet & Portfolio

get_wallet

Returns the raw wallet (balances) for a single exchange account.

Parameter Type Required Description
account_id string Yes Exchange account ID

list_wallets

Returns raw wallets for all exchange accounts belonging to the authenticated user.

No parameters.


get_balance

Returns the balance for an account converted to a target currency.

Parameter Type Required Description
account_id string Yes Exchange account ID
currency string Yes Target currency (e.g. USDT)
aggregate_currencies boolean Yes Aggregate all currencies into a single total

get_portfolio

Returns the full portfolio (holdings and value) across one or more accounts.

Parameter Type Required Description
account_ids string Yes Comma-separated account IDs, or empty string for all accounts
coins string Yes Comma-separated coin list to include, or empty string for all
currency string Yes Target currency for value conversion (e.g. USDT)
timestamp integer Yes Unix timestamp for historical snapshot; use 0 for current value