16 using System.Collections.Generic;
18 using System.Runtime.CompilerServices;
30 public static partial class Messages
40 [MethodImpl(MethodImplOptions.AggressiveInlining)]
41 public static string ToString(Orders.CancelOrderRequest request)
43 return Invariant($
@"{request.Time.ToStringInvariant()} UTC: Cancel Order: ({request.OrderId}) - {
44 request.Tag} Status: {request.Status}");
56 [MethodImpl(MethodImplOptions.AggressiveInlining)]
60 var ids =
string.Join(
",", securities.Keys.Select(o => o.Id));
61 var values =
string.Join(
",", securities.Select(o => o.Key.GetValue(o.Value).SmartRounding()));
62 return $
@"Order Error: ids: [{ids}], Insufficient buying power to complete orders (Value:[{values}]), Reason: {
63 hasSufficientBuyingPowerResult.Reason}.";
75 [MethodImpl(MethodImplOptions.AggressiveInlining)]
76 public static string Tag(Orders.LimitIfTouchedOrder order)
86 [MethodImpl(MethodImplOptions.AggressiveInlining)]
87 public static string ToString(Orders.LimitIfTouchedOrder order)
90 return Invariant($
@"{Order.ToString(order)} at trigger {currencySymbol}{order.TriggerPrice.SmartRounding()
91 } limit {currencySymbol}{order.LimitPrice.SmartRounding()}");
103 [MethodImpl(MethodImplOptions.AggressiveInlining)]
104 public static string Tag(Orders.LimitOrder order)
113 [MethodImpl(MethodImplOptions.AggressiveInlining)]
114 public static string ToString(Orders.LimitOrder order)
117 return Invariant($
"{Order.ToString(order)} at limit {currencySymbol}{order.LimitPrice.SmartRounding()}");
129 [MethodImpl(MethodImplOptions.AggressiveInlining)]
132 var tag =
string.IsNullOrEmpty(order.Tag) ?
string.Empty : $
": {order.Tag}";
133 return Invariant($
@"OrderId: {order.Id} (BrokerId: {string.Join(",
", order.BrokerId)}) {order.Status} {
134 order.Type} order for {order.Quantity} unit{(order.Quantity == 1 ? "" : "s
")} of {order.Symbol}{tag}");
146 [MethodImpl(MethodImplOptions.AggressiveInlining)]
147 public static string ToString(Orders.OrderEvent orderEvent)
149 var message = Invariant($
@"Time: {orderEvent.UtcTime} OrderID: {orderEvent.OrderId} EventID: {
150 orderEvent.Id} Symbol: {orderEvent.Symbol.Value} Status: {orderEvent.Status} Quantity: {orderEvent.Quantity}");
153 if (orderEvent.FillQuantity != 0)
155 message += Invariant($
@" FillQuantity: {orderEvent.FillQuantity
156 } FillPrice: {currencySymbol}{orderEvent.FillPrice.SmartRounding()}");
159 if (orderEvent.LimitPrice.HasValue)
161 message += Invariant($
" LimitPrice: {currencySymbol}{orderEvent.LimitPrice.Value.SmartRounding()}");
164 if (orderEvent.StopPrice.HasValue)
166 message += Invariant($
" StopPrice: {currencySymbol}{orderEvent.StopPrice.Value.SmartRounding()}");
169 if (orderEvent.TrailingAmount.HasValue)
172 orderEvent.TrailingAsPercentage ??
false, currencySymbol);
173 message += $
" TrailingAmount: {trailingAmountString}";
176 if (orderEvent.TriggerPrice.HasValue)
178 message += Invariant($
" TriggerPrice: {currencySymbol}{orderEvent.TriggerPrice.Value.SmartRounding()}");
182 if (orderEvent.OrderFee.Value.Amount != 0m)
184 message += Invariant($
" OrderFee: {orderEvent.OrderFee}");
188 if (!
string.IsNullOrEmpty(orderEvent.Message))
190 message += Invariant($
" Message: {orderEvent.Message}");
193 if (orderEvent.Symbol.SecurityType.IsOption())
195 message += Invariant($
" IsAssignment: {orderEvent.IsAssignment}");
204 [MethodImpl(MethodImplOptions.AggressiveInlining)]
207 var message = Invariant($
"{orderEvent.UtcTime} OID:{orderEvent.OrderId} {orderEvent.Symbol.Value} {orderEvent.Status} Q:{orderEvent.Quantity}");
210 if (orderEvent.FillQuantity != 0)
212 message += Invariant($
" FQ:{orderEvent.FillQuantity} FP:{currencySymbol}{orderEvent.FillPrice.SmartRounding()}");
215 if (orderEvent.LimitPrice.HasValue)
217 message += Invariant($
" LP:{currencySymbol}{orderEvent.LimitPrice.Value.SmartRounding()}");
220 if (orderEvent.StopPrice.HasValue)
222 message += Invariant($
" SP:{currencySymbol}{orderEvent.StopPrice.Value.SmartRounding()}");
225 if (orderEvent.TrailingAmount.HasValue)
228 orderEvent.TrailingAsPercentage ??
false, currencySymbol);
229 message += $
" TA: {trailingAmountString}";
232 if (orderEvent.TriggerPrice.HasValue)
234 message += Invariant($
" TP:{currencySymbol}{orderEvent.TriggerPrice.Value.SmartRounding()}");
238 if (orderEvent.OrderFee.Value.Amount != 0m)
240 message += Invariant($
" OF:{currencySymbol}{orderEvent.OrderFee}");
244 if (!
string.IsNullOrEmpty(orderEvent.Message))
246 message += Invariant($
" M:{orderEvent.Message}");
249 if (orderEvent.Symbol.SecurityType.IsOption())
251 message += Invariant($
" IA:{orderEvent.IsAssignment}");
266 [MethodImpl(MethodImplOptions.AggressiveInlining)]
267 public static string ToString(Orders.OrderRequest request)
269 return Invariant($
"{request.Time} UTC: Order: ({request.OrderId}) - {request.Tag} Status: {request.Status}");
291 [MethodImpl(MethodImplOptions.AggressiveInlining)]
292 public static string ToString(Orders.OrderResponse response)
294 if (response == Orders.OrderResponse.Unprocessed)
296 return "Unprocessed";
299 if (response.IsError)
301 return Invariant($
"Error: {response.ErrorCode} - {response.ErrorMessage}");
311 [MethodImpl(MethodImplOptions.AggressiveInlining)]
312 public static string InvalidStatus(Orders.OrderRequest request, Orders.Order order)
314 return Invariant($
"Unable to update order with id {request.OrderId} because it already has {order.Status} status.");
321 [MethodImpl(MethodImplOptions.AggressiveInlining)]
324 return Invariant($
@"Unable to update or cancel order with id {
325 request.OrderId} and status {order.Status} because the submit confirmation has not been received yet.");
332 [MethodImpl(MethodImplOptions.AggressiveInlining)]
335 return Invariant($
"Unable to locate order with id {request.OrderId}.");
342 [MethodImpl(MethodImplOptions.AggressiveInlining)]
345 return Invariant($
"Unable to {request.OrderRequestType.ToLower()} order with id {request.OrderId} that has zero quantity.");
354 [MethodImpl(MethodImplOptions.AggressiveInlining)]
357 return Invariant($
"You haven't requested {request.Symbol} data. Add this with AddSecurity() in the Initialize() Method.");
365 [MethodImpl(MethodImplOptions.AggressiveInlining)]
366 public static string WarmingUp(Orders.OrderRequest request)
368 return Invariant($
@"This operation is not allowed in Initialize or during warm up: OrderRequest.{
369 request.OrderRequestType}. Please move this code to the OnWarmupFinished() method.");
382 [MethodImpl(MethodImplOptions.AggressiveInlining)]
385 return Invariant($
"Unable to get field {field} on order of type {ticket.SubmitRequest.OrderType}");
392 [MethodImpl(MethodImplOptions.AggressiveInlining)]
395 return Invariant($
"Order {ticket.OrderId} has already received a cancellation request.");
401 [MethodImpl(MethodImplOptions.AggressiveInlining)]
402 public static string ToString(Orders.OrderTicket ticket, Orders.Order order,
int requestCount,
int responseCount)
404 var counts = Invariant($
"Request Count: {requestCount} Response Count: {responseCount}");
407 return Invariant($
"{ticket.OrderId}: {order} {counts}");
410 return Invariant($
"{ticket.OrderId}: {counts}");
422 [MethodImpl(MethodImplOptions.AggressiveInlining)]
423 public static string Tag(Orders.StopLimitOrder order)
432 [MethodImpl(MethodImplOptions.AggressiveInlining)]
433 public static string ToString(Orders.StopLimitOrder order)
436 return Invariant($
@"{Order.ToString(order)} at stop {currencySymbol}{order.StopPrice.SmartRounding()
437 } limit {currencySymbol}{order.LimitPrice.SmartRounding()}");
449 [MethodImpl(MethodImplOptions.AggressiveInlining)]
450 public static string Tag(Orders.StopMarketOrder order)
459 [MethodImpl(MethodImplOptions.AggressiveInlining)]
460 public static string ToString(Orders.StopMarketOrder order)
463 return Invariant($
"{Order.ToString(order)} at stop {currencySymbol}{order.StopPrice.SmartRounding()}");
475 [MethodImpl(MethodImplOptions.AggressiveInlining)]
476 public static string Tag(Orders.TrailingStopOrder order)
478 return Invariant($
"Trailing Amount: {TrailingAmount(order)}");
484 [MethodImpl(MethodImplOptions.AggressiveInlining)]
485 public static string ToString(Orders.TrailingStopOrder order)
488 return Invariant($
@"{Order.ToString(order)} at stop {currencySymbol}{order.StopPrice.SmartRounding()}. Trailing amount: {
489 TrailingAmountImpl(order, currencySymbol)}");
495 [MethodImpl(MethodImplOptions.AggressiveInlining)]
504 [MethodImpl(MethodImplOptions.AggressiveInlining)]
505 public static string TrailingAmount(decimal trailingAmount,
bool trailingAsPercentage,
string priceCurrency)
507 return trailingAsPercentage ? Invariant($
"{trailingAmount * 100}%") : Invariant($
"{priceCurrency}{trailingAmount}");
510 [MethodImpl(MethodImplOptions.AggressiveInlining)]
511 private static string TrailingAmountImpl(Orders.TrailingStopOrder order,
string currencySymbol)
513 return TrailingAmount(order.TrailingAmount, order.TrailingAsPercentage, currencySymbol);
525 [MethodImpl(MethodImplOptions.AggressiveInlining)]
526 public static string ToString(Orders.SubmitOrderRequest request)
529 var proxy = Orders.Order.CreateOrder(request);
530 return Invariant($
"{request.Time} UTC: Submit Order: ({request.OrderId}) - {proxy} {request.Tag} Status: {request.Status}");
542 [MethodImpl(MethodImplOptions.AggressiveInlining)]
543 public static string ToString(Orders.UpdateOrderRequest request)
545 var updates =
new List<string>(4);
546 if (request.Quantity.HasValue)
548 updates.Add(Invariant($
"Quantity: {request.Quantity.Value}"));
550 if (request.LimitPrice.HasValue)
552 updates.Add(Invariant($
"LimitPrice: {request.LimitPrice.Value.SmartRounding()}"));
554 if (request.StopPrice.HasValue)
556 updates.Add(Invariant($
"StopPrice: {request.StopPrice.Value.SmartRounding()}"));
558 if (request.TrailingAmount.HasValue)
560 updates.Add(Invariant($
"TrailingAmount: {request.TrailingAmount.Value.SmartRounding()}"));
562 if (request.TriggerPrice.HasValue)
564 updates.Add(Invariant($
"TriggerPrice: {request.TriggerPrice.Value.SmartRounding()}"));
567 return Invariant($
@"{request.Time} UTC: Update Order: ({request.OrderId}) - {string.Join(",
", updates)} {
568 request.Tag} Status: {request.Status}");