/// <summary>
        /// We use column names like 'openMIN' and parse stat value from string
        /// </summary>
        /// <param name="stats"></param>
        /// <param name="priceType"></param>
        /// <param name="statAggregate"></param>
        /// <returns></returns>
        private static double?ParseStatValue(Serie stats, PriceType priceType, StatAggregate statAggregate)
        {
            var priceTypeColumn = priceType.ToString().ToLower();
            var statValue       = stats.Values[0][stats.Columns.IndexOf(priceTypeColumn + statAggregate)].ToString().Replace(',', '.');

            return(ParseHelper.ParseDouble(statValue));
        }
Example #2
0
 /// <summary>
 /// This function will be called after creating an indicator as well as after its input params reset or chart (symbol or timeframe) updates.
 /// </summary>
 protected override void OnInit()
 {
     // Serves for an identification of related indicators with different parameters.
     ShortName = "EMA (" + MaPeriod.ToString() + ": " + SourcePrice.ToString() + ")";
     // Calculation of a coefficient.
     k = 2.0 / (MaPeriod + 1);
 }
Example #3
0
        public static async Task <List <CustomerSalesPrice> > FetchCustomerSalesPricesForItem(string itemNo,
                                                                                              VismaNetAuthorization authorization, PriceType priceType = PriceType.Undefined)
        {
            var webclient = GetHttpClient(authorization);
            {
                var apiUrl = GetApiUrlForController(VismaNetControllers.CustomerSalesPrices);
                try
                {
                    string fullUrl = string.Empty;
                    if (priceType == PriceType.Undefined)
                    {
                        fullUrl = $"{apiUrl}?inventoryId={itemNo}";
                    }
                    else
                    {
                        fullUrl = $"{apiUrl}?priceType={priceType.ToString()}&inventoryId={itemNo}";
                    }

                    return(await webclient.Get <List <CustomerSalesPrice> >(fullUrl));
                }
                catch (AggregateException e)
                {
                    VismaNetExceptionHandler.HandleException(e);
                }
                catch (WebException e)
                {
                    VismaNetExceptionHandler.HandleException(e);
                }

                return(null);
            }
        }
		public static async Task<decimal> FetchPriceAsync(int typeId, int region = -1, int system = -1, PriceType type = PriceType.sell, PriceMeasure measure = PriceMeasure.min)
		{
			try
			{
				var webClient = new WebClient();
				var uri = GetUriForRequest(typeId, region, system);
				var xml = await webClient.DownloadStringTaskAsync(uri);
				var xdoc = XDocument.Parse(xml);
				return Decimal.Parse(xdoc.Descendants(type.ToString()).Single().Descendants(measure.ToString()).Single().Value);
			}
			catch (Exception e)
			{
				Console.Error.WriteLine(e);
				return -1;
			}
		}
Example #5
0
        public static async Task <decimal> FetchPriceAsync(int typeId, int region = -1, int system = -1, PriceType type = PriceType.sell, PriceMeasure measure = PriceMeasure.min)
        {
            try
            {
                var webClient = new WebClient();
                var uri       = GetUriForRequest(typeId, region, system);
                var xml       = await webClient.DownloadStringTaskAsync(uri);

                var xdoc = XDocument.Parse(xml);
                return(Decimal.Parse(xdoc.Descendants(type.ToString()).Single().Descendants(measure.ToString()).Single().Value));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                return(-1);
            }
        }
Example #6
0
 private void setComboBoxItemOHLC(ComboBox combo, PriceType priceType)
 {
     combo.Text = priceType.ToString();
 }
