Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"03" : "",
"04" : "",
"05" : "",
"06" : ""
"06" : "",
"07" : "",
"08" : ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Code generated by API-Reference-Code-Generator.py -->

<p>
Download the orders of a backtest as a CSV file.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Code generated by API-Reference-Code-Generator.py -->

<p>
The CSV file has the same format as the file you get when you click <span class='button-name'>Download Orders</span> on the backtest results page. To get all the properties of the orders, call the <a href='/docs/v2/cloud-platform/api-reference/backtest-management/read-backtest/orders'>/backtests/orders/read</a> endpoint.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Code generated by API-Reference-Code-Generator.py -->
<p>
Download the orders of the backtest Id provided. The <code>/backtests/export/orders</code> API accepts requests in the following format:
</p>
<table class="table qc-table">
<thead>
<tr>
<th colspan="2"><code>ExportBacktestOrdersRequest</code> Model - Request to download the orders of a backtest.</th>
</tr>
</thead>
<tr>
<td width="20%">backtestId</td> <td> <code>string<br/><i><sub>required</sub></i><br/><i><sub>example: 26c7bb06b8487cff1c7b3c44652b30f1</sub></i></code> <br/> Id of the backtest from which to download the orders.</td>
</tr>
<tr>
<td width="20%">Example</td>
<td>
<div class="cli section-example-container"><pre>
{
"backtestId": "26c7bb06b8487cff1c7b3c44652b30f1"
}</pre>
</div>
</td>
</tr>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!-- Code generated by API-Reference-Code-Generator.py -->

<p>
The <code>/backtests/export/orders</code> API provides a response in the following format:
</p>
<h4>200 Success</h4>
<table class="table qc-table">
<thead>
<tr>
<th colspan="2"><code>text/csv</code> - Orders of the backtest, sorted by time.</th>
</tr>
</thead>
<tr>
<td width="20%">content</td> <td> <code>string</code> <br/> One row per order. The Time column is in UTC.</td>
</tr>
<tr>
<td width="20%">Example</td>
<td>
<div class="cli section-example-container"><pre>
Time,Symbol,Price,Quantity,Type,Status,Value,Tag
2024-01-02T15:00:00Z,IWM,195.236280785,500,Market,Filled,97618.1403925,"" </pre>
</div>
</td>
</tr>
</table>
<h4>401 Authentication Error</h4>
<table class="table qc-table">
<thead>
<tr>
<th colspan="2"><code>UnauthorizedError</code> Model - Unauthorized response from the API. Key is missing, invalid, or timestamp is too old for hash.</th>
</tr>
</thead>
<tr>
<td width="20%">www_authenticate</td> <td> <code>string</code> <br/> Header</td>
</tr>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<? include(DOCS_RESOURCES."/qc-api/examples/backtest-management.php");?>
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Code generated by API-Reference-Code-Generator.py -->

<p>
Download the closed trades of a backtest as a CSV file.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Code generated by API-Reference-Code-Generator.py -->

<p>
The CSV file has the same format as the file you get when you click <span class='button-name'>Download Trades</span> on the backtest results page. It contains the closed trades that the <a href='/docs/v2/cloud-platform/api-reference/backtest-management/read-backtest/trades'>/backtests/trades/read</a> endpoint returns, sorted by entry time.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Code generated by API-Reference-Code-Generator.py -->
<p>
Download the closed trades of the backtest Id provided. The <code>/backtests/export/trades</code> API accepts requests in the following format:
</p>
<table class="table qc-table">
<thead>
<tr>
<th colspan="2"><code>ExportBacktestTradesRequest</code> Model - Request to download the closed trades of a backtest.</th>
</tr>
</thead>
<tr>
<td width="20%">backtestId</td> <td> <code>string<br/><i><sub>required</sub></i><br/><i><sub>example: 26c7bb06b8487cff1c7b3c44652b30f1</sub></i></code> <br/> Id of the backtest from which to download the closed trades.</td>
</tr>
<tr>
<td width="20%">Example</td>
<td>
<div class="cli section-example-container"><pre>
{
"backtestId": "26c7bb06b8487cff1c7b3c44652b30f1"
}</pre>
</div>
</td>
</tr>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!-- Code generated by API-Reference-Code-Generator.py -->

<p>
The <code>/backtests/export/trades</code> API provides a response in the following format:
</p>
<h4>200 Success</h4>
<table class="table qc-table">
<thead>
<tr>
<th colspan="2"><code>text/csv</code> - Closed trades of the backtest, sorted by entry time.</th>
</tr>
</thead>
<tr>
<td width="20%">content</td> <td> <code>string</code> <br/> One row per closed trade. The Entry Time and Exit Time columns are in UTC.</td>
</tr>
<tr>
<td width="20%">Example</td>
<td>
<div class="cli section-example-container"><pre>
Entry Time,Symbols,Exit Time,Direction,Entry Price,Exit Price,Quantity,P&amp;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" </pre>
</div>
</td>
</tr>
</table>
<h4>401 Authentication Error</h4>
<table class="table qc-table">
<thead>
<tr>
<th colspan="2"><code>UnauthorizedError</code> Model - Unauthorized response from the API. Key is missing, invalid, or timestamp is too old for hash.</th>
</tr>
</thead>
<tr>
<td width="20%">www_authenticate</td> <td> <code>string</code> <br/> Header</td>
</tr>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<? include(DOCS_RESOURCES."/qc-api/examples/backtest-management.php");?>
Original file line number Diff line number Diff line change
@@ -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"
}
}
82 changes: 82 additions & 0 deletions QuantConnect-Platform-2.0.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <span class='button-name'>Download Orders</span> on the backtest results page. To get all the properties of the orders, call the <a href='/docs/v2/cloud-platform/api-reference/backtest-management/read-backtest/orders'>/backtests/orders/read</a> 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 <span class='button-name'>Download Trades</span> on the backtest results page. It contains the closed trades that the <a href='/docs/v2/cloud-platform/api-reference/backtest-management/read-backtest/trades'>/backtests/trades/read</a> 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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Resources/algorithm-results/orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<p>The timestamps in the Order Summary table are based in Eastern Time (ET).</p>

