Exemple #1
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src"></param>
 protected MarketOrder(SerializableOrderListItem src)
 {
     m_state = GetState(src);
     m_orderID = src.OrderID;
     m_itemID = src.ItemID;
     m_item = StaticItems.GetItemByID(src.ItemID);
     m_station = GetStationByID(src.StationID);
     m_unitaryPrice = src.UnitaryPrice;
     m_initialVolume = src.InitialVolume;
     m_remainingVolume = src.RemainingVolume;
     m_lastStateChange = DateTime.UtcNow;
     m_minVolume = src.MinVolume;
     m_duration = src.Duration;
     m_issued = src.Issued;
     m_issuedFor = src.IssuedFor;
 }
Exemple #2
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src"></param>
 internal SellOrder(SerializableOrderListItem src)
     : base(src)
 {
 }
Exemple #3
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src"></param>
 internal BuyOrder(SerializableOrderListItem src)
     : base(src)
 {
     Escrow = src.Escrow;
     m_range = src.Range;
 }
Exemple #4
0
 /// <summary>
 /// Checks whether the given API object matches with this order.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 internal bool IsModified (SerializableOrderListItem src)
 {
     return src.RemainingVolume != 0
         && ((src.UnitaryPrice != m_unitaryPrice && src.Issued != m_issued)
         || src.RemainingVolume != m_remainingVolume);
 }
Exemple #5
0
 /// <summary>
 /// Checks whether the given API object matches with this order.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 internal bool MatchesWith(SerializableOrderListItem src)
 {
     return src.OrderID == m_orderID;
 }
Exemple #6
0
        /// <summary>
        /// Gets the state of an order.
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        private static OrderState GetState(SerializableOrderListItem src)
        {
            switch ((APIEnumerations.CCPOrderState)src.State)
            {
                case APIEnumerations.CCPOrderState.Closed:
                case APIEnumerations.CCPOrderState.Canceled:
                case APIEnumerations.CCPOrderState.CharacterDeleted:
                    return OrderState.Canceled;

                case APIEnumerations.CCPOrderState.Pending:
                case APIEnumerations.CCPOrderState.Opened:
                    return OrderState.Active;

                case APIEnumerations.CCPOrderState.ExpiredOrFulfilled:
                    return (src.RemainingVolume == 0 ? OrderState.Fulfilled : OrderState.Expired);

                default:
                    throw new NotImplementedException();
            }
        }
Exemple #7
0
        /// <summary>
        /// Try to update this order with a serialization object from the API.
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        internal bool TryImport(SerializableOrderListItem src, List<MarketOrder> endedOrders)
        {
            // Note that, before a match is found, all orders have been marked for deletion : m_markedForDeletion == true

            // Checks whether ID is the same (IDs can be recycled ?)
            if (!MatchesWith(src))
                return false;

            // Prevent deletion
            m_markedForDeletion = false;

            // Update infos (if ID is the same it may have been modified either by the market 
            // or by the user [modify order] so we update the orders info that are changeable)
            if (IsModified(src))
            {
                // If it's a buying order, escrow may have changed
                if (src.IsBuyOrder != 0)
                    ((BuyOrder)this).Escrow = src.Escrow;

                m_unitaryPrice = src.UnitaryPrice;
                m_remainingVolume = src.RemainingVolume;
                m_issued = src.Issued;
                m_state = OrderState.Modified;
            }
            else if (m_state == OrderState.Modified)
            {
                m_state = OrderState.Active;
            }

            // Update state
            OrderState state = GetState(src);
            if (m_state != OrderState.Modified && state != m_state) // it has either expired or fulfilled
            {
                m_state = state;
                m_lastStateChange = DateTime.UtcNow;

                // Should we notify it to the user ?
                if ((state == OrderState.Expired || state == OrderState.Fulfilled) && !Ignored)
                    endedOrders.Add(this);
            }

            return true;
        }