예제 #1
0
        public TradePrice CurrentTradePrice(string fromCurrencyId, string toCurrencyId)
        {
            TradePrice result  = null;
            var        fullUrl = _baseUrl + "price"; // https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD

            if (!string.IsNullOrEmpty(fromCurrencyId) && !string.IsNullOrEmpty(toCurrencyId))
            {
                var request = _httpClient.CreateRequest(fullUrl);
                request.Parameters.Add(new HttpParameter {
                    Key = "fsym", Value = fromCurrencyId, Type = HttpParameterType.QUERY
                });
                request.Parameters.Add(new HttpParameter {
                    Key = "tsyms", Value = toCurrencyId, Type = HttpParameterType.QUERY
                });

                var response = _httpClient.ExecuteRequest <Dictionary <string, object> >(request);
                if (CheckAPIResponse(response))
                {
                    if (response.Data.ContainsKey(toCurrencyId))
                    {
                        result = new TradePrice
                        {
                            FromCurrencyId = fromCurrencyId,
                            ToCurrencyId   = toCurrencyId,
                            TimestampUTC   = DateTime.UtcNow,
                            Price          = Convert.ToDecimal(response.Data[toCurrencyId], NumberFormatInfo.InvariantInfo)
                        };
                    }
                }
            }

            return(result);
        }
예제 #2
0
 private bool ValuesEqual(TradePrice price, ProfitAnalysis optimalProfit)
 {
     return
         (price.Date.Equals(optimalProfit.PurchaseDate) &&
          price.Date.Equals(optimalProfit.SaleDate) &&
          price.OpeningPrice.Equals(optimalProfit.PurchasePrice) &&
          price.ClosingPrice.Equals(optimalProfit.SalePrice));
 }
 public void Update(TradePrice price)
 {
     var foundMenuItems = Menu.MenuItems.Find("BitcoinPrice", false);
     if (foundMenuItems.Length > 0)
     {
         foundMenuItems[0].Text = $"{price.Price} {price.Currency}";
     }
 }
예제 #4
0
 public override string ToString()
 {
     return(code + "," +
            (Direction == TradeDirection.Buy ? "买入" : "卖出") +
            ",委托日期=" + this.entrustDate.ToString("yyyyMMdd") +
            ",委托价格=" + this.entrustPrice.ToString("F2") +
            ",数量=" + this.Amount.ToString() +
            ",交易日期=" + this.TradeDate.ToString("yyyyMMdd") +
            ",交易价格=" + TradePrice.ToString("F2") + ",总金额=" + Turnover.ToString("F2") + (reason == null || reason == ""?"":"," + reason));
 }
예제 #5
0
        public void GetOptimalProfitPeriod_ShouldReturnSecondDetailsWhenSecondHistoryItemHigherProfit()
        {
            var prices = new TradePrice[]
            {
                TradePrice.Create(new DateTime(2010, 01, 01), 35, 30),
                TradePrice.Create(new DateTime(2010, 01, 02), 30, 35)
            };

            var optimalProfit = GetOptimalProfit(prices);

            Assert.IsTrue(ValuesEqual(prices.ElementAt(1), optimalProfit));
        }
예제 #6
0
        public void GetOptimalProfitPeriod_ShouldPriceValuesWhenTradeHistoryOfOne()
        {
            var price = TradePrice.Create(new DateTime(2010, 01, 01), 56, 93);
            var set   = new HashSet <TradePrice> {
                price
            };

            var stockHistory  = new StockHistory(set);
            var optimalProfit = stockHistory.GetOptimalProfitPeriod();

            Assert.IsTrue(ValuesEqual(price, optimalProfit));
        }
 public void Update(TradePrice price)
 {
     _currentPrice = price;
     if (_iconSwitcherTimer == null)
     {
         _iconSwitcherTimer = new Timer();
         _iconSwitcherTimer.Elapsed += delegate { SwitchIcon(); };
         _iconSwitcherTimer.Interval = 5000;
         _iconSwitcherTimer.Enabled = true;
     }
     _notifyIcon.Icon = CreateIconImage(_displayingCurrency
             ? _currentPrice.Currency.ToString()
             : Math.Round(_currentPrice.Price).ToString(CultureInfo.InvariantCulture));
     _notifyIcon.Text = $"{price.Price} {price.Currency}";
 }
예제 #8
0
 private HashSet <TradePrice> CreatePriceSet()
 {
     return(new HashSet <TradePrice>
     {
         TradePrice.Create(new DateTime(2009, 03, 05), 117, 112),
         TradePrice.Create(new DateTime(2009, 03, 06), 112, 110),
         TradePrice.Create(new DateTime(2009, 03, 07), 110, 122),
         TradePrice.Create(new DateTime(2009, 03, 08), 122, 129),
         TradePrice.Create(new DateTime(2009, 03, 09), 129, 124),
         TradePrice.Create(new DateTime(2009, 03, 10), 124, 134),
         TradePrice.Create(new DateTime(2009, 03, 11), 134, 133),
         TradePrice.Create(new DateTime(2009, 03, 12), 133, 132),
         TradePrice.Create(new DateTime(2009, 03, 13), 132, 131),
         TradePrice.Create(new DateTime(2009, 03, 14), 131, 130)
     });
 }
예제 #9
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hash = 17;
         hash = hash * 29 + Symbol.GetHashCode();
         hash = hash * 29 + CorrectionType.GetHashCode();
         hash = hash * 29 + TradeDate.GetHashCode();
         hash = hash * 29 + TradeTime.GetHashCode();
         hash = hash * 29 + TradePrice.GetHashCode();
         hash = hash * 29 + TradeSize.GetHashCode();
         hash = hash * 29 + TickId.GetHashCode();
         hash = hash * 29 + TradeConditions.GetHashCode();
         hash = hash * 29 + TradeMarketCentre.GetHashCode();
         return(hash);
     }
 }
예제 #10
0
        public void GetOptimalProfitPeriod_ShouldReturnFirstOpeningSecondClosingDetails()
        {
            var prices = new TradePrice[]
            {
                TradePrice.Create(new DateTime(2010, 01, 01), 30, 33),
                TradePrice.Create(new DateTime(2010, 01, 02), 33, 36)
            };

            var optimalProfit = GetOptimalProfit(prices);

            var correctProfit = new ProfitAnalysis(
                purchaseDate: prices[0].Date,
                saleDate: prices[1].Date,
                purchasePrice: prices[0].OpeningPrice,
                salePrice: prices[1].ClosingPrice
                );

            Assert.AreEqual(correctProfit, optimalProfit);
        }
예제 #11
0
 public override string ToString()
 {
     return($"Status={Status}|Symbol={Symbol}|ExChange={ExChange}|AskPrice={AskPrice?.ToString()}|AskTime={AskTime?.ToString("yyyy-MM-dd HH:mm:ss.fff")}|BidPrice={BidPrice?.ToString()}|BidTime={BidTime?.ToString("yyyy-MM-dd HH:mm:ss.fff")}|TradePrice={TradePrice?.ToString()}|TradeTime={TradeTime?.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
 }