From 5b4061fd6a485aaee9caaef92d9f05ebd6804b4c Mon Sep 17 00:00:00 2001 From: Alexandre Catarino Date: Fri, 16 Oct 2026 00:09:53 +0100 Subject: [PATCH] Document the backtest orders and trades export endpoints Add /backtests/export/orders and /backtests/export/trades to the API reference, add examples, and link them from the backtest results pages. Co-Authored-By: Claude Opus 5.5 --- .../02 Read Backtest/00.json | 4 +- .../07 Export Orders/01 Introduction.html | 5 ++ .../07 Export Orders/02 Description.html | 5 ++ .../07 Export Orders/03 Request.html | 24 ++++++ .../07 Export Orders/04 Responses.html | 36 ++++++++ .../07 Export Orders/99 Examples.php | 1 + .../07 Export Orders/metadata.json | 12 +++ .../08 Export Trades/01 Introduction.html | 5 ++ .../08 Export Trades/02 Description.html | 5 ++ .../08 Export Trades/03 Request.html | 24 ++++++ .../08 Export Trades/04 Responses.html | 36 ++++++++ .../08 Export Trades/99 Examples.php | 1 + .../08 Export Trades/metadata.json | 12 +++ QuantConnect-Platform-2.0.0.yaml | 82 +++++++++++++++++++ Resources/algorithm-results/orders.php | 2 +- Resources/algorithm-results/trades.php | 2 +- .../qc-api/examples/backtest-management.php | 20 ++++- 17 files changed, 272 insertions(+), 4 deletions(-) create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/01 Introduction.html create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/02 Description.html create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/03 Request.html create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/04 Responses.html create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/99 Examples.php create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/metadata.json create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/01 Introduction.html create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/02 Description.html create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/03 Request.html create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/04 Responses.html create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/99 Examples.php create mode 100644 01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/metadata.json diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/00.json b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/00.json index 3dd85dd814..80117f229f 100644 --- a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/00.json +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/00.json @@ -11,6 +11,8 @@ "03" : "", "04" : "", "05" : "", - "06" : "" + "06" : "", + "07" : "", + "08" : "" } } diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/01 Introduction.html b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/01 Introduction.html new file mode 100644 index 0000000000..bd88cbf720 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/01 Introduction.html @@ -0,0 +1,5 @@ + + +

+Download the orders of a backtest as a CSV file. +

diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/02 Description.html b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/02 Description.html new file mode 100644 index 0000000000..44fdb9959c --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/02 Description.html @@ -0,0 +1,5 @@ + + +

+The CSV file has the same format as the file you get when you click Download Orders on the backtest results page. To get all the properties of the orders, call the /backtests/orders/read endpoint. +

diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/03 Request.html b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/03 Request.html new file mode 100644 index 0000000000..84c49b4499 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/03 Request.html @@ -0,0 +1,24 @@ + +

+Download the orders of the backtest Id provided. The /backtests/export/orders API accepts requests in the following format: +

+ + + + + + + + + + + + + +
ExportBacktestOrdersRequest Model - Request to download the orders of a backtest.
backtestId string
required
example: 26c7bb06b8487cff1c7b3c44652b30f1

Id of the backtest from which to download the orders.
Example +
+{
+  "backtestId": "26c7bb06b8487cff1c7b3c44652b30f1"
+}
+
+
\ No newline at end of file diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/04 Responses.html b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/04 Responses.html new file mode 100644 index 0000000000..73ceb72e86 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/04 Responses.html @@ -0,0 +1,36 @@ + + +

+The /backtests/export/orders API provides a response in the following format: +

+

200 Success

+ + + + + + + + + + + + + +
text/csv - Orders of the backtest, sorted by time.
content string
One row per order. The Time column is in UTC.
Example +
+Time,Symbol,Price,Quantity,Type,Status,Value,Tag
+2024-01-02T15:00:00Z,IWM,195.236280785,500,Market,Filled,97618.1403925,"" 
+
+
+

401 Authentication Error

