adfad475cc
API Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
* refactor: adding OrderId in GroupOrderManger * feat: new support of OrderTypes in TradeStationBrokerageModel feat: unSupported OrderTypes in CanUpdateOrder's TradeStationBrokerageModel * feat: AllOrNone property in TradeStationOrderProperties * feat: unsupported SubmitCrossZero of Combo Order in TSBrokerageModel * test:feat: submit / update CrossZero Combo Orders * feat: new Message Brokerage error message refactor: use new Message in TradeStationBrokerageModel * feat: setter of Id in GroupOrderManager * feat: new constructor of GroupOrderManager * feat: develop GroupOrderCacheManager service * fix: groupOrderManger.Id in OrderProvider * fix: incrementOrderGroupOrderManagerID in BrokerageTransactionHandler feat: add _groupOrderManagerId in OrderProvider * remove: extra semicolon * refactor: prevent increment GroupOrderID * feat: add new Exchanges * feat: Try Get Group Combo Orders extension * refactor: ComboORderType in TSBrokerageModel * remove: implementing of prop ID in GroupOrderManager * refactor: UnsupportedCrossZeroByOrderType message * fix: warning of UnsupportedCrossZeroByOrderType * fix: several exchanges code based on tradier docs https://documentation.tradier.com/brokerage-api/reference/exchanges * feat: add missed Exchange in Global class * refactor: possible update LimitPrice in TSBrokerageModel test:feat: validate upddate LimitPrice of ComboLimit Order * refactor: GroupOrderCacheManager remove: TryGetGroupCachedOrders from extension * refactor: exchange SPHR to MIAX_SAPPHIRE * remove: Exchange BYX cuz It is BATS_Y * refactor: change position of Exchange C2 * refactor: change constructor's access modifier in class Exchange
92 lines
3.7 KiB
C#
92 lines
3.7 KiB
C#
/*
|
|
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
|
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace QuantConnect.Orders
|
|
{
|
|
/// <summary>
|
|
/// Provides a thread-safe service for caching and managing original orders when they are part of a group.
|
|
/// </summary>
|
|
public class GroupOrderCacheManager
|
|
{
|
|
/// <summary>
|
|
/// A thread-safe dictionary that caches original orders when they are part of a group.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The dictionary uses the order ID as the key and stores the original <see cref="Order"/> objects as values.
|
|
/// This allows for the modification of the original orders, such as setting the brokerage ID,
|
|
/// without retrieving a cloned instance from the order provider.
|
|
/// </remarks>
|
|
private readonly ConcurrentDictionary<int, Order> _pendingGroupOrders = new();
|
|
|
|
/// <summary>
|
|
/// Attempts to retrieve all the orders in the combo group from the cache.
|
|
/// </summary>
|
|
/// <param name="order">Target order, which can be any of the legs of the combo</param>
|
|
/// <param name="orders">List of orders in the combo</param>
|
|
/// <returns>
|
|
/// <c>true</c> if all the orders in the combo group were successfully retrieved from the cache;
|
|
/// otherwise, <c>false</c>. If the retrieval fails, the target order is cached for future retrieval.
|
|
/// </returns>
|
|
public bool TryGetGroupCachedOrders(Order order, out List<Order> orders)
|
|
{
|
|
if (!order.TryGetGroupOrders(TryGetOrder, out orders))
|
|
{
|
|
// some order of the group is missing but cache the new one
|
|
CacheOrder(order);
|
|
return false;
|
|
}
|
|
RemoveCachedOrders(orders);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to retrieve an original order from the cache using the specified order ID.
|
|
/// </summary>
|
|
/// <param name="orderId">The unique identifier of the order to retrieve.</param>
|
|
/// <returns>
|
|
/// The original <see cref="Order"/> if found; otherwise, <c>null</c>.
|
|
/// </returns>
|
|
private Order TryGetOrder(int orderId)
|
|
{
|
|
_pendingGroupOrders.TryGetValue(orderId, out var order);
|
|
return order;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Caches an original order in the internal dictionary for future retrieval.
|
|
/// </summary>
|
|
/// <param name="order">The <see cref="Order"/> object to cache.</param>
|
|
private void CacheOrder(Order order)
|
|
{
|
|
_pendingGroupOrders[order.Id] = order;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes a list of orders from the internal cache.
|
|
/// </summary>
|
|
/// <param name="orders">The list of <see cref="Order"/> objects to remove from the cache.</param>
|
|
private void RemoveCachedOrders(List<Order> orders)
|
|
{
|
|
for (var i = 0; i < orders.Count; i++)
|
|
{
|
|
_pendingGroupOrders.TryRemove(orders[i].Id, out _);
|
|
}
|
|
}
|
|
}
|
|
}
|