Example #7
0
        public static DataTable GetProductsByType(TypeFlag type, int count, PriceType priceType)
        {
            var priceField = priceType.ToString();

            string sqlCmd = "select Top(@count) Product.ProductId, Product.ArtNo, Name, BriefDescription, " +
                            "(CASE WHEN Offer.ColorID is not null THEN (Select TOP(1) PhotoName From [Catalog].[Photo] WHERE ([Photo].ColorID = Offer.ColorID or [Photo].ColorID is null) and [Product].[ProductID] = [Photo].[ObjId] and Type=@Type order by main desc, PhotoSortOrder) ELSE (Select TOP(1) PhotoName From [Catalog].[Photo] WHERE [Product].[ProductID] = [Photo].[ObjId] and Type=@Type order by main desc, PhotoSortOrder) END)  AS Photo, " +
                            "(CASE WHEN Offer.ColorID is not null THEN (Select TOP(1) [Photo].[Description] From [Catalog].[Photo] WHERE ([Photo].ColorID = Offer.ColorID or [Photo].ColorID is null) and [Product].[ProductID] = [Photo].[ObjId] and Type=@Type) ELSE (Select TOP(1) [Photo].[Description] From [Catalog].[Photo] WHERE [Product].[ProductID] = [Photo].[ObjId] and Type=@Type AND [Photo].[Main] = 1) END)  AS PhotoDesc, " +
                            "Discount, Ratio, RatioID, AllowPreOrder, Recomended, New, BestSeller, OnSale, UrlPath, " +
                            "ShoppingCartItemID, " +
                            (SettingsCatalog.UseLastPrice
                            ? string.Format("(CASE WHEN ProductPrice IS NULL THEN {0} ELSE ProductPrice END) as Price, ", priceField)
                            : string.Format("{0} as Price, ", priceField)
                            ) +
                            "(Select Max(Offer.Amount) from catalog.Offer Where ProductId=[Product].[ProductID]) as Amount," +
                            " Offer.OfferID, Offer.ColorID, MinAmount, " +
                            (SettingsCatalog.ComplexFilter ?
                            "(select [Settings].[ProductColorsToString]([Product].[ProductID])) as Colors":
                            "null as Colors") +
                            " from Catalog.Product " +
                            "LEFT JOIN [Catalog].[Offer] ON [Product].[ProductID] = [Offer].[ProductID] and Offer.main=1 " +
                            "LEFT JOIN Catalog.Photo on Product.ProductID=Photo.ObjId and Type=@Type and Photo.main=1 " +
                            "LEFT JOIN [Catalog].[ShoppingCart] ON [Catalog].[ShoppingCart].[OfferID] = [Catalog].[Offer].[OfferID] AND [Catalog].[ShoppingCart].[ShoppingCartType] = @ShoppingCartType AND [ShoppingCart].[CustomerID] = @CustomerId " +
                            "Left JOIN [Catalog].[Ratio] on Product.ProductId=Ratio.ProductID and Ratio.CustomerId=@CustomerId " +
                            "LEFT JOIN [Customers].[LastPrice] ON [LastPrice].[ProductId] = [Product].[ProductId] AND [LastPrice].[CustomerId] = @CustomerId " +
                            "where {0} and Enabled=1 and CategoryEnabled=1 and [Settings].[CountCategoriesByProduct](Product.ProductID) > 0 order by {1}";
            switch (type)
            {
                case TypeFlag.Bestseller:
                    sqlCmd = string.Format(sqlCmd, "Bestseller=1", "SortBestseller");
                    break;
                case TypeFlag.New:
                    sqlCmd = string.Format(sqlCmd, "New=1", "SortNew");
                    break;
                case TypeFlag.Discount:
                    sqlCmd = string.Format(sqlCmd, "Discount>0", "SortDiscount");
                    break;
                default:
                    throw new NotImplementedException();
            }
            return SQLDataAccess.ExecuteTable(sqlCmd, CommandType.Text,
                                              new SqlParameter {ParameterName = "@count", Value = count},
                                              new SqlParameter("@CustomerId", CustomerSession.CustomerId.ToString()),
                                              new SqlParameter("@Type", PhotoType.Product.ToString()),
                                              new SqlParameter("@ShoppingCartType", ShoppingCartType.Compare));
        }