+ + + + + + + + + +
UnauthorizedError Model - Unauthorized response from the API. Key is missing, invalid, or timestamp is too old for hash.
www_authenticate string
Header
diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/99 Examples.php b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/99 Examples.php new file mode 100644 index 0000000000..c766cb2967 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/99 Examples.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/metadata.json b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/metadata.json new file mode 100644 index 0000000000..a2bad9e7ab --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/07 Export Orders/metadata.json @@ -0,0 +1,12 @@ +{ + "type": "metadata", + "values": { + "description": "Download the orders of a backtest as a CSV file.", + "keywords": "api, backtest management, export orders, csv", + "og:description": "Download the orders of a backtest as a CSV file.", + "og:title": "Export Orders - Documentation QuantConnect.com", + "og:type": "website", + "og:site_name": "Export Orders - QuantConnect.com", + "og:image": "https://cdn.quantconnect.com/docs/i/cloud-platform/api-reference/backtest-management/read-backtest/export-orders.png" + } +} diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/01 Introduction.html b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/01 Introduction.html new file mode 100644 index 0000000000..c6f73e8393 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/01 Introduction.html @@ -0,0 +1,5 @@ + + +

+Download the closed trades of a backtest as a CSV file. +

diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/02 Description.html b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/02 Description.html new file mode 100644 index 0000000000..4c81819172 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/02 Description.html @@ -0,0 +1,5 @@ + + +

+The CSV file has the same format as the file you get when you click Download Trades on the backtest results page. It contains the closed trades that the /backtests/trades/read endpoint returns, sorted by entry time. +

diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/03 Request.html b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/03 Request.html new file mode 100644 index 0000000000..50a0c42ff2 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/03 Request.html @@ -0,0 +1,24 @@ + +

+Download the closed trades of the backtest Id provided. The /backtests/export/trades API accepts requests in the following format: +

+ + + + + + + + + + + + + +
ExportBacktestTradesRequest Model - Request to download the closed trades of a backtest.
backtestId string
required
example: 26c7bb06b8487cff1c7b3c44652b30f1

Id of the backtest from which to download the closed trades.
Example +
+{
+  "backtestId": "26c7bb06b8487cff1c7b3c44652b30f1"
+}
+
+
\ No newline at end of file diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/04 Responses.html b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/04 Responses.html new file mode 100644 index 0000000000..b63ebaa343 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/04 Responses.html @@ -0,0 +1,36 @@ + + +

+The /backtests/export/trades API provides a response in the following format: +

+

200 Success

+ + + + + + + + + + + + + +
text/csv - Closed trades of the backtest, sorted by entry time.
content string
One row per closed trade. The Entry Time and Exit Time columns are in UTC.
Example +
+Entry Time,Symbols,Exit Time,Direction,Entry Price,Exit Price,Quantity,P&L,Fees,MAE,MFE,Drawdown,IsWin,Order Ids
+2024-01-02T15:00:00Z,"IWM",2024-01-02T19:54:00Z,Buy,195.236280785,193.28,500,-978.14,5,-1029.04,203.87,1232.91,0,"	1,3" 
+
+
+

401 Authentication Error

