Beispiel #1
0
        // Three possible outcomes:
        // - Result is not null. That's success. In this case error is guaranteed to be null.
        // - Result is null, error is null. It means the entry isn't a trade. Not an error.
        // - Result is null, error is not null. That's an error.
        static MarketTrade MakeTrade(DateTime msgTime, Mantle.Fix44.MDEntry entry, out string error)
        {
            var res = new MarketTrade();

            error = null;

            if (!entry.MDEntryType.HasValue)
            {
                error = "Missing MDEntryType field";
                return(null);
            }

            if (entry.MDEntryType.Value != '2')
            {
                return(null);                                 // No error.
            }
            if (!entry.MDEntryPx.HasValue)
            {
                error = "Missing MDEntryPx field";
                return(null);
            }
            res.Price = entry.MDEntryPx.Value;
            if (!entry.MDEntrySize.HasValue)
            {
                error = "Missing MDEntrySize field";
                return(null);
            }
            res.Quantity = entry.MDEntrySize.Value;

            if (entry.Side.HasValue)
            {
                if (entry.Side.Value == '1')
                {
                    res.Side = Side.Buy;
                }
                else if (entry.Side.Value == '2')
                {
                    res.Side = Side.Sell;
                }
                else
                {
                    _log.Warn("Unknown value of Side field: {0}", entry.Side.Value);
                }
            }

            if (entry.MDEntryTime.HasValue)
            {
                // Huobi sends MDEntryTime with every trade report but this field contains only
                // time without the date. We combine it with OrigTime or SendingTime (whichever is present)
                // to get a full timestamp.
                res.Timestamp = Combine(msgTime, entry.MDEntryTime.Value);
            }

            return(res);
        }
Beispiel #2
0
        // Three possible outcomes:
        // - Result is not null. That's success. In this case error is guaranteed to be null.
        // - Result is null, error is null. It means the entry isn't an order. Not an error.
        // - Result is null, error is not null. That's an error.
        static MarketOrder MakeOrder(Mantle.Fix44.MDEntry entry, out string error)
        {
            var res = new MarketOrder();

            error = null;

            if (!entry.MDEntryType.HasValue)
            {
                error = "Missing MDEntryType field";
                return(null);
            }

            if (entry.MDEntryType.Value == '0')
            {
                res.Side = Side.Buy;
            }
            else if (entry.MDEntryType.Value == '1')
            {
                res.Side = Side.Sell;
            }
            else
            {
                return(null);  // No error.
            }
            if (!entry.MDEntryPx.HasValue)
            {
                error = "Missing MDEntryPx field";
                return(null);
            }
            res.Price = entry.MDEntryPx.Value;
            if (!entry.MDEntrySize.HasValue)
            {
                error = "Missing MDEntrySize field";
                return(null);
            }
            res.Quantity = entry.MDEntrySize.Value;

            return(res);
        }