diff --git a/04 Research Environment/10 Meta Analysis/05 Live Reconciliation/05 Plot Order Fills.php b/04 Research Environment/10 Meta Analysis/05 Live Reconciliation/05 Plot Order Fills.php index d613a72ce8..b0821343c2 100644 --- a/04 Research Environment/10 Meta Analysis/05 Live Reconciliation/05 Plot Order Fills.php +++ b/04 Research Environment/10 Meta Analysis/05 Live Reconciliation/05 Plot Order Fills.php @@ -1,37 +1,67 @@
Follow these steps to overlay live and OOS backtest order fills on a single marker-only chart per symbol. The chart deliberately omits candlesticks and any price history so the comparison between live and backtest executions is not drowned out by other series.
ReadLiveOrdersread_live_orders and ReadBacktestOrdersread_backtest_orders returns at most 100 orders, so paginate in 100-Id windows until the endpoint returns an empty window. The first window can take a few seconds to load, so retry while it is empty.List<ApiOrderResponse> ReadOrders(Func<List<ApiOrderResponse>> fetch)
+ List<ApiOrderResponse> ReadAllOrders(Func<int, int, List<ApiOrderResponse>> fetchWindow)
{
+ var all = new List<ApiOrderResponse>();
+ // Retry the first window while the response is empty (may be loading).
+ List<ApiOrderResponse> first = null;
for (var attempt = 0; attempt < 10; attempt++)
{
- var result = fetch();
- if (result.Any()) return result;
+ first = fetchWindow(0, 100);
+ if (first.Any()) break;
Console.WriteLine($"Orders loading... (attempt {attempt + 1}/10)");
Thread.Sleep(10000);
}
- throw new Exception("Failed to read orders after 10 attempts");
+ if (first == null || !first.Any()) return all;
+ all.AddRange(first);
+ // Paginate in 100-Id windows until the endpoint returns an empty window.
+ var start = 100;
+ while (true)
+ {
+ var window = fetchWindow(start, start + 100);
+ if (!window.Any()) break;
+ all.AddRange(window);
+ start += 100;
+ }
+ return all;
}
-var liveOrders = ReadOrders(() => api.ReadLiveOrders(projectId, 0, 100));
-var backtestOrders = ReadOrders(() => api.ReadBacktestOrders(projectId, backtestId, 0, 100));
+var liveOrders = ReadAllOrders((s, e) => api.ReadLiveOrders(projectId, s, e));
+var backtestOrders = ReadAllOrders((s, e) => api.ReadBacktestOrders(projectId, backtestId, s, e));
+Console.WriteLine($"Live orders: {liveOrders.Count}, OOS orders: {backtestOrders.Count}");
from time import sleep
-def read_orders(fetch):
+def read_all_orders(fetch_window):
+ orders = []
+ # Retry the first window while the response is empty (may be loading).
+ first = []
for attempt in range(10):
- result = fetch()
- if result:
- return result
+ first = fetch_window(0, 100)
+ if first:
+ break
print(f"Orders loading... (attempt {attempt + 1}/10)")
sleep(10)
- raise RuntimeError("Failed to read orders after 10 attempts")
-
-live_orders = read_orders(lambda: api.read_live_orders(project_id, 0, 100))
-backtest_orders = read_orders(lambda: api.read_backtest_orders(project_id, backtest_id, 0, 100))
+ if not first:
+ return orders
+ orders.extend(first)
+ # Paginate in 100-Id windows until the endpoint returns an empty window.
+ start = 100
+ while True:
+ window = fetch_window(start, start + 100)
+ if not window:
+ break
+ orders.extend(window)
+ start += 100
+ return orders
+
+live_orders = read_all_orders(lambda s, e: api.read_live_orders(project_id, s, e))
+backtest_orders = read_all_orders(lambda s, e: api.read_backtest_orders(project_id, backtest_id, s, e))
+print(f"Live orders: {len(live_orders)}, OOS orders: {len(backtest_orders)}")
By default, you receive the orders with an Id between 0 and 100. To read more, call the method repeatedly in windows of up to 100 Ids. For more on the order objects returned, see Plot Order Fills in the Live Analysis documentation.
+For more on the order objects returned, see Plot Order Fills in the Live Analysis documentation.
stop_live_algorithm - Stop a live algorithm.liquidate_live_algorithm - Liquidate and stop a live algorithm.The following tools operate on a Jupyter notebook in the QuantConnect Cloud Research environment:
+jupyter_create_cell - Insert a new Jupyter notebook cell. By default the cell is appended; provide an index to insert at a specific zero-based position.jupyter_read_cell - Return the source lines for a single notebook cell at a zero-based index.jupyter_update_cell - Replace the source of an existing notebook cell at a zero-based index.jupyter_delete_cell - Delete a notebook cell at a zero-based index.jupyter_execute_cell - Execute one code cell by zero-based index and return its captured outputs.jupyter_create_notebook - Replace the current notebook with raw notebook JSON content.jupyter_read_notebook - Return the full current notebook as a raw JSON string.jupyter_execute_notebook - Execute all notebook cells in order and return aggregated outputs from code cells.The following tools fetch financial news and blog posts from a curated list of more than 20 sources:
+financial_data_blog_posts - Fetch recent financial blog posts.financial_data_web_get - Fetch the full content of a web page given its URL. Use this to read blog posts and articles.environment_library_support - Fetch the list of available preinstalled libraries in the QuantConnect environment.datasets - Fetch the list of available QuantConnect datasets.+ The following tools send messages from QuantConnect Cloud to you using the Live Trading Notifications system: +
+send_email_notification - Send an email notification.send_sms_notification - Send an SMS notification.send_telegram_notification - Send a Telegram notification.