From 1c33d57310caab165585d5680e57d142ad0761a7 Mon Sep 17 00:00:00 2001 From: Alexandre Catarino Date: Thu, 15 Oct 2026 19:16:29 +0100 Subject: [PATCH] Document the live orders and trades export endpoints (#2773) Add /live/export/orders and /live/export/trades to the API reference, render CSV responses in the generator, add an example that builds the full orders CSV, link the endpoints from the results pages, and add the missing live Trades results page. /live/orders/read filters on deployId, not algorithmId. Co-Authored-By: Claude Opus 5.5 --- .../10 Live Trading/07 Results/10 Trades.php | 4 + .../02 Read Live Algorithm/00.json | 4 +- .../04 Orders/02 Request.html | 4 +- .../08 Export Orders/01 Introduction.html | 5 + .../08 Export Orders/02 Description.html | 5 + .../08 Export Orders/03 Request.html | 32 ++++++ .../08 Export Orders/04 Responses.html | 36 ++++++ .../08 Export Orders/99 Examples.php | 1 + .../08 Export Orders/metadata.json | 12 ++ .../09 Export Trades/01 Introduction.html | 5 + .../09 Export Trades/02 Description.html | 5 + .../09 Export Trades/03 Request.html | 28 +++++ .../09 Export Trades/04 Responses.html | 36 ++++++ .../09 Export Trades/99 Examples.php | 1 + .../09 Export Trades/metadata.json | 12 ++ QuantConnect-Platform-2.0.0.yaml | 104 +++++++++++++++++- Resources/algorithm-results/orders.php | 2 +- Resources/algorithm-results/trades.php | 2 +- Resources/qc-api/examples/live-management.php | 74 ++++++++++++- .../API-Reference-Code-Generator.py | 21 ++++ 20 files changed, 385 insertions(+), 8 deletions(-) create mode 100644 01 Cloud Platform/10 Live Trading/07 Results/10 Trades.php create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/01 Introduction.html create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/02 Description.html create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/03 Request.html create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/04 Responses.html create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/99 Examples.php create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/metadata.json create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/01 Introduction.html create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/02 Description.html create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/03 Request.html create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/04 Responses.html create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/99 Examples.php create mode 100644 01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/metadata.json diff --git a/01 Cloud Platform/10 Live Trading/07 Results/10 Trades.php b/01 Cloud Platform/10 Live Trading/07 Results/10 Trades.php new file mode 100644 index 0000000000..d9cbe7b208 --- /dev/null +++ b/01 Cloud Platform/10 Live Trading/07 Results/10 Trades.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/00.json b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/00.json index 2a6d466175..9ce3bc9b91 100644 --- a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/00.json +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/00.json @@ -12,6 +12,8 @@ "04" : "", "05" : "", "06" : "", - "07" : "" + "07" : "", + "08" : "", + "09" : "" } } diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/04 Orders/02 Request.html b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/04 Orders/02 Request.html index 1646898bac..ab8d5866ec 100644 --- a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/04 Orders/02 Request.html +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/04 Orders/02 Request.html @@ -9,7 +9,7 @@ -algorithmId string
example: L-6e9d8a78f5af89d401f630585be90e43

Deploy Id (Algorithm Id) of the live running algorithm. +deployId string
example: L-6e9d8a78f5af89d401f630585be90e43

Deploy Id of the live algorithm. When you provide it, the response contains the orders of that deployment. When you omit it, the response contains the orders of every deployment of the project. start integer
required
example: 0

Starting index of the orders to be fetched. @@ -25,7 +25,7 @@
 {
-  "algorithmId": "L-6e9d8a78f5af89d401f630585be90e43",
+  "deployId": "L-6e9d8a78f5af89d401f630585be90e43",
   "start": 0,
   "end": 100,
   "projectId": 23456789
diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/01 Introduction.html b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/01 Introduction.html
new file mode 100644
index 0000000000..027b5b6637
--- /dev/null
+++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/01 Introduction.html	
@@ -0,0 +1,5 @@
+
+                            
+

+Download the orders of all the live deployments of a project as a CSV file. +

diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/02 Description.html b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/02 Description.html new file mode 100644 index 0000000000..0396cd8558 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 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 live results page. The response contains at most 750 days of orders. If the date range is longer, the response contains the last 750 days of the range. To get older orders, call the endpoint again with an earlier end or call the /live/orders/read endpoint. The response can contain orders outside of the date range. To get an exact range, filter the rows by their Time value. +

diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/03 Request.html b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/03 Request.html new file mode 100644 index 0000000000..398e885560 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/03 Request.html @@ -0,0 +1,32 @@ + +

+Download the orders of a project for the date range provided. The /live/export/orders API accepts requests in the following format: +

+ + + + + + + + + + + + + + + + + + + +
ExportLiveOrdersRequest Model - Request to download the orders of the live deployments of a project.
projectId integer
required
example: 23456789

Id of the project from which to download the orders.
start integer
example: 1727222400

Start of the date range in Unix time (seconds). The default value is one hour before the first deployment of the project.
end integer
example: 1792022400

End of the date range in Unix time (seconds). The default value is the current time.
Example +
+{
+  "projectId": 23456789,
+  "start": 1727222400,
+  "end": 1792022400
+}
+
+
\ No newline at end of file diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/04 Responses.html b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/04 Responses.html new file mode 100644 index 0000000000..cbdc735ed0 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/04 Responses.html @@ -0,0 +1,36 @@ + + +

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

+

200 Success

+ + + + + + + + + + + + + +
text/csv - Orders of the live deployments of the project, sorted by time.
content string
One row per order. The Time column is in UTC.
Example +
+Deploy,Time,Symbol,Price,Quantity,Type,Status,Value,Tag
+L-6e9d8a78f5af89d401f630585be90e43,2026-10-08T14:20:04.8005773Z,SPY,672.35,10,"Market","Filled",6723.5,"" 
+
+
+

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/07 Live Management/02 Read Live Algorithm/08 Export Orders/99 Examples.php b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/99 Examples.php new file mode 100644 index 0000000000..7a7178cf85 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/99 Examples.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/metadata.json b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/metadata.json new file mode 100644 index 0000000000..1855245abf --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/08 Export Orders/metadata.json @@ -0,0 +1,12 @@ +{ + "type": "metadata", + "values": { + "description": "Download the orders of all the live deployments of a project as a CSV file.", + "keywords": "api, live trading, export orders, csv, live management", + "og:description": "Download the orders of all the live deployments of a project 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/live-management/read-live-algorithm/export-orders.png" + } +} diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/01 Introduction.html b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/01 Introduction.html new file mode 100644 index 0000000000..653beee989 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/01 Introduction.html @@ -0,0 +1,5 @@ + + +

+Download the closed trades of all the live deployments of a project as a CSV file. +

diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/02 Description.html b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/02 Description.html new file mode 100644 index 0000000000..5c6dab9f94 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/02 Description.html @@ -0,0 +1,5 @@ + + +

+The CSV file contains the closed trades that the /live/trades/read endpoint returns for the project. The response contains the trades with an entry time at or after start. +

diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/03 Request.html b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/03 Request.html new file mode 100644 index 0000000000..99a6bcd669 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/03 Request.html @@ -0,0 +1,28 @@ + +

+Download the closed trades of a project from the start time provided. The /live/export/trades API accepts requests in the following format: +

+ + + + + + + + + + + + + + + + +
ExportLiveTradesRequest Model - Request to download the closed trades of the live deployments of a project.
projectId integer
required
example: 23456789

Id of the project from which to download the closed trades.
start integer
example: 1727222400

Earliest entry time of the trades in Unix time (seconds). The default value is one hour before the first deployment of the project.
Example +
+{
+  "projectId": 23456789,
+  "start": 1727222400
+}
+
+
\ No newline at end of file diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/04 Responses.html b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/04 Responses.html new file mode 100644 index 0000000000..0bf73a4404 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/04 Responses.html @@ -0,0 +1,36 @@ + + +

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

+

200 Success

+ + + + + + + + + + + + + +
text/csv - Closed trades of the live deployments of the project.
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
+2026-10-09T14:17:04.8008663Z,"SPY",2026-10-09T18:06:03.8005312Z,Buy,670.08,672.61,10,25.3,2,-8.9,25.3,8.9,1,"	276,308" 
+
+
+

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/07 Live Management/02 Read Live Algorithm/09 Export Trades/99 Examples.php b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/99 Examples.php new file mode 100644 index 0000000000..7a7178cf85 --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/99 Examples.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/metadata.json b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/metadata.json new file mode 100644 index 0000000000..22e486869b --- /dev/null +++ b/01 Cloud Platform/99 API Reference/07 Live Management/02 Read Live Algorithm/09 Export Trades/metadata.json @@ -0,0 +1,12 @@ +{ + "type": "metadata", + "values": { + "description": "Download the closed trades of all the live deployments of a project as a CSV file.", + "keywords": "api, live trading, export trades, csv, live management", + "og:description": "Download the closed trades of all the live deployments of a project 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/live-management/read-live-algorithm/export-trades.png" + } +} diff --git a/QuantConnect-Platform-2.0.0.yaml b/QuantConnect-Platform-2.0.0.yaml index 72ee99723f..e82c0312c8 100644 --- a/QuantConnect-Platform-2.0.0.yaml +++ b/QuantConnect-Platform-2.0.0.yaml @@ -1039,6 +1039,66 @@ paths: "401": $ref: '#/components/responses/UnauthorizedErrorResponse' operationId: readLiveAlgorithmTrades + /live/export/orders: + post: + tags: + - 01 Cloud Platform + - 99 API Reference + - 07 Live Management + - 02 Read Live Algorithm + - 08 Export Orders + summary: Download the orders of all the live deployments of a project as a CSV file. + description: "The CSV file has the same format as the file you get when you click Download Orders on the live results page. The response contains at most 750 days of orders. If the date range is longer, the response contains the last 750 days of the range. To get older orders, call the endpoint again with an earlier end or call the /live/orders/read endpoint. The response can contain orders outside of the date range. To get an exact range, filter the rows by their Time value." + requestBody: + description: Download the orders of a project for the date range provided. + content: + application/json: + schema: + $ref: '#/components/schemas/ExportLiveOrdersRequest' + required: true + responses: + "200": + description: Orders of the live deployments of the project, sorted by time. + content: + text/csv: + schema: + type: string + description: "One row per order. The Time column is in UTC." + examples: + - "Deploy,Time,Symbol,Price,Quantity,Type,Status,Value,Tag\nL-6e9d8a78f5af89d401f630585be90e43,2026-10-08T14:20:04.8005773Z,SPY,672.35,10,\"Market\",\"Filled\",6723.5,\"\" " + "401": + $ref: '#/components/responses/UnauthorizedErrorResponse' + operationId: exportLiveAlgorithmOrders + /live/export/trades: + post: + tags: + - 01 Cloud Platform + - 99 API Reference + - 07 Live Management + - 02 Read Live Algorithm + - 09 Export Trades + summary: Download the closed trades of all the live deployments of a project as a CSV file. + description: "The CSV file contains the closed trades that the /live/trades/read endpoint returns for the project. The response contains the trades with an entry time at or after start." + requestBody: + description: Download the closed trades of a project from the start time provided. + content: + application/json: + schema: + $ref: '#/components/schemas/ExportLiveTradesRequest' + required: true + responses: + "200": + description: Closed trades of the live deployments of the project. + 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\n2026-10-09T14:17:04.8008663Z,\"SPY\",2026-10-09T18:06:03.8005312Z,Buy,670.08,672.61,10,25.3,2,-8.9,25.3,8.9,1,\"\t276,308\" " + "401": + $ref: '#/components/responses/UnauthorizedErrorResponse' + operationId: exportLiveAlgorithmTrades /live/insights/read: post: tags: @@ -6981,11 +7041,14 @@ components: - projectId type: object properties: - algorithmId: + deployId: type: string - description: Deploy Id (Algorithm Id) of the live running algorithm. examples: - L-6e9d8a78f5af89d401f630585be90e43 + description: >- + Deploy Id of the live algorithm. When you provide it, the response contains the orders + of that deployment. When you omit it, the response contains the orders of every + deployment of the project. start: type: integer examples: @@ -7002,6 +7065,43 @@ components: - 23456789 description: Id of the project from which to read the live algorithm. description: Request to read orders from a live algorithm. + ExportLiveOrdersRequest: + required: + - projectId + type: object + properties: + projectId: + type: integer + examples: + - 23456789 + description: Id of the project from which to download the orders. + start: + type: integer + examples: + - 1727222400 + description: Start of the date range in Unix time (seconds). The default value is one hour before the first deployment of the project. + end: + type: integer + examples: + - 1792022400 + description: End of the date range in Unix time (seconds). The default value is the current time. + description: Request to download the orders of the live deployments of a project. + ExportLiveTradesRequest: + required: + - projectId + type: object + properties: + projectId: + type: integer + examples: + - 23456789 + description: Id of the project from which to download the closed trades. + start: + type: integer + examples: + - 1727222400 + description: Earliest entry time of the trades in Unix time (seconds). The default value is one hour before the first deployment of the project. + description: Request to download the closed trades of the live deployments of a project. ReadLiveTradesRequest: required: - start diff --git a/Resources/algorithm-results/orders.php b/Resources/algorithm-results/orders.php index 038e3fc6e6..b95ff15647 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). 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. 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 232f9782cd..e7cd0be5e1 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). 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. 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/live-management.php b/Resources/qc-api/examples/live-management.php index 84b7765e88..78f5c35d0d 100644 --- a/Resources/qc-api/examples/live-management.php +++ b/Resources/qc-api/examples/live-management.php @@ -97,5 +97,77 @@ # Check if the request was successful and print the list if result['success']: print("List of Live Algorithms:") - print(result)
+ print(result) + +### Export Orders +from decimal import Decimal +from time import sleep + +# Download the orders of the last 750 days as a CSV file +payload = { + "projectId": project_id # ID of the project +} +response = post(f'{BASE_URL}/live/export/orders', headers=get_headers(), json=payload) +rows = response.text.splitlines() +header, recent = rows[0], rows[1:] +# The export starts at its first row. Older orders come from the /live/orders/read endpoint. +cutoff = recent[0].split(',')[1][:19].replace('T', ' ') if recent else '9999' + +# Map the order type and status enums to the names in the CSV file +order_types = ["Market", "Limit", "Stop Market", "Stop Limit", "Market On Open", "Market On Close", + "Option Exercise", "Limit If Touched", "Combo Market", "Combo Limit", "Combo Leg Limit", "Trailing Stop"] +order_statuses = ["New", "Submitted", "Partially Filled", "Filled", "", "Canceled", "None", "Invalid", + "Cancel Pending", "Update Submitted"] + +def number(value): + text = format(Decimal(str(value)), 'f') + return text.rstrip('0').rstrip('.') if '.' in text else text + +# Read the older orders of each deployment that started before the cutoff +older = [] +response = post(f'{BASE_URL}/live/list', headers=get_headers(), json={"projectId": project_id}) +deployments = sorted(response.json()['live'], key=lambda x: x['launched']) +for deployment in deployments: + if deployment['launched'] >= cutoff: + continue + start = 0 + while True: + payload = { + "projectId": project_id, # ID of the project + "deployId": deployment['deployId'], # ID of the deployment + "start": start, # Starting index for orders + "end": start + 1000 # Ending index for orders + } + result = post(f'{BASE_URL}/live/orders/read', headers=get_headers(), json=payload).json() + # The first request can return a loading status while the orders are prepared + if result.get('status') == 'loading': + sleep(1) + continue + for order in result['orders']: + if order['time'][:19].replace('T', ' ') >= cutoff: + continue + older.append(','.join([ + deployment['deployId'], order['time'], order['symbol']['value'], + number(order['price']), number(order['quantity']), + f'"{order_types[order["type"]]}"', f'"{order_statuses[order["status"]]}"', + number(order['value']), '"' + order['tag'].replace('"', '""') + '" ' + ])) + start += 1000 + if start >= result['length']: + break + +# Save all the orders in one CSV file +with open(f'orders-{project_id}.csv', 'w', newline='') as file: + file.write('\n'.join([header] + older + recent) + '\n') +print(f"Saved {len(older) + len(recent)} orders") + +### Export Trades +# Download the closed trades that opened since the start time as a CSV file +payload = { + "projectId": project_id, # ID of the project + "start": 1717801200 # Start time (Unix timestamp) for the trade entry time +} +response = post(f'{BASE_URL}/live/export/trades', headers=get_headers(), json=payload) +with open(f'trades-{project_id}.csv', 'w', newline='') as file: + file.write(response.text)
\ No newline at end of file diff --git a/code-generators/API-Reference-Code-Generator.py b/code-generators/API-Reference-Code-Generator.py index 42c85c0004..c91c9e3c23 100644 --- a/code-generators/API-Reference-Code-Generator.py +++ b/code-generators/API-Reference-Code-Generator.py @@ -8,6 +8,7 @@ python API-Reference-Code-Generator.py """ +import html import json import pathlib @@ -844,8 +845,28 @@ def _write_responses(self, api_call, content, dest, page): elif code == "default": f.write("

Default Generic Error

\n") + csv = props.get("content", {}).get("text/csv") + if csv: + f.write(self._build_csv_table(props, csv["schema"])) + continue + f.write(self._build_schema_tables(props)) + @staticmethod + def _build_csv_table(wrapper, schema): + """Build the table for a response that is a CSV file.""" + example = html.escape(schema["examples"][0], quote=False) + return ( + '\n\n\n' + f'\n' + "\n\n\n" + f'\n' + "\n\n" + '\n\n\n
text/csv - {wrapper["description"]}
content string
{schema["description"]}
Example\n' + f'
\n{example}
\n
\n' + "
\n" + ) + # ------------------------------------------------------------------ # # Entry point #