+ + + + + + + + + +
UnauthorizedError Model - Unauthorized response from the API. Key is missing, invalid, or timestamp is too old for hash.
www_authenticate string
Header
diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/99 Examples.php b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/99 Examples.php new file mode 100644 index 0000000000..c766cb2967 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/99 Examples.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/metadata.json b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/metadata.json new file mode 100644 index 0000000000..2d31bec8ec --- /dev/null +++ b/01 Cloud Platform/99 API Reference/05 Backtest Management/02 Read Backtest/08 Export Trades/metadata.json @@ -0,0 +1,12 @@ +{ + "type": "metadata", + "values": { + "description": "Download the closed trades of a backtest as a CSV file.", + "keywords": "api, backtest management, export trades, csv", + "og:description": "Download the closed trades of a backtest as a CSV file.", + "og:title": "Export Trades - Documentation QuantConnect.com", + "og:type": "website", + "og:site_name": "Export Trades - QuantConnect.com", + "og:image": "https://cdn.quantconnect.com/docs/i/cloud-platform/api-reference/backtest-management/read-backtest/export-trades.png" + } +} diff --git a/QuantConnect-Platform-2.0.0.yaml b/QuantConnect-Platform-2.0.0.yaml index e82c0312c8..7b3e872360 100644 --- a/QuantConnect-Platform-2.0.0.yaml +++ b/QuantConnect-Platform-2.0.0.yaml @@ -614,6 +614,66 @@ paths: "401": $ref: '#/components/responses/UnauthorizedErrorResponse' operationId: readBacktestTrades + /backtests/export/orders: + post: + tags: + - 01 Cloud Platform + - 99 API Reference + - 05 Backtest Management + - 02 Read Backtest + - 07 Export Orders + summary: Download the orders of a backtest as a CSV file. + description: "The CSV file has the same format as the file you get when you click Download Orders on the backtest results page. To get all the properties of the orders, call the /backtests/orders/read endpoint." + requestBody: + description: Download the orders of the backtest Id provided. + content: + application/json: + schema: + $ref: '#/components/schemas/ExportBacktestOrdersRequest' + required: true + responses: + "200": + description: Orders of the backtest, sorted by time. + content: + text/csv: + schema: + type: string + description: "One row per order. The Time column is in UTC." + examples: + - "Time,Symbol,Price,Quantity,Type,Status,Value,Tag\n2024-01-02T15:00:00Z,IWM,195.236280785,500,Market,Filled,97618.1403925,\"\" " + "401": + $ref: '#/components/responses/UnauthorizedErrorResponse' + operationId: exportBacktestOrders + /backtests/export/trades: + post: + tags: + - 01 Cloud Platform + - 99 API Reference + - 05 Backtest Management + - 02 Read Backtest + - 08 Export Trades + summary: Download the closed trades of a backtest as a CSV file. + description: "The CSV file has the same format as the file you get when you click Download Trades on the backtest results page. It contains the closed trades that the /backtests/trades/read endpoint returns, sorted by entry time." + requestBody: + description: Download the closed trades of the backtest Id provided. + content: + application/json: + schema: + $ref: '#/components/schemas/ExportBacktestTradesRequest' + required: true + responses: + "200": + description: Closed trades of the backtest, sorted by entry time. + content: + text/csv: + schema: + type: string + description: "One row per closed trade. The Entry Time and Exit Time columns are in UTC." + examples: + - "Entry Time,Symbols,Exit Time,Direction,Entry Price,Exit Price,Quantity,P&L,Fees,MAE,MFE,Drawdown,IsWin,Order Ids\n2024-01-02T15:00:00Z,\"IWM\",2024-01-02T19:54:00Z,Buy,195.236280785,193.28,500,-978.14,5,-1029.04,203.87,1232.91,0,\"\t1,3\" " + "401": + $ref: '#/components/responses/UnauthorizedErrorResponse' + operationId: exportBacktestTrades /backtests/read/report: post: tags: @@ -7311,6 +7371,28 @@ components: - 26c7bb06b8487cff1c7b3c44652b30f1 description: Id of the backtest from which to read the closed trades. description: Request to read closed trades from a backtest. + ExportBacktestOrdersRequest: + required: + - backtestId + type: object + properties: + backtestId: + type: string + examples: + - 26c7bb06b8487cff1c7b3c44652b30f1 + description: Id of the backtest from which to download the orders. + description: Request to download the orders of a backtest. + ExportBacktestTradesRequest: + required: + - backtestId + type: object + properties: + backtestId: + type: string + examples: + - 26c7bb06b8487cff1c7b3c44652b30f1 + description: Id of the backtest from which to download the closed trades. + description: Request to download the closed trades of a backtest. ReadBacktestInsightsRequest: required: - start diff --git a/Resources/algorithm-results/orders.php b/Resources/algorithm-results/orders.php index b95ff15647..26bb3b76cd 100644 --- a/Resources/algorithm-results/orders.php +++ b/Resources/algorithm-results/orders.php @@ -15,7 +15,7 @@

