コード例 #1
0
ファイル: Order.cs プロジェクト: bcbowen/WebAPIObjects
 public bool Equals(OrderDetail token)
 {
     return this == token;
 }
コード例 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            OrderDetail order = new OrderDetail();

            while (reader.Read())
            {
                if (reader.Value != null)
                {
                    int testInt;
                    switch (reader.Value.ToString())
                    {
                    case "AccountAlias":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.AccountAlias = reader.Value.ToString();
                        }
                        break;

                    case "AccountID":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.AccountKey = reader.Value.ToString();
                        }
                        break;

                    case "AdvancedOptions":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.AdvancedOptions = reader.Value.ToString();
                        }
                        break;

                    case "AssetType":
                        AssetType assetType;
                        if (reader.Read() && reader.Value != null && Enum.TryParse(reader.Value.ToString(), out assetType))
                        {
                            order.AssetType = assetType;
                        }
                        break;

                    case "CommissionFee":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.CommissionFee = decimal.Parse(reader.Value.ToString());
                        }
                        break;

                    case "ContractExpireDate":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.ContractExpireDate = reader.Value.ToString();
                        }
                        break;

                    case "ConversionRate":
                        decimal testDecimal;
                        if (reader.Read() && reader.Value != null && decimal.TryParse(reader.Value.ToString(), out testDecimal))
                        {
                            order.ConversionRate = testDecimal;
                        }
                        break;

                    case "Country":
                        if (reader.Read() && reader.Value != null && !string.IsNullOrEmpty(reader.Value.ToString()))
                        {
                            order.Country = reader.Value.ToString();
                        }
                        break;

                    case "Denomination":
                        Currency denomination;
                        if (reader.Read() && reader.Value != null && Enum.TryParse(reader.Value.ToString(), out denomination))
                        {
                            order.Denomination = denomination;
                        }
                        break;

                    case "Duration":
                        if (reader.Read() && reader.Value != null && !string.IsNullOrEmpty(reader.Value.ToString()))
                        {
                            order.Duration = new OrderDuration(reader.Value.ToString());
                        }
                        break;

                    case "ExecuteQuantity":
                        if (reader.Read() && reader.Value != null && int.TryParse(reader.Value.ToString(), out testInt))
                        {
                            order.ExecuteQuantity = testInt;
                        }
                        break;

                    case "FilledCanceled":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.FilledCanceled = reader.Value.ToString();
                        }
                        break;

                    case "FilledPriceText":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.FilledPriceText = reader.Value.ToString();
                        }
                        break;

                    case "GroupName":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.GroupName = reader.Value.ToString();
                        }
                        break;

                    case "Legs":

                        if (reader.Read() && reader.TokenType == JsonToken.StartArray)
                        {
                            //	order.Legs.AddRange((List<Leg>)JsonConvert.DeserializeObject<List<Leg>>(reader.Value.ToString()));
                            StringWriter sw = new StringWriter();

                            JsonTextWriter jw = new JsonTextWriter(sw);
                            jw.WriteStartArray();

                            do
                            {
                                reader.Read();
                                jw.WriteToken(reader);
                            } while (reader.TokenType != JsonToken.EndArray);
                            order.Legs.AddRange(JsonConvert.DeserializeObject <List <Leg> >(sw.ToString()));
                        }
                        break;

                    case "LimitPriceText":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.LimitPriceText = reader.Value.ToString();
                        }
                        break;

                    case "OrderID":
                        if (reader.Read() && reader.Value != null && int.TryParse(reader.Value.ToString(), out testInt))
                        {
                            order.OrderId = testInt;
                        }
                        break;

                    case "Originator":
                        if (reader.Read() && reader.Value != null && int.TryParse(reader.Value.ToString(), out testInt))
                        {
                            order.Originator = testInt;
                        }
                        break;

                    case "Quantity":
                        if (reader.Read() && reader.Value != null && int.TryParse(reader.Value.ToString(), out testInt))
                        {
                            order.Quantity = testInt;
                        }
                        break;

                    case "QuantityLeft":
                        if (reader.Read() && reader.Value != null && int.TryParse(reader.Value.ToString(), out testInt))
                        {
                            order.QuantityLeft = testInt;
                        }
                        break;

                    case "RejectReason":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.RejectReason = reader.Value.ToString();
                        }
                        break;

                    case "Routing":
                        Route route;
                        if (reader.Read() && reader.Value != null && Enum.TryParse(reader.Value.ToString(), out route))
                        {
                            order.Route = route;
                        }
                        break;

                    case "Spread":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.Spread = reader.Value.ToString();
                        }
                        break;

                    case "Status":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.Status = (OrderState)Enum.Parse(typeof(OrderState), reader.Value.ToString());
                        }
                        break;

                    case "StatusDescription":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.StatusDescription = reader.Value.ToString();
                        }
                        break;

                    case "StopPriceText":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.StopPriceText = reader.Value.ToString();
                        }
                        break;

                    case "Symbol":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.Symbol = reader.Value.ToString();
                        }
                        break;

                    case "TimeStamp":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.TimeStamp = DateTime.Parse(reader.Value.ToString());
                        }
                        break;

                    case "TriggeredBy":
                        if (reader.Read() && reader.Value != null)
                        {
                            order.TriggeredBy = reader.Value.ToString();
                        }
                        break;

                    case "Type":
                        if (reader.Read() && reader.Value != null)
                        {
                            StringBuilder action = new StringBuilder(255);
                            string[]      fields = reader.Value.ToString().Split(' ');
                            foreach (string field in fields)
                            {
                                if (!string.IsNullOrEmpty(field))
                                {
                                    action.Append(Char.ToUpper(field[0]) + field.Substring(1).ToLower());
                                }
                            }
                            order.TradeAction = (TradeAction)Enum.Parse(typeof(TradeAction), action.ToString());
                        }

                        break;

                    default:
                        reader.Read();
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            return(order);
        }
