Beispiel #1
0
 private void Dispatch(TickerModel tickerModel)
 {
     this.Ask       = tickerModel.Ask;
     this.Bid       = tickerModel.Bid;
     this.LastPrice = tickerModel.LastPrice;
     this.DateTime  = tickerModel.DateTime;
     this.Mid       = tickerModel.Mid;
     OnPropertyChanged("IsAsk");
 }
 public JsonResult Tick()
 {
     TickerModel model = new TickerModel();
     model.IPAddress = Request.UserHostAddress;
     model = _taService.Tick(model);
     model.IPAddress = Request.UserHostAddress;
     ViewBag.NewMessagesCount = model.NewMessagesCount;
     return Json(model, JsonRequestBehavior.AllowGet);
 }
Beispiel #3
0
        public async Task <IActionResult> AddTicker(TickerModel ticker)
        {
            var cmd = new Add.Command {
                Ticker = ticker
            };
            var cnt = await _mediator.Send(cmd);

            return(Ok(cnt));
        }
Beispiel #4
0
        public async Task <List <TickerModel> > ConvertTickerToFloatAndRemoveUsdt()
        {
            var coinList = new List <TickerModel>();
            var response = await _binanceClient.GetTwentyFourHourTickerInfo();

            var newResponse = RemoveUsdt(response);

            foreach (var coin in newResponse)
            {
                var tempObject = new TickerModel();
                tempObject.Symbol             = coin.symbol;
                tempObject.PriceChangePercent = float.Parse(coin.priceChangePercent);
                tempObject.PriceChange        = double.Parse(coin.priceChange);
                tempObject.Count = coin.count;
                coinList.Add(tempObject);
            }
            return(coinList);
        }
            internal static List <string> FormatTicker(TickerModel ticker)
            {
                var b = IrcConstants.IrcBold;
                var n = IrcConstants.IrcNormal;

                DateTime updateDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Convert.ToInt64(ticker.LastUpdated));

                // I think I'm gonna have an aneurysm, why is there no format option where I can keep all my decimal places? F**k you C#
                int decimalPlaces = ticker.PriceUsd.Split('.').Last().Length;

                string response =
                    $"{b}{ticker.TickerName} ({ticker.Symbol}):{n} " +
                    $"{b}Price:{n} ${Convert.ToDouble(ticker.PriceUsd).ToString("N" + decimalPlaces)} / {ticker.PriceBtc} BTC; {b}Volume (24h):{n} {Convert.ToDecimal(ticker.DayVolumeUsd):n0}; " +
                    $"{b}“Market Cap”:{n} ${Convert.ToDecimal(ticker.MarketCapUsd):n0}; " +
                    $"{b}Change:{n} 1h: {FormatPercentChange(Convert.ToDouble(ticker.PercentChange1Hour))}, 24h: {FormatPercentChange(Convert.ToDouble(ticker.PercentChange24Hours))}, 7d: {FormatPercentChange(Convert.ToDouble(ticker.PercentChange7Days))}; " +
                    $"{b}Last Updated:{n} {(DateTime.UtcNow - updateDate).Humanize()} ago";

                return(response.SplitInParts(430).ToList());
            }
Beispiel #6
0
        public TickerModel Transform()
        {
            if (TickerResponseResult == null)
            {
                return(new TickerModel()
                {
                    ResponseState = ResponseState.Error
                });
            }
            var ticker = TickerResponseResult.Values.First();


            var rs = new TickerModel
            {
                DateTime             = DateTime.Now,
                Ask                  = ticker.Ask[0],
                AskVolume            = ticker.Ask[1],
                Bid                  = ticker.Bid[0],
                BidVolume            = ticker.Bid[1],
                LastPrice            = ticker.LastTradeClosed[0],
                LastPriceVolume      = ticker.LastTradeClosed[1],
                VolumeToday          = ticker.Volume[0],
                Volume24Hour         = ticker.Volume[1],
                VolumeAverageToday   = ticker.VolumeWeightedAveragePrice[0],
                VolumeAverage24Hour  = ticker.VolumeWeightedAveragePrice[1],
                LowToday             = ticker.Low[0],
                Low24Hour            = ticker.Low[1],
                HighToday            = ticker.High[0],
                High24Hour           = ticker.High[1],
                NumberOfTradesToday  = ticker.NumberOfTrades[0],
                NumberOfTrades24Hour = ticker.NumberOfTrades[1],
                OpeningPriceToday    = ticker.OpeningPriceToday
            };

            return(rs);
        }
 public TickerModel Tick(TickerModel tick)
 {
     TickerRequest request = (TickerRequest)GetMappedObject(tick, typeof(TickerRequest));
     return (TickerModel)GetMappedObject(_travelersAroundService.Tick(request), typeof(TickerModel));
 }
