Exemplo n.º 1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var obj  = JObject.Load(reader);
            var type = new SymbolFilterTypeConverter(false).ReadString(obj["filterType"].ToString());
            BinanceSymbolFilter result;

            switch (type)
            {
            case SymbolFilterType.LotSize:
                result = new BinanceSymbolLotSizeFilter
                {
                    MaxQuantity = obj["maxQty"] != null ? (decimal)obj["maxQty"] : -1,
                    MinQuantity = obj["minQty"] != null ? (decimal)obj["minQty"] : -1,
                    StepSize    = obj["stepSize"] != null ? (decimal)obj["stepSize"] : -1
                };
                break;

            case SymbolFilterType.MarketLotSize:
                result = new BinanceSymbolMarketLotSizeFilter
                {
                    MaxQuantity = (decimal)obj["maxQty"],
                    MinQuantity = (decimal)obj["minQty"],
                    StepSize    = (decimal)obj["stepSize"]
                };
                break;

            case SymbolFilterType.MinNotional:
                result = new BinanceSymbolMinNotionalFilter
                {
                    MinNotional         = (decimal)obj["minNotional"],
                    ApplyToMarketOrders = (bool)obj["applyToMarket"],
                    AveragePriceMinutes = (int)obj["avgPriceMins"]
                };
                break;

            case SymbolFilterType.Price:
                result = new BinanceSymbolPriceFilter
                {
                    MaxPrice = (decimal)obj["maxPrice"],
                    MinPrice = (decimal)obj["minPrice"],
                    TickSize = (decimal)obj["tickSize"]
                };
                break;

            case SymbolFilterType.MaxNumberAlgorithmicOrders:
                result = new BinanceSymbolMaxAlgorithmicOrdersFilter
                {
                    MaxNumberAlgorithmicOrders = (int)obj["maxNumAlgoOrders"]
                };
                break;

            case SymbolFilterType.MaxNumberIcebergOrders:
                result = new BinanceSymbolMaxIcebergOrdersFilter
                {
                    MaxNumberIcebergOrders = (int)obj["maxNumIcebergOrders"]
                };
                break;

            case SymbolFilterType.MaxNumberOrders:
                result = new BinanceSymbolMaxOrdersFilter
                {
                    MaxNumberOrders = (int)obj["limit"]
                };
                break;

            case SymbolFilterType.IcebergParts:
                result = new BinanceSymbolIcebergPartsFilter
                {
                    Limit = (int)obj["limit"]
                };
                break;

            case SymbolFilterType.PricePercent:
                result = new BinanceSymbolPercentPriceFilter
                {
                    MultiplierUp        = (decimal)obj["multiplierUp"],
                    MultiplierDown      = (decimal)obj["multiplierDown"],
                    AveragePriceMinutes = obj["avgPriceMins"] != null? (int)obj["avgPriceMins"] : -1
                };
                break;

            default:
                Debug.WriteLine("Can't parse symbol filter of type: " + obj["filterType"]);
                result = new BinanceSymbolFilter();
                break;
            }
            result.FilterType = type;
            return(result);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject             obj    = JObject.Load(reader);
            SymbolFilterType    type   = new SymbolFilterTypeConverter(false).ReadString(obj["filterType"].ToString());
            BinanceSymbolFilter result = null;

            switch (type)
            {
            case SymbolFilterType.LotSize:
                result = new BinanceSymbolLotSizeFilter()
                {
                    MaxQuantity = JsonConvert.DeserializeObject <decimal>(obj["maxQty"].ToString()),
                    MinQuantity = JsonConvert.DeserializeObject <decimal>(obj["minQty"].ToString()),
                    StepSize    = JsonConvert.DeserializeObject <decimal>(obj["stepSize"].ToString())
                };
                break;

            case SymbolFilterType.MarketLotSize:
                result = new BinanceSymbolMarketLotSizeFilter()
                {
                    MaxQuantity = JsonConvert.DeserializeObject <decimal>(obj["maxQty"].ToString()),
                    MinQuantity = JsonConvert.DeserializeObject <decimal>(obj["minQty"].ToString()),
                    StepSize    = JsonConvert.DeserializeObject <decimal>(obj["stepSize"].ToString())
                };
                break;

            case SymbolFilterType.MinNotional:
                result = new BinanceSymbolMinNotionalFilter()
                {
                    MinNotional         = JsonConvert.DeserializeObject <decimal>(obj["minNotional"].ToString()),
                    ApplyToMarketOrders = (bool)obj["applyToMarket"],
                    AveragePriceMinutes = JsonConvert.DeserializeObject <int>(obj["avgPriceMins"].ToString())
                };
                break;

            case SymbolFilterType.Price:
                result = new BinanceSymbolPriceFilter()
                {
                    MaxPrice = JsonConvert.DeserializeObject <decimal>(obj["maxPrice"].ToString()),
                    MinPrice = JsonConvert.DeserializeObject <decimal>(obj["minPrice"].ToString()),
                    TickSize = JsonConvert.DeserializeObject <decimal>(obj["tickSize"].ToString()),
                };
                break;

            case SymbolFilterType.MaxNumberAlogitmicalOrders:
                result = new BinanceSymbolMaxAlgoritmicalOrdersFilter()
                {
                    MaxNumberAlgoritmicalOrders = JsonConvert.DeserializeObject <int>(obj["maxNumAlgoOrders"].ToString())
                };
                break;

            case SymbolFilterType.MaxNumberIcebergOrders:
                result = new BinanceSymbolMaxIcebergOrdersFilter()
                {
                    MaxNumberIcebergOrders = JsonConvert.DeserializeObject <int>(obj["maxNumIcebergOrders"].ToString())
                };
                break;

            case SymbolFilterType.MaxNumberOrders:
                result = new BinanceSymbolMaxOrdersFilter()
                {
                    MaxNumberOrders = JsonConvert.DeserializeObject <int>(obj["limit"].ToString())
                };
                break;

            case SymbolFilterType.IcebergParts:
                result = new BinanceSymbolIcebergPartsFilter()
                {
                    Limit = JsonConvert.DeserializeObject <int>(obj["limit"].ToString())
                };
                break;

            case SymbolFilterType.PricePercent:
                result = new BinanceSymbolPercentPriceFilter()
                {
                    MultiplierUp        = JsonConvert.DeserializeObject <decimal>(obj["multiplierUp"].ToString()),
                    MultiplierDown      = JsonConvert.DeserializeObject <decimal>(obj["multiplierDown"].ToString()),
                    AveragePriceMinutes = JsonConvert.DeserializeObject <int>(obj["avgPriceMins"].ToString()),
                };
                break;
            }
            result.FilterType = type;
            return(result);
        }