The timestamps in the Order Summary table are based in Eastern Time (ET).

Access the Order Summary CSV

-

To view the orders data in CSV format, open the results page, click the Orders tab, and then click Download Orders. The content of the CSV file is the content displayed in the Orders Summary table when the table rows are collapsed. The timestamps in the CSV file are based in Coordinated Universal Time (UTC). To download the CSV file with the API, call the /live/export/orders endpoint. The CSV file only contains the orders from the last 750 days. To get older orders, call the ReadLiveOrdersread_live_orders method or the /live/orders/read endpoint. If you download the order summary CSV for a local backtest, the file is stored in <organizationWorkspace> / <projectName> / backtests / <unixTimestamp> / orders.csv.

+

To view the orders data in CSV format, open the results page, click the Orders tab, and then click Download Orders. The content of the CSV file is the content displayed in the Orders Summary table when the table rows are collapsed. The timestamps in the CSV file are based in Coordinated Universal Time (UTC). To download the CSV file with the API, call the /live/export/orders endpoint. The CSV file only contains the orders from the last 750 days. To get older orders, call the ReadLiveOrdersread_live_orders method or the /live/orders/read endpoint. To download the CSV file with the API, call the /backtests/export/orders endpoint. If you download the order summary CSV for a local backtest, the file is stored in <organizationWorkspace> / <projectName> / backtests / <unixTimestamp> / orders.csv.

Access the Orders JSON

diff --git a/Resources/algorithm-results/trades.php b/Resources/algorithm-results/trades.php index e7cd0be5e1..a29bf017ff 100644 --- a/Resources/algorithm-results/trades.php +++ b/Resources/algorithm-results/trades.php @@ -6,7 +6,7 @@

The timestamps in the Trades Summary table are based in Eastern Time (ET).

Access the Trade Summary CSV

-

To view the trades data in CSV format, open the results page, click the Trades tab, and then click Download Trades. The content of the CSV file is the content displayed in the Trades Summary table when the table rows are collapsed. The timestamps in the CSV file are based in Coordinated Universal Time (UTC). To download the CSV file with the API, call the /live/export/trades endpoint. If you download the trade summary CSV for a local backtest, the file is stored in <organizationWorkspace> / <projectName> / backtests / <unixTimestamp> / trades.csv.

+

To view the trades data in CSV format, open the results page, click the Trades tab, and then click Download Trades. The content of the CSV file is the content displayed in the Trades Summary table when the table rows are collapsed. The timestamps in the CSV file are based in Coordinated Universal Time (UTC). To download the CSV file with the API, call the /live/export/trades endpoint. To download the CSV file with the API, call the /backtests/export/trades endpoint. If you download the trade summary CSV for a local backtest, the file is stored in <organizationWorkspace> / <projectName> / backtests / <unixTimestamp> / trades.csv.

Access the Trades JSON

diff --git a/Resources/qc-api/examples/backtest-management.php b/Resources/qc-api/examples/backtest-management.php index 7a29fa0f1e..151fd4d978 100644 --- a/Resources/qc-api/examples/backtest-management.php +++ b/Resources/qc-api/examples/backtest-management.php @@ -97,5 +97,23 @@ # Check if the request was successful and print the list if result['success']: print("List of Backtests:") - print(result) + print(result) + +### Export Orders +# Download the orders of the backtest as a CSV file +payload = { + "backtestId": backtest_id # ID of the backtest +} +response = post(f'{BASE_URL}/backtests/export/orders', headers=get_headers(), json=payload) +with open(f'orders-{backtest_id}.csv', 'w', newline='') as file: + file.write(response.text) + +### Export Trades +# Download the closed trades of the backtest as a CSV file +payload = { + "backtestId": backtest_id # ID of the backtest +} +response = post(f'{BASE_URL}/backtests/export/trades', headers=get_headers(), json=payload) +with open(f'trades-{backtest_id}.csv', 'w', newline='') as file: + file.write(response.text) \ No newline at end of file