コード例 #3
0
 public bool Equals(OrderDetail token)
 {
     return(this == token);
 }
コード例 #4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            OrderDetail order = new OrderDetail();
            while (reader.Read())
            {
                if (reader.Value != null)
                {
                    int testInt;
                    switch (reader.Value.ToString())
                    {
                        case "AccountAlias":
                            if (reader.Read() && reader.Value != null) order.AccountAlias = reader.Value.ToString();
                            break;
                        case "AccountID":
                            if (reader.Read() && reader.Value != null) order.AccountKey = reader.Value.ToString();
                            break;
                        case "AdvancedOptions":
                            if (reader.Read() && reader.Value != null) order.AdvancedOptions = reader.Value.ToString();
                            break;
                        case "AssetType":
                            AssetType assetType;
                            if (reader.Read() && reader.Value != null && Enum.TryParse(reader.Value.ToString(), out assetType))
                                order.AssetType = assetType;
                            break;
                        case "CommissionFee":
                            if (reader.Read() && reader.Value != null) order.CommissionFee = decimal.Parse(reader.Value.ToString());
                            break;
                        case "ContractExpireDate":
                            if (reader.Read() && reader.Value != null) order.ContractExpireDate = reader.Value.ToString();
                            break;
                        case "ConversionRate":
                            decimal testDecimal;
                            if (reader.Read() && reader.Value != null && decimal.TryParse(reader.Value.ToString(), out testDecimal)) order.ConversionRate = testDecimal;
                            break;
                        case "Country":
                            if (reader.Read() && reader.Value != null && !string.IsNullOrEmpty(reader.Value.ToString()))
                                order.Country = reader.Value.ToString();
                            break;
                        case "Denomination":
                            Currency denomination;
                            if (reader.Read() && reader.Value != null && Enum.TryParse(reader.Value.ToString(), out denomination))
                                order.Denomination = denomination;
                            break;
                        case "Duration":
                            if (reader.Read() && reader.Value != null && !string.IsNullOrEmpty(reader.Value.ToString()))
                                order.Duration = new OrderDuration(reader.Value.ToString());
                            break;
                        case "ExecuteQuantity":
                            if (reader.Read() && reader.Value != null && int.TryParse(reader.Value.ToString(), out testInt))
                                order.ExecuteQuantity = testInt;
                            break;
                        case "FilledCanceled":
                            if (reader.Read() && reader.Value != null) order.FilledCanceled = reader.Value.ToString();
                            break;
                        case "FilledPriceText":
                            if (reader.Read() && reader.Value != null) order.FilledPriceText = reader.Value.ToString();
                            break;
                        case "GroupName":
                            if (reader.Read() && reader.Value != null) order.GroupName = reader.Value.ToString();
                            break;
                        case "Legs":

                            if (reader.Read() && reader.TokenType == JsonToken.StartArray)
                            {
                                //	order.Legs.AddRange((List<Leg>)JsonConvert.DeserializeObject<List<Leg>>(reader.Value.ToString()));
                                StringWriter sw = new StringWriter();

                                JsonTextWriter jw = new JsonTextWriter(sw);
                                jw.WriteStartArray();

                                do
                                {
                                    reader.Read();
                                    jw.WriteToken(reader);
                                } while (reader.TokenType != JsonToken.EndArray);
                                order.Legs.AddRange(JsonConvert.DeserializeObject<List<Leg>>(sw.ToString()));
                            }
                            break;
                        case "LimitPriceText":
                            if (reader.Read() && reader.Value != null) order.LimitPriceText = reader.Value.ToString();
                            break;
                        case "OrderID":
                            if (reader.Read() && reader.Value != null && int.TryParse(reader.Value.ToString(), out testInt))
                                order.OrderId = testInt;
                            break;
                        case "Originator":
                            if (reader.Read() && reader.Value != null && int.TryParse(reader.Value.ToString(), out testInt))
                                order.Originator = testInt;
                            break;
                        case "Quantity":
                            if (reader.Read() && reader.Value != null && int.TryParse(reader.Value.ToString(), out testInt))
                                order.Quantity = testInt;
                            break;
                        case "QuantityLeft":
                            if (reader.Read() && reader.Value != null && int.TryParse(reader.Value.ToString(), out testInt))
                                order.QuantityLeft = testInt;
                            break;
                        case "RejectReason":
                            if (reader.Read() && reader.Value != null) order.RejectReason = reader.Value.ToString();
                            break;
                        case "Routing":
                            Route route;
                            if (reader.Read() && reader.Value != null && Enum.TryParse(reader.Value.ToString(), out route))
                                order.Route = route;
                            break;
                        case "Spread":
                            if (reader.Read() && reader.Value != null) order.Spread = reader.Value.ToString();
                            break;
                        case "Status":
                            if (reader.Read() && reader.Value != null) order.Status = (OrderState)Enum.Parse(typeof(OrderState), reader.Value.ToString());
                            break;
                        case "StatusDescription":
                            if (reader.Read() && reader.Value != null) order.StatusDescription = reader.Value.ToString();
                            break;
                        case "StopPriceText":
                            if (reader.Read() && reader.Value != null) order.StopPriceText = reader.Value.ToString();
                            break;
                        case "Symbol":
                            if (reader.Read() && reader.Value != null) order.Symbol = reader.Value.ToString();
                            break;
                        case "TimeStamp":
                            if (reader.Read() && reader.Value != null) order.TimeStamp = DateTime.Parse(reader.Value.ToString());
                            break;
                        case "TriggeredBy":
                            if (reader.Read() && reader.Value != null) order.TriggeredBy = reader.Value.ToString();
                            break;
                        case "Type":
                            if (reader.Read() && reader.Value != null)
                            {
                                StringBuilder action = new StringBuilder(255);
                                string[] fields = reader.Value.ToString().Split(' ');
                                foreach (string field in fields)
                                {
                                    if (!string.IsNullOrEmpty(field)) action.Append(Char.ToUpper(field[0]) + field.Substring(1).ToLower());
                                }
                                order.TradeAction = (TradeAction)Enum.Parse(typeof(TradeAction), action.ToString());
                            }

                            break;
                        default:
                            reader.Read();
                            break;

                    }
                }
                else
                    break;
            }

            return order;
        }