Example #8
0
        /// <summary>
        /// Some KPIs has history.
        /// See list of KPI and how to call on github
        /// https://github.com/Borsdata-Sweden/API/wiki/KPI-History
        /// </summary>
        /// <param name="instrumentId">Company Ericsson has instrumentId=77</param>
        /// <param name="KpiId">KPI id. P/E =2</param>
        /// <param name="rt"> What report is KPI calculated with? [year, r12, quarter]</param>
        /// <param name="pt">What stockprice is KPI calculated with? [mean, high, low]</param>
        /// <returns>List of historical KPI values</returns>
        public KpisHistoryRespV1 GetKpiHistory(long instrumentId, int KpiId, ReportType rt, PriceType pt)
        {
            string url    = string.Format(_urlRoot + "/v1/Instruments/{0}/kpis/{1}/{2}/{3}/history", instrumentId, KpiId, rt.ToString(), pt.ToString());
            string urlPar = string.Format(_authKey);
            HttpResponseMessage response = WebbCall(url, urlPar);

            if (response.IsSuccessStatusCode)
            {
                string            json = response.Content.ReadAsStringAsync().Result;
                KpisHistoryRespV1 res  = JsonConvert.DeserializeObject <KpisHistoryRespV1>(json);
                return(res);
            }
            else
            {
                Console.WriteLine("GetStockPrices time  {0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }

            return(null);
        }
Example #9
0
        //private void lwma(int candleCount)
        //{
        //    double sum = 0;
        //    double wsum = 0;

        //    for (int i = 0; i < candleCount; i++)
        //    {
        //        double price = GetPrice(i);

        //        sum += price;
        //        wsum += price * (period - i);
        //    }

        //    currentValue = wsum / sum;
        //}

        //private void smma(int candleCount)
        //{
        //    if (candleCount < period)
        //    {
        //        sma(candleCount);
        //        return;
        //    }

        //    double temp = period * currentValue;
        //    temp -= currentValue;
        //    temp += GetPrice(0);

        //    currentValue = temp / period;
        //}

        //private void ema(int candleCount)
        //{
        //    if (candleCount < period)
        //    {
        //        sma(candleCount);
        //        return;
        //    }

        //    double multiplier = (double)2 / (1 + period);
        //    double result = GetPrice(0) - currentValue;
        //    result *= multiplier;

        //    currentValue += result;
        //}

        //private void sma(int candleCount)
        //{
        //    currentValue = 0;

        //    for (int i = 0; i < candleCount; i++)
        //    {
        //        currentValue += GetPrice(i);
        //    }

        //    currentValue /= candleCount;
        //}

        public override int CalculateIdentifier()
        {
            return(("MA" + instrument.ToString() + timeFrame.ToString() + applyTo.ToString() + method.ToString() + period.ToString()).GetHashCode());
        }
Example #10
0
        public IEnumerable <Bar> QueryQuoteHistoryBarsRange(DateTime from, DateTime to, string symbol, string pereodicity, PriceType priceType)
        {
            if (!IsConnected)
            {
                throw new Exception("Client is not connected!");
            }

            if (to < from)
            {
                DateTime temp = from;
                from = to;
                to   = temp;
            }

            var periodicity = Periodicity.Parse(pereodicity);
            var timestamp   = periodicity.GetPeriodStartTime(from);
            var last        = timestamp;

            var filename      = periodicity + " " + priceType.ToString("g").ToLowerInvariant();
            var zipSerializer = new ItemsZipSerializer <HistoryBar, List <HistoryBar> >(BarFormatter.Default, filename);
            var txtSerializer = new ItemsTextSerializer <HistoryBar, List <HistoryBar> >(BarFormatter.Default, filename);

            do
            {
                List <byte[]> content = QueryQuoteHistoryBarsFilesInternal(timestamp, symbol, pereodicity, priceType);
                foreach (var file in content)
                {
                    List <HistoryBar> historyBars;
                    if ((file.Length >= 4) && (file[0] == 0x50) && (file[1] == 0x4b) && (file[2] == 0x03) && (file[3] == 0x04))
                    {
                        historyBars = zipSerializer.Deserialize(file);
                    }
                    else
                    {
                        historyBars = txtSerializer.Deserialize(file);
                    }

                    foreach (var historyBar in historyBars)
                    {
                        if (historyBar.Time < from)
                        {
                            continue;
                        }
                        if (historyBar.Time > to)
                        {
                            break;
                        }

                        if (historyBar.Time <= last)
                        {
                            continue;
                        }
                        last = historyBar.Time;

                        yield return(new Bar
                        {
                            Time = historyBar.Time,
                            Open = historyBar.Open,
                            High = historyBar.Hi,
                            Low = historyBar.Low,
                            Close = historyBar.Close,
                            Volume = (decimal)historyBar.Volume
                        });
                    }
                }

                if (periodicity.Interval == TimeInterval.Second)
                {
                    if (periodicity.IntervalsCount < 10)
                    {
                        timestamp = timestamp.AddHours(1);
                    }
                    else
                    {
                        timestamp = timestamp.AddDays(1);
                    }
                }
                else if (periodicity.Interval == TimeInterval.Minute)
                {
                    if (periodicity.IntervalsCount < 5)
                    {
                        timestamp = timestamp.AddDays(1);
                    }
                    else
                    {
                        timestamp = timestamp.AddMonths(1);
                    }
                }
                else
                {
                    timestamp = timestamp.AddMonths(1);
                }
            } while (timestamp < to);
        }
 /// <summary>
 /// This function will be called after creating an indicator as well as after its input params reset or chart (symbol or timeframe) updates.
 /// </summary>
 protected override void OnInit()
 {
     // Serves for an identification of related indicators with different parameters.
     ShortName = "CMO (" + Period + ":" + SourcePrice.ToString() + ")";
 }
Example #12
0
 public static void ChangePriceType(string customerId, PriceType priceType)
 {
     SQLDataAccess.ExecuteNonQuery(
         "Update [Customers].[Customer] Set PriceType = @PriceType WHERE CustomerID = @CustomerID",
         CommandType.Text, new SqlParameter("@CustomerID", customerId),
         new SqlParameter("@PriceType", priceType.ToString()));
 }
Example #13
0
 public static KeyValuePair<float, float> GetPriceRange(int categoryId, bool inDepth, PriceType priceType)
 {
     return SQLDataAccess.ExecuteReadOne(
         @"[Catalog].[sp_GetPriceRange]",
         CommandType.StoredProcedure,
         reader =>
         new KeyValuePair<float, float>(
             SQLDataHelper.GetFloat(reader, "minprice"),
             SQLDataHelper.GetFloat(reader, "maxprice")),
         new SqlParameter("@categoryId", categoryId),
         new SqlParameter("@useDepth", inDepth),
         new SqlParameter("@PriceField", priceType.ToString())
         );
 }
Example #14
0
 public override string ToString()
 {
     return(PriceType.ToString() + "/" + UnitType.ToString());
 }
Example #15
0
 /// <summary>
 /// Returns a bar volumes key from the given arguments.
 /// </summary>
 /// <param name="symbol">The symbol for the key.</param>
 /// <param name="barStructure">The bar structure for the key.</param>
 /// <param name="priceType">The price type for the key.</param>
 /// <returns>A key string.</returns>
 internal static string GetBarVolumesKey(Symbol symbol, BarStructure barStructure, PriceType priceType)
 {
     return($"{BarsNamespace}:{symbol.Venue.Value}:{symbol.Code}:{barStructure.ToString()}:{priceType.ToString()}:Volumes");
 }
Example #16
0
 /// <summary>
 /// Returns a tick volumes key from the given arguments.
 /// </summary>
 /// <param name="symbol">The symbol for the key.</param>
 /// <param name="priceType">The price type for the key.</param>
 /// <returns>A key string.</returns>
 internal static string GetSizesKey(Symbol symbol, PriceType priceType)
 {
     return($"{SizesNamespace}:{symbol.Venue.Value}:{symbol.Code}:{priceType.ToString()}");
 }
 public EveCentralCell(TypeID typeId, int region = -1, int system = 30000142, PriceType type = PriceType.sell, PriceMeasure measure = PriceMeasure.min)
 {
     var uri = FetchEveCentralPrice.GetUriForRequest(typeId.ToInt(), region, system);
     var xpath = "/evec_api/marketstat/type/"+type.ToString()+"/"+measure.ToString();
     text = "=ImportXML(\"" + uri + "&clock=\"&GoogleClock(), \"" + xpath + "\")";
 }