<h4>Access the Order Summary CSV</h4>
<p>To view the orders data in CSV format, open the <?=$pageName?> results page, click the <span class='tab-name'>Orders</span> tab, and then click <span class='button-name'>Download Orders</span>. 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). <? if ($pageName == "live") { ?>To download the CSV file with the API, call the <a href='/docs/v2/cloud-platform/api-reference/live-management/read-live-algorithm/export-orders'>/live/export/orders</a> endpoint. The CSV file only contains the orders from the last 750 days. To get older orders, call the <a href='/docs/v2/research-environment/meta-analysis/live-analysis#03-Plot-Order-Fills'><span class='csharp'>ReadLiveOrders</span><span class='python'>read_live_orders</span></a> method or the <a href='/docs/v2/cloud-platform/api-reference/live-management/read-live-algorithm/orders'>/live/orders/read</a> endpoint.<? } ?> <? if ($localPlatform) { ?>If you download the order summary CSV for a local backtest, the file is stored in <span class='public-file-name'><a href='/docs/v2/local-platform/development-environment/organization-workspaces'>&lt;organizationWorkspace&gt;</a> / &lt;projectName&gt; / backtests / &lt;unixTimestamp&gt; / orders.csv</span>.<? } ?></p>
<p>To view the orders data in CSV format, open the <?=$pageName?> results page, click the <span class='tab-name'>Orders</span> tab, and then click <span class='button-name'>Download Orders</span>. 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). <? if ($pageName == "live") { ?>To download the CSV file with the API, call the <a href='/docs/v2/cloud-platform/api-reference/live-management/read-live-algorithm/export-orders'>/live/export/orders</a> endpoint. The CSV file only contains the orders from the last 750 days. To get older orders, call the <a href='/docs/v2/research-environment/meta-analysis/live-analysis#03-Plot-Order-Fills'><span class='csharp'>ReadLiveOrders</span><span class='python'>read_live_orders</span></a> method or the <a href='/docs/v2/cloud-platform/api-reference/live-management/read-live-algorithm/orders'>/live/orders/read</a> endpoint.<? } ?> <? if ($pageName == "backtest" && !$localPlatform) { ?>To download the CSV file with the API, call the <a href='/docs/v2/cloud-platform/api-reference/backtest-management/read-backtest/export-orders'>/backtests/export/orders</a> endpoint.<? } ?> <? if ($localPlatform) { ?>If you download the order summary CSV for a local backtest, the file is stored in <span class='public-file-name'><a href='/docs/v2/local-platform/development-environment/organization-workspaces'>&lt;organizationWorkspace&gt;</a> / &lt;projectName&gt; / backtests / &lt;unixTimestamp&gt; / orders.csv</span>.<? } ?></p>

<? if ($pageName == "backtest") { ?>
<h4>Access the Orders JSON</h4>
Expand Down
2 changes: 1 addition & 1 deletion Resources/algorithm-results/trades.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<p>The timestamps in the Trades Summary table are based in Eastern Time (ET).</p>

<h4>Access the Trade Summary CSV</h4>
<p>To view the trades data in CSV format, open the <?=$pageName?> results page, click the <span class='tab-name'>Trades</span> tab, and then click <span class='button-name'>Download Trades</span>. 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). <? if ($pageName == "live") { ?>To download the CSV file with the API, call the <a href='/docs/v2/cloud-platform/api-reference/live-management/read-live-algorithm/export-trades'>/live/export/trades</a> endpoint.<? } ?> <? if ($localPlatform) { ?>If you download the trade summary CSV for a local backtest, the file is stored in <span class='public-file-name'><a href='/docs/v2/local-platform/development-environment/organization-workspaces'>&lt;organizationWorkspace&gt;</a> / &lt;projectName&gt; / backtests / &lt;unixTimestamp&gt; / trades.csv</span>.<? } ?></p>
<p>To view the trades data in CSV format, open the <?=$pageName?> results page, click the <span class='tab-name'>Trades</span> tab, and then click <span class='button-name'>Download Trades</span>. 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). <? if ($pageName == "live") { ?>To download the CSV file with the API, call the <a href='/docs/v2/cloud-platform/api-reference/live-management/read-live-algorithm/export-trades'>/live/export/trades</a> endpoint.<? } ?> <? if ($pageName == "backtest" && !$localPlatform) { ?>To download the CSV file with the API, call the <a href='/docs/v2/cloud-platform/api-reference/backtest-management/read-backtest/export-trades'>/backtests/export/trades</a> endpoint.<? } ?> <? if ($localPlatform) { ?>If you download the trade summary CSV for a local backtest, the file is stored in <span class='public-file-name'><a href='/docs/v2/local-platform/development-environment/organization-workspaces'>&lt;organizationWorkspace&gt;</a> / &lt;projectName&gt; / backtests / &lt;unixTimestamp&gt; / trades.csv</span>.<? } ?></p>

<? if ($pageName == "backtest") { ?>
<h4>Access the Trades JSON</h4>
Expand Down
20 changes: 19 additions & 1 deletion Resources/qc-api/examples/backtest-management.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,23 @@
# Check if the request was successful and print the list
if result['success']:
print("List of Backtests:")
print(result)</pre>
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)</pre>
</div>
Loading