/*
* 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.ComponentModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace QuantConnect.Orders.Serialization
{
///
/// Data transfer object used for serializing an that was just generated by an algorithm
///
public class SerializedOrderEvent
{
///
/// The unique order event id
///
[JsonProperty("id")]
public string Id => $"{AlgorithmId}-{OrderId}-{OrderEventId}";
///
/// Algorithm Id, BacktestId or DeployId
///
[JsonProperty("algorithm-id")]
public string AlgorithmId { get; set; }
///
/// Id of the order this event comes from.
///
[JsonProperty("order-id")]
public int OrderId { get; set; }
///
/// The unique order event id for each order
///
[JsonProperty("order-event-id")]
public int OrderEventId { get; set; }
///
/// Easy access to the order symbol associated with this event.
///
[JsonProperty("symbol")]
public string Symbol { get; set; }
///
/// The time of this event in unix timestamp
///
[JsonProperty("time")]
public double Time { get; set; }
///
/// Status message of the order.
///
[JsonProperty("status"), JsonConverter(typeof(StringEnumConverter), true)]
public OrderStatus Status { get; set; }
///
/// The fee amount associated with the order
///
[JsonProperty("order-fee-amount", DefaultValueHandling = DefaultValueHandling.Ignore)]
public decimal? OrderFeeAmount { get; set; }
///
/// The fee currency associated with the order
///
[JsonProperty("order-fee-currency", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string OrderFeeCurrency { get; set; }
///
/// Fill price information about the order
///
[JsonProperty("fill-price")]
public decimal FillPrice { get; set; }
///
/// Currency for the fill price
///
[JsonProperty("fill-price-currency")]
public string FillPriceCurrency { get; set; }
///
/// Number of shares of the order that was filled in this event.
///
[JsonProperty("fill-quantity")]
public decimal FillQuantity { get; set; }
///
/// Order direction.
///
[JsonProperty("direction"), JsonConverter(typeof(StringEnumConverter), true)]
public OrderDirection Direction { get; set; }
///
/// Any message from the exchange.
///
[DefaultValue(""), JsonProperty("message", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Message { get; set; }
///
/// True if the order event is an assignment
///
[JsonProperty("is-assignment")]
public bool IsAssignment { get; set; }
///
/// The current order quantity
///
[JsonProperty("quantity")]
public decimal Quantity { get; set; }
///
/// The current stop price
///
[JsonProperty("stop-price", DefaultValueHandling = DefaultValueHandling.Ignore)]
public decimal? StopPrice { get; set; }
///
/// The current limit price
///
[JsonProperty("limit-price", DefaultValueHandling = DefaultValueHandling.Ignore)]
public decimal? LimitPrice { get; set; }
///
/// Empty constructor required for JSON converter.
///
private SerializedOrderEvent()
{
}
///
/// Creates a new instances based on the provided order event and algorithm Id
///
public SerializedOrderEvent(OrderEvent orderEvent, string algorithmId)
{
AlgorithmId = algorithmId;
OrderId = orderEvent.OrderId;
OrderEventId = orderEvent.Id;
Symbol = orderEvent.Symbol.ID.ToString();
Time = QuantConnect.Time.DateTimeToUnixTimeStamp(orderEvent.UtcTime);
Status = orderEvent.Status;
if (orderEvent.OrderFee.Value.Currency != Currencies.NullCurrency)
{
OrderFeeAmount = orderEvent.OrderFee.Value.Amount;
OrderFeeCurrency = orderEvent.OrderFee.Value.Currency;
}
FillPrice = orderEvent.FillPrice;
FillPriceCurrency = orderEvent.FillPriceCurrency;
FillQuantity = orderEvent.FillQuantity;
Direction = orderEvent.Direction;
Message = orderEvent.Message;
IsAssignment = orderEvent.IsAssignment;
Quantity = orderEvent.Quantity;
StopPrice = orderEvent.StopPrice;
LimitPrice = orderEvent.LimitPrice;
}
}
}