cleanup: archive legacy-orders and placeholders, remove tombstone and backup files
This commit is contained in:
@@ -1,143 +0,0 @@
|
||||
using NT8.Core.Common.Models;
|
||||
using NT8.Core.Risk;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
// ARCHIVED: This namespace (NT8.Core.Orders) is superseded by NT8.Core.OMS.
|
||||
// NT8.Core.OMS is the canonical order management implementation used by NT8StrategyBase.
|
||||
// These files are retained for reference only and are not referenced by any active code.
|
||||
// Do not add new code here. Do not remove these files until a full audit confirms zero references.
|
||||
|
||||
namespace NT8.Core.Orders
|
||||
{
|
||||
/// <summary>
|
||||
/// Order management interface - handles order submission, routing, and execution
|
||||
/// </summary>
|
||||
public interface IOrderManager
|
||||
{
|
||||
#region Order Submission and Management
|
||||
|
||||
/// <summary>
|
||||
/// Submit a new order for execution
|
||||
/// </summary>
|
||||
Task<OrderResult> SubmitOrderAsync(OrderRequest request, StrategyContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Cancel an existing order
|
||||
/// </summary>
|
||||
Task<bool> CancelOrderAsync(string orderId);
|
||||
|
||||
/// <summary>
|
||||
/// Modify an existing order
|
||||
/// </summary>
|
||||
Task<OrderResult> ModifyOrderAsync(string orderId, OrderModification modification);
|
||||
|
||||
/// <summary>
|
||||
/// Get order status
|
||||
/// </summary>
|
||||
Task<OrderStatus> GetOrderStatusAsync(string orderId);
|
||||
|
||||
/// <summary>
|
||||
/// Get all orders for a symbol
|
||||
/// </summary>
|
||||
Task<List<OrderStatus>> GetOrdersBySymbolAsync(string symbol);
|
||||
|
||||
/// <summary>
|
||||
/// Get all active orders
|
||||
/// </summary>
|
||||
Task<List<OrderStatus>> GetActiveOrdersAsync();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Algorithmic Execution
|
||||
|
||||
/// <summary>
|
||||
/// Execute a TWAP order
|
||||
/// </summary>
|
||||
Task<OrderResult> ExecuteTwapAsync(TwapParameters parameters, StrategyContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Execute a VWAP order
|
||||
/// </summary>
|
||||
Task<OrderResult> ExecuteVwapAsync(VwapParameters parameters, StrategyContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Execute an Iceberg order
|
||||
/// </summary>
|
||||
Task<OrderResult> ExecuteIcebergAsync(IcebergParameters parameters, StrategyContext context);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Smart Order Routing
|
||||
|
||||
/// <summary>
|
||||
/// Route order based on smart routing logic
|
||||
/// </summary>
|
||||
Task<RoutingResult> RouteOrderAsync(OrderRequest request, StrategyContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Get available execution venues
|
||||
/// </summary>
|
||||
List<ExecutionVenue> GetAvailableVenues();
|
||||
|
||||
/// <summary>
|
||||
/// Get routing performance metrics
|
||||
/// </summary>
|
||||
RoutingMetrics GetRoutingMetrics();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Risk Integration
|
||||
|
||||
/// <summary>
|
||||
/// Validate order against risk parameters
|
||||
/// </summary>
|
||||
Task<RiskDecision> ValidateOrderAsync(OrderRequest request, StrategyContext context);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Configuration and Management
|
||||
|
||||
/// <summary>
|
||||
/// Update routing configuration
|
||||
/// </summary>
|
||||
void UpdateRoutingConfig(RoutingConfig config);
|
||||
|
||||
/// <summary>
|
||||
/// Get current routing configuration
|
||||
/// </summary>
|
||||
RoutingConfig GetRoutingConfig();
|
||||
|
||||
/// <summary>
|
||||
/// Update algorithm parameters
|
||||
/// </summary>
|
||||
void UpdateAlgorithmParameters(AlgorithmParameters parameters);
|
||||
|
||||
/// <summary>
|
||||
/// Get current algorithm parameters
|
||||
/// </summary>
|
||||
AlgorithmParameters GetAlgorithmParameters();
|
||||
|
||||
/// <summary>
|
||||
/// Reset OMS state
|
||||
/// </summary>
|
||||
void Reset();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Monitoring and Metrics
|
||||
|
||||
/// <summary>
|
||||
/// Get OMS performance metrics
|
||||
/// </summary>
|
||||
OmsMetrics GetMetrics();
|
||||
|
||||
/// <summary>
|
||||
/// Check if OMS is healthy
|
||||
/// </summary>
|
||||
bool IsHealthy();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,856 +0,0 @@
|
||||
using NT8.Core.Common.Models;
|
||||
using NT8.Core.Risk;
|
||||
using NT8.Core.Sizing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
// ARCHIVED: This namespace (NT8.Core.Orders) is superseded by NT8.Core.OMS.
|
||||
// NT8.Core.OMS is the canonical order management implementation used by NT8StrategyBase.
|
||||
// These files are retained for reference only and are not referenced by any active code.
|
||||
// Do not add new code here. Do not remove these files until a full audit confirms zero references.
|
||||
|
||||
namespace NT8.Core.Orders
|
||||
{
|
||||
/// <summary>
|
||||
/// Order manager implementation with smart routing and algorithmic execution
|
||||
/// </summary>
|
||||
public class OrderManager : IOrderManager
|
||||
{
|
||||
private readonly IRiskManager _riskManager;
|
||||
private readonly IPositionSizer _positionSizer;
|
||||
private readonly ILogger<OrderManager> _logger;
|
||||
private readonly object _lock = new object();
|
||||
|
||||
// Configuration
|
||||
private RoutingConfig _routingConfig;
|
||||
private AlgorithmParameters _algorithmParameters;
|
||||
|
||||
// State
|
||||
private readonly Dictionary<string, OrderStatus> _orders;
|
||||
private readonly Dictionary<string, ExecutionVenue> _venues;
|
||||
private readonly RoutingMetrics _routingMetrics;
|
||||
private readonly OmsMetrics _omsMetrics;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for OrderManager
|
||||
/// </summary>
|
||||
public OrderManager(
|
||||
IRiskManager riskManager,
|
||||
IPositionSizer positionSizer,
|
||||
ILogger<OrderManager> logger)
|
||||
{
|
||||
if (riskManager == null) throw new ArgumentNullException("riskManager");
|
||||
if (positionSizer == null) throw new ArgumentNullException("positionSizer");
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
|
||||
_riskManager = riskManager;
|
||||
_positionSizer = positionSizer;
|
||||
_logger = logger;
|
||||
|
||||
_orders = new Dictionary<string, OrderStatus>();
|
||||
_venues = new Dictionary<string, ExecutionVenue>();
|
||||
|
||||
var venuePerformance = new Dictionary<string, VenueMetrics>();
|
||||
_routingMetrics = new RoutingMetrics(venuePerformance, 0, 0.0, DateTime.UtcNow);
|
||||
|
||||
_omsMetrics = new OmsMetrics(0, 0, 0, 0.0, 0.0, 0.0, 0, DateTime.UtcNow);
|
||||
|
||||
InitializeDefaultConfig();
|
||||
InitializeVenues();
|
||||
}
|
||||
|
||||
private void InitializeDefaultConfig()
|
||||
{
|
||||
var venuePreferences = new Dictionary<string, double>();
|
||||
venuePreferences.Add("Primary", 1.0);
|
||||
venuePreferences.Add("Secondary", 0.8);
|
||||
|
||||
_routingConfig = new RoutingConfig(
|
||||
true, // SmartRoutingEnabled
|
||||
"Primary", // DefaultVenue
|
||||
venuePreferences,
|
||||
0.5, // MaxSlippagePercent
|
||||
TimeSpan.FromSeconds(30), // MaxRoutingTime
|
||||
true, // RouteByCost
|
||||
true, // RouteBySpeed
|
||||
true // RouteByReliability
|
||||
);
|
||||
|
||||
var twapConfig = new TwapConfig(TimeSpan.FromMinutes(15), 30, true);
|
||||
var vwapConfig = new VwapConfig(0.1, true);
|
||||
var icebergConfig = new IcebergConfig(0.1, true);
|
||||
|
||||
_algorithmParameters = new AlgorithmParameters(twapConfig, vwapConfig, icebergConfig);
|
||||
}
|
||||
|
||||
private void InitializeVenues()
|
||||
{
|
||||
var primaryVenue = new ExecutionVenue(
|
||||
"Primary", "Primary execution venue", true, 1.0, 1.0, 0.99);
|
||||
_venues.Add("Primary", primaryVenue);
|
||||
|
||||
var secondaryVenue = new ExecutionVenue(
|
||||
"Secondary", "Backup execution venue", true, 1.2, 0.9, 0.95);
|
||||
_venues.Add("Secondary", secondaryVenue);
|
||||
}
|
||||
|
||||
#region Order Submission and Management
|
||||
|
||||
/// <summary>
|
||||
/// Submit a new order for execution
|
||||
/// </summary>
|
||||
public async Task<OrderResult> SubmitOrderAsync(OrderRequest request, StrategyContext context)
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException("request");
|
||||
if (context == null) throw new ArgumentNullException("context");
|
||||
|
||||
try
|
||||
{
|
||||
_logger.LogInformation(String.Format("Submitting order for {0} {1} {2}",
|
||||
request.Symbol, request.Side, request.Quantity));
|
||||
|
||||
// 1. Validate order through risk management
|
||||
var riskDecision = await ValidateOrderAsync(request, context);
|
||||
if (!riskDecision.Allow)
|
||||
{
|
||||
_logger.LogWarning(String.Format("Order rejected by risk management: {0}", riskDecision.RejectReason));
|
||||
return new OrderResult(false, null, riskDecision.RejectReason, null);
|
||||
}
|
||||
|
||||
// 2. Route order based on smart routing logic
|
||||
var routingResult = await RouteOrderAsync(request, context);
|
||||
if (!routingResult.Success)
|
||||
{
|
||||
_logger.LogError(String.Format("Order routing failed: {0}", routingResult.Message));
|
||||
return new OrderResult(false, null, routingResult.Message, null);
|
||||
}
|
||||
|
||||
// 3. Submit to selected venue (simulated)
|
||||
var orderId = Guid.NewGuid().ToString();
|
||||
|
||||
var fills = new List<OrderFill>();
|
||||
var orderStatus = new OrderStatus(
|
||||
orderId, request.Symbol, request.Side, request.Type, request.Quantity, 0,
|
||||
request.LimitPrice, request.StopPrice, OrderState.Submitted, DateTime.UtcNow, null,
|
||||
fills);
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_orders[orderId] = orderStatus;
|
||||
UpdateOmsMetrics();
|
||||
}
|
||||
|
||||
_logger.LogInformation(String.Format("Order {0} submitted to {1}", orderId, routingResult.SelectedVenue.Name));
|
||||
|
||||
return new OrderResult(true, orderId, "Order submitted successfully", orderStatus);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(String.Format("Error submitting order for {0}: {1}", request.Symbol, ex.Message));
|
||||
return new OrderResult(false, null, String.Format("Error submitting order: {0}", ex.Message), null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancel an existing order
|
||||
/// </summary>
|
||||
public async Task<bool> CancelOrderAsync(string orderId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(orderId)) throw new ArgumentException("Order ID required", "orderId");
|
||||
|
||||
try
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!_orders.ContainsKey(orderId))
|
||||
{
|
||||
_logger.LogWarning(String.Format("Cannot cancel order {0} - not found", orderId));
|
||||
return false;
|
||||
}
|
||||
|
||||
var order = _orders[orderId];
|
||||
if (order.State == OrderState.Filled || order.State == OrderState.Cancelled)
|
||||
{
|
||||
_logger.LogWarning(String.Format("Cannot cancel order {0} - already {1}", orderId, order.State));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update order state to cancelled
|
||||
var fills = new List<OrderFill>();
|
||||
foreach (var fill in order.Fills)
|
||||
{
|
||||
fills.Add(fill);
|
||||
}
|
||||
|
||||
var updatedOrder = new OrderStatus(
|
||||
order.OrderId, order.Symbol, order.Side, order.Type, order.Quantity, order.FilledQuantity,
|
||||
order.LimitPrice, order.StopPrice, OrderState.Cancelled, order.CreatedTime, DateTime.UtcNow,
|
||||
fills);
|
||||
_orders[orderId] = updatedOrder;
|
||||
|
||||
UpdateOmsMetrics();
|
||||
}
|
||||
|
||||
_logger.LogInformation(String.Format("Order {0} cancelled successfully", orderId));
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(String.Format("Error cancelling order {0}: {1}", orderId, ex.Message));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modify an existing order
|
||||
/// </summary>
|
||||
public async Task<OrderResult> ModifyOrderAsync(string orderId, OrderModification modification)
|
||||
{
|
||||
if (string.IsNullOrEmpty(orderId)) throw new ArgumentException("Order ID required", "orderId");
|
||||
if (modification == null) throw new ArgumentNullException("modification");
|
||||
|
||||
try
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!_orders.ContainsKey(orderId))
|
||||
{
|
||||
_logger.LogWarning(String.Format("Cannot modify order {0} - not found", orderId));
|
||||
return new OrderResult(false, null, "Order not found", null);
|
||||
}
|
||||
|
||||
var order = _orders[orderId];
|
||||
if (order.State != OrderState.Submitted && order.State != OrderState.Accepted)
|
||||
{
|
||||
_logger.LogWarning(String.Format("Cannot modify order {0} - state is {1}", orderId, order.State));
|
||||
return new OrderResult(false, null, String.Format("Cannot modify order in state {0}", order.State), null);
|
||||
}
|
||||
|
||||
// Update order with modification parameters
|
||||
var fills = new List<OrderFill>();
|
||||
foreach (var fill in order.Fills)
|
||||
{
|
||||
fills.Add(fill);
|
||||
}
|
||||
|
||||
var updatedOrder = new OrderStatus(
|
||||
order.OrderId, order.Symbol, order.Side, order.Type,
|
||||
modification.NewQuantity.HasValue ? modification.NewQuantity.Value : order.Quantity,
|
||||
order.FilledQuantity,
|
||||
modification.NewLimitPrice.HasValue ? modification.NewLimitPrice.Value : order.LimitPrice,
|
||||
modification.NewStopPrice.HasValue ? modification.NewStopPrice.Value : order.StopPrice,
|
||||
order.State, order.CreatedTime, order.FilledTime,
|
||||
fills);
|
||||
|
||||
_orders[orderId] = updatedOrder;
|
||||
|
||||
_logger.LogInformation(String.Format("Order {0} modified successfully", orderId));
|
||||
|
||||
return new OrderResult(true, orderId, "Order modified successfully", updatedOrder);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(String.Format("Error modifying order {0}: {1}", orderId, ex.Message));
|
||||
return new OrderResult(false, null, String.Format("Error modifying order: {0}", ex.Message), null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get order status
|
||||
/// </summary>
|
||||
public async Task<OrderStatus> GetOrderStatusAsync(string orderId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(orderId)) throw new ArgumentException("Order ID required", "orderId");
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
if (_orders.ContainsKey(orderId))
|
||||
{
|
||||
return _orders[orderId];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all orders for a symbol
|
||||
/// </summary>
|
||||
public async Task<List<OrderStatus>> GetOrdersBySymbolAsync(string symbol)
|
||||
{
|
||||
if (string.IsNullOrEmpty(symbol)) throw new ArgumentException("Symbol required", "symbol");
|
||||
|
||||
var result = new List<OrderStatus>();
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
foreach (var order in _orders.Values)
|
||||
{
|
||||
if (order.Symbol.Equals(symbol, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
result.Add(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all active orders
|
||||
/// </summary>
|
||||
public async Task<List<OrderStatus>> GetActiveOrdersAsync()
|
||||
{
|
||||
var result = new List<OrderStatus>();
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
foreach (var order in _orders.Values)
|
||||
{
|
||||
if (order.State == OrderState.Submitted ||
|
||||
order.State == OrderState.Accepted ||
|
||||
order.State == OrderState.PartiallyFilled)
|
||||
{
|
||||
result.Add(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Algorithmic Execution
|
||||
|
||||
/// <summary>
|
||||
/// Execute a TWAP order
|
||||
/// </summary>
|
||||
public async Task<OrderResult> ExecuteTwapAsync(TwapParameters parameters, StrategyContext context)
|
||||
{
|
||||
if (parameters == null) throw new ArgumentNullException("parameters");
|
||||
if (context == null) throw new ArgumentNullException("context");
|
||||
|
||||
_logger.LogInformation(String.Format("Executing TWAP order for {0} {1} {2} over {3}",
|
||||
parameters.Symbol, parameters.Side, parameters.TotalQuantity, parameters.Duration));
|
||||
|
||||
// Create a parent order for tracking
|
||||
var parentOrderId = Guid.NewGuid().ToString();
|
||||
|
||||
// Calculate slice parameters
|
||||
var sliceCount = (int)(parameters.Duration.TotalSeconds / parameters.IntervalSeconds);
|
||||
var sliceQuantity = parameters.TotalQuantity / sliceCount;
|
||||
|
||||
// Execute slices
|
||||
for (int i = 0; i < sliceCount; i++)
|
||||
{
|
||||
// Create slice order
|
||||
var algorithmParameters = new Dictionary<string, object>();
|
||||
var sliceRequest = new OrderRequest(
|
||||
parameters.Symbol,
|
||||
parameters.Side,
|
||||
OrderType.Market, // Simplified to market orders
|
||||
sliceQuantity,
|
||||
parameters.LimitPrice,
|
||||
null, // StopPrice
|
||||
TimeInForce.Day,
|
||||
null, // No algorithm for slices
|
||||
algorithmParameters
|
||||
);
|
||||
|
||||
// Submit slice order
|
||||
var result = await SubmitOrderAsync(sliceRequest, context);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
_logger.LogWarning(String.Format("TWAP slice {0}/{1} failed: {2}",
|
||||
i + 1, sliceCount, result.Message));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation(String.Format("TWAP slice {0}/{1} submitted: {2}",
|
||||
i + 1, sliceCount, result.OrderId));
|
||||
}
|
||||
|
||||
// Wait for next interval (except for last slice)
|
||||
if (i < sliceCount - 1)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(parameters.IntervalSeconds));
|
||||
}
|
||||
}
|
||||
|
||||
return new OrderResult(true, parentOrderId, "TWAP execution completed", null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute a VWAP order
|
||||
/// </summary>
|
||||
public async Task<OrderResult> ExecuteVwapAsync(VwapParameters parameters, StrategyContext context)
|
||||
{
|
||||
if (parameters == null) throw new ArgumentNullException("parameters");
|
||||
if (context == null) throw new ArgumentNullException("context");
|
||||
|
||||
_logger.LogInformation(String.Format("Executing VWAP order for {0} {1} {2} from {3} to {4}",
|
||||
parameters.Symbol, parameters.Side, parameters.TotalQuantity, parameters.StartTime, parameters.EndTime));
|
||||
|
||||
// Create a parent order for tracking
|
||||
var parentOrderId = Guid.NewGuid().ToString();
|
||||
|
||||
// Simplified VWAP implementation - in a real system, this would:
|
||||
// 1. Monitor market volume throughout the execution period
|
||||
// 2. Calculate participation rate based on target participation
|
||||
// 3. Execute orders in proportion to volume
|
||||
|
||||
// For now, we'll execute the order as a single market order
|
||||
var algorithmParameters = new Dictionary<string, object>();
|
||||
var request = new OrderRequest(
|
||||
parameters.Symbol,
|
||||
parameters.Side,
|
||||
OrderType.Market,
|
||||
parameters.TotalQuantity,
|
||||
parameters.LimitPrice,
|
||||
null, // StopPrice
|
||||
TimeInForce.Day,
|
||||
null, // No algorithm for this simplified version
|
||||
algorithmParameters
|
||||
);
|
||||
|
||||
var result = await SubmitOrderAsync(request, context);
|
||||
|
||||
return new OrderResult(result.Success, parentOrderId,
|
||||
result.Success ? "VWAP execution completed" : String.Format("VWAP execution failed: {0}", result.Message),
|
||||
result.Status);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute an Iceberg order
|
||||
/// </summary>
|
||||
public async Task<OrderResult> ExecuteIcebergAsync(IcebergParameters parameters, StrategyContext context)
|
||||
{
|
||||
if (parameters == null) throw new ArgumentNullException("parameters");
|
||||
if (context == null) throw new ArgumentNullException("context");
|
||||
|
||||
_logger.LogInformation(String.Format("Executing Iceberg order for {0} {1} {2} (visible: {3})",
|
||||
parameters.Symbol, parameters.Side, parameters.TotalQuantity, parameters.VisibleQuantity));
|
||||
|
||||
// Create a parent order for tracking
|
||||
var parentOrderId = Guid.NewGuid().ToString();
|
||||
|
||||
var remainingQuantity = parameters.TotalQuantity;
|
||||
|
||||
while (remainingQuantity > 0)
|
||||
{
|
||||
// Determine visible quantity for this slice
|
||||
var visibleQuantity = Math.Min(parameters.VisibleQuantity, remainingQuantity);
|
||||
|
||||
// Create slice order
|
||||
var algorithmParameters = new Dictionary<string, object>();
|
||||
OrderType orderType = parameters.LimitPrice.HasValue ? OrderType.Limit : OrderType.Market;
|
||||
|
||||
var sliceRequest = new OrderRequest(
|
||||
parameters.Symbol,
|
||||
parameters.Side,
|
||||
orderType,
|
||||
visibleQuantity,
|
||||
parameters.LimitPrice,
|
||||
null, // StopPrice
|
||||
TimeInForce.Day,
|
||||
null, // No algorithm for slices
|
||||
algorithmParameters
|
||||
);
|
||||
|
||||
// Submit slice order
|
||||
var result = await SubmitOrderAsync(sliceRequest, context);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
_logger.LogWarning(String.Format("Iceberg slice failed with {0} qty remaining: {1}",
|
||||
remainingQuantity, result.Message));
|
||||
break;
|
||||
}
|
||||
|
||||
// Update remaining quantity
|
||||
remainingQuantity -= visibleQuantity;
|
||||
|
||||
_logger.LogInformation(String.Format("Iceberg slice submitted, {0} qty remaining", remainingQuantity));
|
||||
|
||||
// In a real implementation, we would wait for the order to fill
|
||||
// before submitting the next slice. For this design, we'll add a delay.
|
||||
if (remainingQuantity > 0)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(5)); // Simulate time between slices
|
||||
}
|
||||
}
|
||||
|
||||
return new OrderResult(true, parentOrderId, "Iceberg execution completed", null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Smart Order Routing
|
||||
|
||||
/// <summary>
|
||||
/// Route order based on smart routing logic
|
||||
/// </summary>
|
||||
public async Task<RoutingResult> RouteOrderAsync(OrderRequest request, StrategyContext context)
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException("request");
|
||||
if (context == null) throw new ArgumentNullException("context");
|
||||
|
||||
if (!_routingConfig.SmartRoutingEnabled)
|
||||
{
|
||||
var defaultVenue = _venues[_routingConfig.DefaultVenue];
|
||||
var routingDetails = new Dictionary<string, object>();
|
||||
routingDetails.Add("venue", defaultVenue.Name);
|
||||
|
||||
return new RoutingResult(true, null, defaultVenue, "Routing disabled, using default venue",
|
||||
routingDetails);
|
||||
}
|
||||
|
||||
// Select best venue based on configuration
|
||||
var selectedVenue = SelectBestVenue(request, context);
|
||||
|
||||
// Update routing metrics
|
||||
UpdateRoutingMetrics(selectedVenue);
|
||||
|
||||
var routingDetails2 = new Dictionary<string, object>();
|
||||
routingDetails2.Add("venue", selectedVenue.Name);
|
||||
routingDetails2.Add("cost_factor", selectedVenue.CostFactor);
|
||||
routingDetails2.Add("speed_factor", selectedVenue.SpeedFactor);
|
||||
|
||||
return new RoutingResult(true, null, selectedVenue, "Order routed successfully", routingDetails2);
|
||||
}
|
||||
|
||||
private ExecutionVenue SelectBestVenue(OrderRequest request, StrategyContext context)
|
||||
{
|
||||
ExecutionVenue bestVenue = null;
|
||||
double bestScore = double.MinValue;
|
||||
|
||||
foreach (var kvp in _venues)
|
||||
{
|
||||
var venue = kvp.Value;
|
||||
if (!venue.IsActive) continue;
|
||||
|
||||
double score = 0;
|
||||
|
||||
// Factor in venue preferences
|
||||
if (_routingConfig.VenuePreferences.ContainsKey(venue.Name))
|
||||
{
|
||||
score += _routingConfig.VenuePreferences[venue.Name] * 100;
|
||||
}
|
||||
|
||||
// Factor in cost if enabled
|
||||
if (_routingConfig.RouteByCost)
|
||||
{
|
||||
score -= venue.CostFactor * 50; // Lower cost is better
|
||||
}
|
||||
|
||||
// Factor in speed if enabled
|
||||
if (_routingConfig.RouteBySpeed)
|
||||
{
|
||||
score += venue.SpeedFactor * 30; // Higher speed is better
|
||||
}
|
||||
|
||||
// Factor in reliability
|
||||
if (_routingConfig.RouteByReliability)
|
||||
{
|
||||
score += venue.ReliabilityFactor * 20; // Higher reliability is better
|
||||
}
|
||||
|
||||
if (score > bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
bestVenue = venue;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestVenue != null)
|
||||
{
|
||||
return bestVenue;
|
||||
}
|
||||
|
||||
return _venues[_routingConfig.DefaultVenue];
|
||||
}
|
||||
|
||||
private void UpdateRoutingMetrics(ExecutionVenue venue)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
VenueMetrics venueMetrics;
|
||||
if (_routingMetrics.VenuePerformance.ContainsKey(venue.Name))
|
||||
{
|
||||
venueMetrics = _routingMetrics.VenuePerformance[venue.Name];
|
||||
}
|
||||
else
|
||||
{
|
||||
venueMetrics = new VenueMetrics(venue.Name, 0, 0.0, 0.0, 0.0, 0);
|
||||
}
|
||||
|
||||
var updatedMetrics = new VenueMetrics(
|
||||
venueMetrics.VenueName,
|
||||
venueMetrics.OrdersRouted + 1,
|
||||
venueMetrics.FillRate,
|
||||
venueMetrics.AverageSlippage,
|
||||
venueMetrics.AverageExecutionTimeMs,
|
||||
venueMetrics.TotalValueRouted
|
||||
);
|
||||
|
||||
_routingMetrics.VenuePerformance[venue.Name] = updatedMetrics;
|
||||
_routingMetrics.TotalRoutedOrders++;
|
||||
_routingMetrics.LastUpdated = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get available execution venues
|
||||
/// </summary>
|
||||
public List<ExecutionVenue> GetAvailableVenues()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var venues = new List<ExecutionVenue>();
|
||||
foreach (var kvp in _venues)
|
||||
{
|
||||
var venue = kvp.Value;
|
||||
if (venue.IsActive)
|
||||
{
|
||||
venues.Add(venue);
|
||||
}
|
||||
}
|
||||
return venues;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get routing performance metrics
|
||||
/// </summary>
|
||||
public RoutingMetrics GetRoutingMetrics()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _routingMetrics;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Risk Integration
|
||||
|
||||
/// <summary>
|
||||
/// Validate order against risk parameters
|
||||
/// </summary>
|
||||
public async Task<RiskDecision> ValidateOrderAsync(OrderRequest request, StrategyContext context)
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException("request");
|
||||
if (context == null) throw new ArgumentNullException("context");
|
||||
|
||||
// Convert OrderRequest to StrategyIntent for risk validation
|
||||
NT8.Core.Common.Models.OrderSide side;
|
||||
if (request.Side == OrderSide.Buy)
|
||||
{
|
||||
side = NT8.Core.Common.Models.OrderSide.Buy;
|
||||
}
|
||||
else
|
||||
{
|
||||
side = NT8.Core.Common.Models.OrderSide.Sell;
|
||||
}
|
||||
|
||||
var intent = new StrategyIntent(
|
||||
request.Symbol,
|
||||
side,
|
||||
ConvertOrderType(request.Type),
|
||||
(double?)request.LimitPrice,
|
||||
GetStopTicks(request),
|
||||
null, // TargetTicks
|
||||
1.0, // Confidence
|
||||
"OMS Order Submission",
|
||||
new Dictionary<string, object>()
|
||||
);
|
||||
|
||||
// Create a mock risk config for validation
|
||||
var riskConfig = new RiskConfig(1000, 200, 10, true);
|
||||
|
||||
return _riskManager.ValidateOrder(intent, context, riskConfig);
|
||||
}
|
||||
|
||||
private NT8.Core.Common.Models.OrderType ConvertOrderType(NT8.Core.Orders.OrderType orderType)
|
||||
{
|
||||
if (orderType == NT8.Core.Orders.OrderType.Market)
|
||||
{
|
||||
return NT8.Core.Common.Models.OrderType.Market;
|
||||
}
|
||||
else if (orderType == NT8.Core.Orders.OrderType.Limit)
|
||||
{
|
||||
return NT8.Core.Common.Models.OrderType.Limit;
|
||||
}
|
||||
else if (orderType == NT8.Core.Orders.OrderType.StopMarket)
|
||||
{
|
||||
return NT8.Core.Common.Models.OrderType.StopMarket;
|
||||
}
|
||||
else if (orderType == NT8.Core.Orders.OrderType.StopLimit)
|
||||
{
|
||||
return NT8.Core.Common.Models.OrderType.StopLimit;
|
||||
}
|
||||
|
||||
return NT8.Core.Common.Models.OrderType.Market;
|
||||
}
|
||||
|
||||
private int GetStopTicks(OrderRequest request)
|
||||
{
|
||||
// Simplified stop ticks calculation
|
||||
return 10;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Configuration and Management
|
||||
|
||||
/// <summary>
|
||||
/// Update routing configuration
|
||||
/// </summary>
|
||||
public void UpdateRoutingConfig(RoutingConfig config)
|
||||
{
|
||||
if (config == null) throw new ArgumentNullException("config");
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_routingConfig = config;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Routing configuration updated");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get current routing configuration
|
||||
/// </summary>
|
||||
public RoutingConfig GetRoutingConfig()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _routingConfig;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update algorithm parameters
|
||||
/// </summary>
|
||||
public void UpdateAlgorithmParameters(AlgorithmParameters parameters)
|
||||
{
|
||||
if (parameters == null) throw new ArgumentNullException("parameters");
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_algorithmParameters = parameters;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Algorithm parameters updated");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get current algorithm parameters
|
||||
/// </summary>
|
||||
public AlgorithmParameters GetAlgorithmParameters()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _algorithmParameters;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset OMS state
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_orders.Clear();
|
||||
_routingMetrics.VenuePerformance.Clear();
|
||||
_routingMetrics.TotalRoutedOrders = 0;
|
||||
_routingMetrics.AverageRoutingTimeMs = 0.0;
|
||||
_routingMetrics.LastUpdated = DateTime.UtcNow;
|
||||
|
||||
// Note: In a real implementation, we would need to update the OmsMetrics properties
|
||||
// Since they are read-only in the current implementation, we can't modify them directly
|
||||
}
|
||||
|
||||
_logger.LogInformation("OMS state reset");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Monitoring and Metrics
|
||||
|
||||
private void UpdateOmsMetrics()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var activeOrders = 0;
|
||||
var filledOrders = 0;
|
||||
var failedOrders = 0;
|
||||
var totalQuantity = 0;
|
||||
|
||||
foreach (var kvp in _orders)
|
||||
{
|
||||
var order = kvp.Value;
|
||||
switch (order.State)
|
||||
{
|
||||
case OrderState.Submitted:
|
||||
case OrderState.Accepted:
|
||||
case OrderState.PartiallyFilled:
|
||||
activeOrders++;
|
||||
break;
|
||||
case OrderState.Filled:
|
||||
filledOrders++;
|
||||
break;
|
||||
case OrderState.Rejected:
|
||||
case OrderState.Expired:
|
||||
case OrderState.Cancelled:
|
||||
failedOrders++;
|
||||
break;
|
||||
}
|
||||
|
||||
totalQuantity += order.Quantity;
|
||||
}
|
||||
|
||||
var totalOrders = _orders.Count;
|
||||
var fillRate = totalOrders > 0 ? (double)filledOrders / totalOrders : 0.0;
|
||||
|
||||
// We can't directly modify the properties of _omsMetrics since they're read-only
|
||||
// In a real implementation, we would have setters or create a new instance
|
||||
// For now, we'll just log the updated values
|
||||
_logger.LogDebug(String.Format("OMS Metrics - Total: {0}, Active: {1}, Failed: {2}, Fill Rate: {3:P2}",
|
||||
totalOrders, activeOrders, failedOrders, fillRate));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get OMS performance metrics
|
||||
/// </summary>
|
||||
public OmsMetrics GetMetrics()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _omsMetrics;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if OMS is healthy
|
||||
/// </summary>
|
||||
public bool IsHealthy()
|
||||
{
|
||||
// Simple health check - in a real implementation, this would check:
|
||||
// - Connection to execution venues
|
||||
// - Risk management system availability
|
||||
// - Position sizing system availability
|
||||
// - Internal state consistency
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,956 +0,0 @@
|
||||
using NT8.Core.Common.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// ARCHIVED: This namespace (NT8.Core.Orders) is superseded by NT8.Core.OMS.
|
||||
// NT8.Core.OMS is the canonical order management implementation used by NT8StrategyBase.
|
||||
// These files are retained for reference only and are not referenced by any active code.
|
||||
// Do not add new code here. Do not remove these files until a full audit confirms zero references.
|
||||
|
||||
namespace NT8.Core.Orders
|
||||
{
|
||||
#region Core Order Models
|
||||
|
||||
/// <summary>
|
||||
/// Order request parameters
|
||||
/// </summary>
|
||||
public class OrderRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Trading symbol
|
||||
/// </summary>
|
||||
public string Symbol { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order side
|
||||
/// </summary>
|
||||
public OrderSide Side { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order type
|
||||
/// </summary>
|
||||
public OrderType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order quantity
|
||||
/// </summary>
|
||||
public int Quantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Limit price (if applicable)
|
||||
/// </summary>
|
||||
public decimal? LimitPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Stop price (if applicable)
|
||||
/// </summary>
|
||||
public decimal? StopPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Time in force
|
||||
/// </summary>
|
||||
public TimeInForce TimeInForce { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm to use (TWAP, VWAP, Iceberg, or null for regular order)
|
||||
/// </summary>
|
||||
public string Algorithm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm-specific parameters
|
||||
/// </summary>
|
||||
public Dictionary<string, object> AlgorithmParameters { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for OrderRequest
|
||||
/// </summary>
|
||||
public OrderRequest(
|
||||
string symbol,
|
||||
OrderSide side,
|
||||
OrderType type,
|
||||
int quantity,
|
||||
decimal? limitPrice,
|
||||
decimal? stopPrice,
|
||||
TimeInForce timeInForce,
|
||||
string algorithm,
|
||||
Dictionary<string, object> algorithmParameters)
|
||||
{
|
||||
Symbol = symbol;
|
||||
Side = side;
|
||||
Type = type;
|
||||
Quantity = quantity;
|
||||
LimitPrice = limitPrice;
|
||||
StopPrice = stopPrice;
|
||||
TimeInForce = timeInForce;
|
||||
Algorithm = algorithm;
|
||||
AlgorithmParameters = algorithmParameters ?? new Dictionary<string, object>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Order submission result
|
||||
/// </summary>
|
||||
public class OrderResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the order submission was successful
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order ID if successful
|
||||
/// </summary>
|
||||
public string OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Message describing the result
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order status if successful
|
||||
/// </summary>
|
||||
public OrderStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for OrderResult
|
||||
/// </summary>
|
||||
public OrderResult(
|
||||
bool success,
|
||||
string orderId,
|
||||
string message,
|
||||
OrderStatus status)
|
||||
{
|
||||
Success = success;
|
||||
OrderId = orderId;
|
||||
Message = message;
|
||||
Status = status;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Current order status
|
||||
/// </summary>
|
||||
public class OrderStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Order ID
|
||||
/// </summary>
|
||||
public string OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Trading symbol
|
||||
/// </summary>
|
||||
public string Symbol { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order side
|
||||
/// </summary>
|
||||
public OrderSide Side { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order type
|
||||
/// </summary>
|
||||
public OrderType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order quantity
|
||||
/// </summary>
|
||||
public int Quantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Filled quantity
|
||||
/// </summary>
|
||||
public int FilledQuantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Limit price (if applicable)
|
||||
/// </summary>
|
||||
public decimal? LimitPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Stop price (if applicable)
|
||||
/// </summary>
|
||||
public decimal? StopPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current order state
|
||||
/// </summary>
|
||||
public OrderState State { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order creation time
|
||||
/// </summary>
|
||||
public DateTime CreatedTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order fill time (if filled)
|
||||
/// </summary>
|
||||
public DateTime? FilledTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order fills
|
||||
/// </summary>
|
||||
public List<OrderFill> Fills { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for OrderStatus
|
||||
/// </summary>
|
||||
public OrderStatus(
|
||||
string orderId,
|
||||
string symbol,
|
||||
OrderSide side,
|
||||
OrderType type,
|
||||
int quantity,
|
||||
int filledQuantity,
|
||||
decimal? limitPrice,
|
||||
decimal? stopPrice,
|
||||
OrderState state,
|
||||
DateTime createdTime,
|
||||
DateTime? filledTime,
|
||||
List<OrderFill> fills)
|
||||
{
|
||||
OrderId = orderId;
|
||||
Symbol = symbol;
|
||||
Side = side;
|
||||
Type = type;
|
||||
Quantity = quantity;
|
||||
FilledQuantity = filledQuantity;
|
||||
LimitPrice = limitPrice;
|
||||
StopPrice = stopPrice;
|
||||
State = state;
|
||||
CreatedTime = createdTime;
|
||||
FilledTime = filledTime;
|
||||
Fills = fills ?? new List<OrderFill>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Order modification parameters
|
||||
/// </summary>
|
||||
public class OrderModification
|
||||
{
|
||||
/// <summary>
|
||||
/// New quantity (if changing)
|
||||
/// </summary>
|
||||
public int? NewQuantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// New limit price (if changing)
|
||||
/// </summary>
|
||||
public decimal? NewLimitPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// New stop price (if changing)
|
||||
/// </summary>
|
||||
public decimal? NewStopPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// New time in force (if changing)
|
||||
/// </summary>
|
||||
public TimeInForce? NewTimeInForce { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for OrderModification
|
||||
/// </summary>
|
||||
public OrderModification(
|
||||
int? newQuantity,
|
||||
decimal? newLimitPrice,
|
||||
decimal? newStopPrice,
|
||||
TimeInForce? newTimeInForce)
|
||||
{
|
||||
NewQuantity = newQuantity;
|
||||
NewLimitPrice = newLimitPrice;
|
||||
NewStopPrice = newStopPrice;
|
||||
NewTimeInForce = newTimeInForce;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Algorithm Parameters
|
||||
|
||||
/// <summary>
|
||||
/// TWAP algorithm parameters
|
||||
/// </summary>
|
||||
public class TwapParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Trading symbol
|
||||
/// </summary>
|
||||
public string Symbol { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order side
|
||||
/// </summary>
|
||||
public OrderSide Side { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total quantity to trade
|
||||
/// </summary>
|
||||
public int TotalQuantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total duration for execution
|
||||
/// </summary>
|
||||
public TimeSpan Duration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Interval between order slices in seconds
|
||||
/// </summary>
|
||||
public int IntervalSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Limit price (if applicable)
|
||||
/// </summary>
|
||||
public decimal? LimitPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for TwapParameters
|
||||
/// </summary>
|
||||
public TwapParameters(
|
||||
string symbol,
|
||||
OrderSide side,
|
||||
int totalQuantity,
|
||||
TimeSpan duration,
|
||||
int intervalSeconds,
|
||||
decimal? limitPrice)
|
||||
{
|
||||
Symbol = symbol;
|
||||
Side = side;
|
||||
TotalQuantity = totalQuantity;
|
||||
Duration = duration;
|
||||
IntervalSeconds = intervalSeconds;
|
||||
LimitPrice = limitPrice;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// VWAP algorithm parameters
|
||||
/// </summary>
|
||||
public class VwapParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Trading symbol
|
||||
/// </summary>
|
||||
public string Symbol { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order side
|
||||
/// </summary>
|
||||
public OrderSide Side { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total quantity to trade
|
||||
/// </summary>
|
||||
public int TotalQuantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Start time for execution
|
||||
/// </summary>
|
||||
public DateTime StartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// End time for execution
|
||||
/// </summary>
|
||||
public DateTime EndTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Limit price (if applicable)
|
||||
/// </summary>
|
||||
public decimal? LimitPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Participation rate (0.0 to 1.0)
|
||||
/// </summary>
|
||||
public double ParticipationRate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for VwapParameters
|
||||
/// </summary>
|
||||
public VwapParameters(
|
||||
string symbol,
|
||||
OrderSide side,
|
||||
int totalQuantity,
|
||||
DateTime startTime,
|
||||
DateTime endTime,
|
||||
decimal? limitPrice,
|
||||
double participationRate)
|
||||
{
|
||||
Symbol = symbol;
|
||||
Side = side;
|
||||
TotalQuantity = totalQuantity;
|
||||
StartTime = startTime;
|
||||
EndTime = endTime;
|
||||
LimitPrice = limitPrice;
|
||||
ParticipationRate = participationRate;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Iceberg algorithm parameters
|
||||
/// </summary>
|
||||
public class IcebergParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Trading symbol
|
||||
/// </summary>
|
||||
public string Symbol { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order side
|
||||
/// </summary>
|
||||
public OrderSide Side { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total quantity to trade
|
||||
/// </summary>
|
||||
public int TotalQuantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Visible quantity for each slice
|
||||
/// </summary>
|
||||
public int VisibleQuantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Limit price (if applicable)
|
||||
/// </summary>
|
||||
public decimal? LimitPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for IcebergParameters
|
||||
/// </summary>
|
||||
public IcebergParameters(
|
||||
string symbol,
|
||||
OrderSide side,
|
||||
int totalQuantity,
|
||||
int visibleQuantity,
|
||||
decimal? limitPrice)
|
||||
{
|
||||
Symbol = symbol;
|
||||
Side = side;
|
||||
TotalQuantity = totalQuantity;
|
||||
VisibleQuantity = visibleQuantity;
|
||||
LimitPrice = limitPrice;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Routing Models
|
||||
|
||||
/// <summary>
|
||||
/// Order routing result
|
||||
/// </summary>
|
||||
public class RoutingResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether routing was successful
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order ID
|
||||
/// </summary>
|
||||
public string OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Selected execution venue
|
||||
/// </summary>
|
||||
public ExecutionVenue SelectedVenue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Message describing the result
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Routing details
|
||||
/// </summary>
|
||||
public Dictionary<string, object> RoutingDetails { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for RoutingResult
|
||||
/// </summary>
|
||||
public RoutingResult(
|
||||
bool success,
|
||||
string orderId,
|
||||
ExecutionVenue selectedVenue,
|
||||
string message,
|
||||
Dictionary<string, object> routingDetails)
|
||||
{
|
||||
Success = success;
|
||||
OrderId = orderId;
|
||||
SelectedVenue = selectedVenue;
|
||||
Message = message;
|
||||
RoutingDetails = routingDetails ?? new Dictionary<string, object>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execution venue information
|
||||
/// </summary>
|
||||
public class ExecutionVenue
|
||||
{
|
||||
/// <summary>
|
||||
/// Venue name
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Venue description
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether venue is active
|
||||
/// </summary>
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Relative cost factor (1.0 = baseline)
|
||||
/// </summary>
|
||||
public double CostFactor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Relative speed factor (1.0 = baseline)
|
||||
/// </summary>
|
||||
public double SpeedFactor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reliability score (0.0 to 1.0)
|
||||
/// </summary>
|
||||
public double ReliabilityFactor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for ExecutionVenue
|
||||
/// </summary>
|
||||
public ExecutionVenue(
|
||||
string name,
|
||||
string description,
|
||||
bool isActive,
|
||||
double costFactor,
|
||||
double speedFactor,
|
||||
double reliabilityFactor)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
IsActive = isActive;
|
||||
CostFactor = costFactor;
|
||||
SpeedFactor = speedFactor;
|
||||
ReliabilityFactor = reliabilityFactor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Routing performance metrics
|
||||
/// </summary>
|
||||
public class RoutingMetrics
|
||||
{
|
||||
/// <summary>
|
||||
/// Performance metrics by venue
|
||||
/// </summary>
|
||||
public Dictionary<string, VenueMetrics> VenuePerformance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total number of routed orders
|
||||
/// </summary>
|
||||
public int TotalRoutedOrders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Average routing time in milliseconds
|
||||
/// </summary>
|
||||
public double AverageRoutingTimeMs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last update timestamp
|
||||
/// </summary>
|
||||
public DateTime LastUpdated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for RoutingMetrics
|
||||
/// </summary>
|
||||
public RoutingMetrics(
|
||||
Dictionary<string, VenueMetrics> venuePerformance,
|
||||
int totalRoutedOrders,
|
||||
double averageRoutingTimeMs,
|
||||
DateTime lastUpdated)
|
||||
{
|
||||
VenuePerformance = venuePerformance ?? new Dictionary<string, VenueMetrics>();
|
||||
TotalRoutedOrders = totalRoutedOrders;
|
||||
AverageRoutingTimeMs = averageRoutingTimeMs;
|
||||
LastUpdated = lastUpdated;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Metrics for a specific execution venue
|
||||
/// </summary>
|
||||
public class VenueMetrics
|
||||
{
|
||||
/// <summary>
|
||||
/// Venue name
|
||||
/// </summary>
|
||||
public string VenueName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of orders routed to this venue
|
||||
/// </summary>
|
||||
public int OrdersRouted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fill rate for this venue
|
||||
/// </summary>
|
||||
public double FillRate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Average slippage for this venue
|
||||
/// </summary>
|
||||
public double AverageSlippage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Average execution time in milliseconds
|
||||
/// </summary>
|
||||
public double AverageExecutionTimeMs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total value routed through this venue
|
||||
/// </summary>
|
||||
public decimal TotalValueRouted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for VenueMetrics
|
||||
/// </summary>
|
||||
public VenueMetrics(
|
||||
string venueName,
|
||||
int ordersRouted,
|
||||
double fillRate,
|
||||
double averageSlippage,
|
||||
double averageExecutionTimeMs,
|
||||
decimal totalValueRouted)
|
||||
{
|
||||
VenueName = venueName;
|
||||
OrdersRouted = ordersRouted;
|
||||
FillRate = fillRate;
|
||||
AverageSlippage = averageSlippage;
|
||||
AverageExecutionTimeMs = averageExecutionTimeMs;
|
||||
TotalValueRouted = totalValueRouted;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Routing configuration parameters
|
||||
/// </summary>
|
||||
public class RoutingConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether smart routing is enabled
|
||||
/// </summary>
|
||||
public bool SmartRoutingEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default venue to use when smart routing is disabled
|
||||
/// </summary>
|
||||
public string DefaultVenue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Venue preferences (venue name -> preference weight)
|
||||
/// </summary>
|
||||
public Dictionary<string, double> VenuePreferences { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Maximum allowed slippage percentage
|
||||
/// </summary>
|
||||
public double MaxSlippagePercent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Maximum time allowed for routing
|
||||
/// </summary>
|
||||
public TimeSpan MaxRoutingTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to route based on cost
|
||||
/// </summary>
|
||||
public bool RouteByCost { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to route based on speed
|
||||
/// </summary>
|
||||
public bool RouteBySpeed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to route based on reliability
|
||||
/// </summary>
|
||||
public bool RouteByReliability { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for RoutingConfig
|
||||
/// </summary>
|
||||
public RoutingConfig(
|
||||
bool smartRoutingEnabled,
|
||||
string defaultVenue,
|
||||
Dictionary<string, double> venuePreferences,
|
||||
double maxSlippagePercent,
|
||||
TimeSpan maxRoutingTime,
|
||||
bool routeByCost,
|
||||
bool routeBySpeed,
|
||||
bool routeByReliability)
|
||||
{
|
||||
SmartRoutingEnabled = smartRoutingEnabled;
|
||||
DefaultVenue = defaultVenue;
|
||||
VenuePreferences = venuePreferences ?? new Dictionary<string, double>();
|
||||
MaxSlippagePercent = maxSlippagePercent;
|
||||
MaxRoutingTime = maxRoutingTime;
|
||||
RouteByCost = routeByCost;
|
||||
RouteBySpeed = routeBySpeed;
|
||||
RouteByReliability = routeByReliability;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm configuration parameters
|
||||
/// </summary>
|
||||
public class AlgorithmParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// TWAP settings
|
||||
/// </summary>
|
||||
public TwapConfig TwapSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// VWAP settings
|
||||
/// </summary>
|
||||
public VwapConfig VwapSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Iceberg settings
|
||||
/// </summary>
|
||||
public IcebergConfig IcebergSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for AlgorithmParameters
|
||||
/// </summary>
|
||||
public AlgorithmParameters(
|
||||
TwapConfig twapSettings,
|
||||
VwapConfig vwapSettings,
|
||||
IcebergConfig icebergSettings)
|
||||
{
|
||||
TwapSettings = twapSettings;
|
||||
VwapSettings = vwapSettings;
|
||||
IcebergSettings = icebergSettings;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TWAP configuration
|
||||
/// </summary>
|
||||
public class TwapConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Default duration for TWAP orders
|
||||
/// </summary>
|
||||
public TimeSpan DefaultDuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default interval between slices in seconds
|
||||
/// </summary>
|
||||
public int DefaultIntervalSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether TWAP is enabled
|
||||
/// </summary>
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for TwapConfig
|
||||
/// </summary>
|
||||
public TwapConfig(
|
||||
TimeSpan defaultDuration,
|
||||
int defaultIntervalSeconds,
|
||||
bool enabled)
|
||||
{
|
||||
DefaultDuration = defaultDuration;
|
||||
DefaultIntervalSeconds = defaultIntervalSeconds;
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// VWAP configuration
|
||||
/// </summary>
|
||||
public class VwapConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Default participation rate for VWAP orders
|
||||
/// </summary>
|
||||
public double DefaultParticipationRate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether VWAP is enabled
|
||||
/// </summary>
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for VwapConfig
|
||||
/// </summary>
|
||||
public VwapConfig(
|
||||
double defaultParticipationRate,
|
||||
bool enabled)
|
||||
{
|
||||
DefaultParticipationRate = defaultParticipationRate;
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Iceberg configuration
|
||||
/// </summary>
|
||||
public class IcebergConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Default visible ratio for Iceberg orders
|
||||
/// </summary>
|
||||
public double DefaultVisibleRatio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether Iceberg is enabled
|
||||
/// </summary>
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for IcebergConfig
|
||||
/// </summary>
|
||||
public IcebergConfig(
|
||||
double defaultVisibleRatio,
|
||||
bool enabled)
|
||||
{
|
||||
DefaultVisibleRatio = defaultVisibleRatio;
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Metrics Models
|
||||
|
||||
/// <summary>
|
||||
/// OMS performance metrics
|
||||
/// </summary>
|
||||
public class OmsMetrics
|
||||
{
|
||||
/// <summary>
|
||||
/// Total number of orders
|
||||
/// </summary>
|
||||
public int TotalOrders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of active orders
|
||||
/// </summary>
|
||||
public int ActiveOrders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of failed orders
|
||||
/// </summary>
|
||||
public int FailedOrders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fill rate (0.0 to 1.0)
|
||||
/// </summary>
|
||||
public double FillRate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Average slippage
|
||||
/// </summary>
|
||||
public double AverageSlippage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Average execution time in milliseconds
|
||||
/// </summary>
|
||||
public double AverageExecutionTimeMs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total value traded
|
||||
/// </summary>
|
||||
public decimal TotalValueTraded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last update timestamp
|
||||
/// </summary>
|
||||
public DateTime LastUpdated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for OmsMetrics
|
||||
/// </summary>
|
||||
public OmsMetrics(
|
||||
int totalOrders,
|
||||
int activeOrders,
|
||||
int failedOrders,
|
||||
double fillRate,
|
||||
double averageSlippage,
|
||||
double averageExecutionTimeMs,
|
||||
decimal totalValueTraded,
|
||||
DateTime lastUpdated)
|
||||
{
|
||||
TotalOrders = totalOrders;
|
||||
ActiveOrders = activeOrders;
|
||||
FailedOrders = failedOrders;
|
||||
FillRate = fillRate;
|
||||
AverageSlippage = averageSlippage;
|
||||
AverageExecutionTimeMs = averageExecutionTimeMs;
|
||||
TotalValueTraded = totalValueTraded;
|
||||
LastUpdated = lastUpdated;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enumerations
|
||||
|
||||
/// <summary>
|
||||
/// Order side enumeration
|
||||
/// </summary>
|
||||
public enum OrderSide
|
||||
{
|
||||
Buy = 1,
|
||||
Sell = -1
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Order type enumeration
|
||||
/// </summary>
|
||||
public enum OrderType
|
||||
{
|
||||
Market,
|
||||
Limit,
|
||||
StopMarket,
|
||||
StopLimit
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Order state enumeration
|
||||
/// </summary>
|
||||
public enum OrderState
|
||||
{
|
||||
New,
|
||||
Submitted,
|
||||
Accepted,
|
||||
PartiallyFilled,
|
||||
Filled,
|
||||
Cancelled,
|
||||
Rejected,
|
||||
Expired
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Time in force enumeration
|
||||
/// </summary>
|
||||
public enum TimeInForce
|
||||
{
|
||||
Day,
|
||||
Gtc, // Good Till Cancelled
|
||||
Ioc, // Immediate Or Cancel
|
||||
Fok // Fill Or Kill
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user