Esempio n. 1
0
        private AddTimeSerieOperationResult _add(LocalDateTime localTime, double?value)
        {
            if (_values.ContainsKey(localTime))
            {
                return(AddTimeSerieOperationResult.TimeAlreadyPresent);
            }

            if (_entity.OriginalGranularity.IsTimeGranularity())
            {
                var period = ArtesianUtils.MapTimePeriod(_entity.OriginalGranularity);
                if (!localTime.IsStartOfInterval(period))
                {
                    throw new ArtesianSdkClientException("Trying to insert Time {0} with the wrong format to serie {1}. Should be of period {2}", localTime, _identifier, period);
                }
            }
            else
            {
                var period = ArtesianUtils.MapDatePeriod(_entity.OriginalGranularity);
                if (!localTime.IsStartOfInterval(period))
                {
                    throw new ArtesianSdkClientException("Trying to insert Time {0} with the wrong format to serie {1}. Should be of period {2}", localTime, _identifier, period);
                }
            }

            _values.Add(localTime, value);
            return(AddTimeSerieOperationResult.ValueAdded);
        }
Esempio n. 2
0
        private AddBidAskOperationResult _addBidAsk(LocalDateTime reportTime, string product, BidAskValue value)
        {
            //Relative products
            if (Regex.IsMatch(product, @"\+\d+$"))
            {
                throw new NotSupportedException("Relative Products are not supported");
            }

            if (_entity.OriginalGranularity.IsTimeGranularity())
            {
                var period = ArtesianUtils.MapTimePeriod(_entity.OriginalGranularity);
                if (!reportTime.IsStartOfInterval(period))
                {
                    throw new BidAskException("Trying to insert Report Time {0} with the wrong format to BidAsk {1}. Should be of period {2}", reportTime, _identifier, period);
                }
            }
            else
            {
                var period = ArtesianUtils.MapDatePeriod(_entity.OriginalGranularity);
                if (!reportTime.IsStartOfInterval(period))
                {
                    throw new BidAskException("Trying to insert Report Time {0} with wrong the format to BidAsk {1}. Should be of period {2}", reportTime, _identifier, period);
                }
            }


            if (BidAsks.Any(row => row.ReportTime == reportTime && row.Product.Equals(product)))
            {
                return(AddBidAskOperationResult.ProductAlreadyPresent);
            }

            BidAsks.Add(new BidAskElement(reportTime, product, value));
            return(AddBidAskOperationResult.BidAskAdded);
        }
Esempio n. 3
0
        private AddAuctionTimeSerieOperationResult _add(LocalDateTime bidTime, AuctionBidValue[] bid, AuctionBidValue[] offer)
        {
            if (_bids.ContainsKey(bidTime))
            {
                return(AddAuctionTimeSerieOperationResult.TimeAlreadyPresent);
            }

            foreach (var element in _bids)
            {
                foreach (var item in element.Value.Bid)
                {
                    if (item.Quantity < 0)
                    {
                        throw new AuctionTimeSerieException($"Auction[{element.Key}] contains invalid Bid Quantity < 0");
                    }
                }

                foreach (var item in element.Value.Offer)
                {
                    if (item.Quantity < 0)
                    {
                        throw new AuctionTimeSerieException($"Auction[{element.Key}] contains invalid Offer Quantity < 0");
                    }
                }
            }

            if (_entity.OriginalGranularity.IsTimeGranularity())
            {
                var period = ArtesianUtils.MapTimePeriod(_entity.OriginalGranularity);
                if (!bidTime.IsStartOfInterval(period))
                {
                    throw new ArtesianSdkClientException("Trying to insert Time {0} with wrong format to serie {1}. Should be of period {2}", bidTime, _identifier, period);
                }
            }
            else
            {
                var period = ArtesianUtils.MapDatePeriod(_entity.OriginalGranularity);
                if (!bidTime.IsStartOfInterval(period))
                {
                    throw new ArtesianSdkClientException("Trying to insert Time {0} with wrong format to serie {1}. Should be of period {2}", bidTime, _identifier, period);
                }
            }

            _bids.Add(bidTime, new AuctionBids(bidTime, bid, offer));
            return(AddAuctionTimeSerieOperationResult.ValueAdded);
        }
Esempio n. 4
0
        private AddAssessmentOperationResult _addAssessment(LocalDateTime reportTime, string product, MarketAssessmentValue value)
        {
            //Relative products
            if (Regex.IsMatch(product, @"\+\d+$"))
            {
                throw new NotSupportedException("Relative Products are not supported");
            }

            if (_entity.OriginalGranularity.IsTimeGranularity())
            {
                var period = ArtesianUtils.MapTimePeriod(_entity.OriginalGranularity);
                if (!reportTime.IsStartOfInterval(period))
                {
                    throw new MarketAssessmentException("Trying to insert Report Time {0} with the wrong format to Assessment {1}. Should be of period {2}", reportTime, _identifier, period);
                }
            }
            else
            {
                var period = ArtesianUtils.MapDatePeriod(_entity.OriginalGranularity);
                if (!reportTime.IsStartOfInterval(period))
                {
                    throw new MarketAssessmentException("Trying to insert Report Time {0} with wrong the format to Assessment {1}. Should be of period {2}", reportTime, _identifier, period);
                }
            }

            //if (reportTime.Date >= product.ReferenceDate)
            //    return AddAssessmentOperationResult.IllegalReferenceDate;

            if (Assessments.Any(row => row.ReportTime == reportTime && row.Product.Equals(product)))
            {
                return(AddAssessmentOperationResult.ProductAlreadyPresent);
            }

            Assessments.Add(new AssessmentElement(reportTime, product, value));
            return(AddAssessmentOperationResult.AssessmentAdded);
        }