Beispiel #8
0
        private Task GetTicker(CurrencyPair currencyPair, double amount, double pricePaid, ulong idOrder = 0)
        {
            IDictionary <CurrencyPair, IMarketData> markets;
            IMarketData marketToTrade = null;
            IMarketData usdtMarket    = null;

            double previousProfit    = -1;
            double profit            = 0;
            double highestProfit     = 0;
            double highestProfitDiff = 0;
            double highestPrice      = 0;
            double baseCurrencyTotal = 0;
            double usdtValue         = 0;

            var currencyPairUsdt = new CurrencyPair(CURRENCY_USDT, currencyPair.BaseCurrency);

            double baseCurrencyUnitPrice = 0;

            // Aller chercher le marché une 1ère fois en dehors du while pour figer dans le temps les données de départ
            markets       = BIZ.GetSummary();
            marketToTrade = BIZ.GetCurrency(markets, currencyPair);

            if (idOrder != 0)
            {
                // Aller chercher les vraies chiffres
                amount = (from x in BIZ.GetBalances() where x.Type == currencyPair.QuoteCurrency select x.USDT_Value).SingleOrDefault();

                pricePaid = BIZ.GetTrades(currencyPair).Where(x => x.IdOrder == idOrder).FirstOrDefault().PricePerCoin;
            }
            else
            {
                // Si le prix payé n'a pas été défini par l'utilisateur, prendre le prix courant
                if (pricePaid == 0)
                {
                    pricePaid = marketToTrade.PriceLast;
                }
            }

            // Enlève un pourcentage du montant à transiger si le prix payé était plus haut que le prix courant
            amount = amount + (marketToTrade.PriceLast / pricePaid) * 100 - 100;

            // Identifier l'unité de base de la monnaie à marchander
            if (currencyPair.BaseCurrency == CURRENCY_USDT)
            {
                baseCurrencyUnitPrice = amount / marketToTrade.PriceLast;
            }
            else
            {
                usdtMarket            = BIZ.GetCurrency(markets, currencyPairUsdt);
                baseCurrencyUnitPrice = (amount / usdtMarket.PriceLast) / marketToTrade.PriceLast;
            }

            TickerModel ticker;

            return(Task.Run(async() =>
            {
                while (!_cts.IsCancellationRequested)
                {
                    try
                    {
                        marketToTrade = BIZ.GetCurrency(currencyPair);

                        profit = (marketToTrade.PriceLast / pricePaid) * 100 - 100;
                        highestProfit = profit > highestProfit ? profit : highestProfit;

                        // Évite d'afficher les données si rien n'a changé
                        if (Math.Round(previousProfit, 4) != Math.Round(profit, 4))
                        {
                            previousProfit = profit;
                            highestPrice = marketToTrade.PriceLast > highestPrice ? marketToTrade.PriceLast : highestPrice;
                            highestProfitDiff = (marketToTrade.PriceLast / highestPrice) * 100 - 100;
                            baseCurrencyTotal = marketToTrade.PriceLast * baseCurrencyUnitPrice;
                            usdtValue = baseCurrencyTotal * (currencyPair.BaseCurrency == CURRENCY_USDT ? 1 : usdtMarket.PriceLast);

                            ticker = new TickerModel()
                            {
                                //CurrencyPair = currencyPair,
                                PriceLast = marketToTrade.PriceLast,
                                HighestPrice = highestPrice,
                                Profit = profit,
                                HighestProfit = highestProfit,
                                HPDiff = highestProfitDiff,
                                BaseCurrencyTotal = baseCurrencyTotal,
                                UsdtValue = usdtValue,
                                LastTicker = DateTime.Now
                            };

                            _tickerSubject.OnNext(ticker);
                        }

                        await Task.Delay(5000);
                    }
                    // erreurs connues: 404
                    catch (WebException ex)
                    {
                        Debug.WriteLine($"{DateTime.Now} - GetTicker() - {ex.Message}");
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"{DateTime.Now} - GetTicker() - {ex.Message}");
                    }
                }

                _tickerSubject.OnCompleted();
            }));
        }