示例#1
0
        public async Task <BaseTypes.Ticker> GetMarketPrice(BaseTypes.Market Market, InvokePrint Print)
        {
            try
            {
                Ticker tmp = await bittrex.GetTicker(Market.MarketName);

                if (tmp.Ask == null || tmp.Bid == null)
                {
                    Print("Ask or Bid is null!");
                    return(null);
                }
                return(new BaseTypes.Ticker
                {
                    Ask = tmp.Ask.Value,
                    Bid = tmp.Bid.Value,
                });
            }
            catch (Exception ex)
            {
                System.Media.SystemSounds.Beep.Play();
                Print(String.Format("Ошибка BitrexApi GetMarketPrice: {0}.\r\nMarket: {1}.",
                                    ex.Message, Market.ToString()));
                return(null);
            }
        }
        void TradeBuy(string pair)
        {
            //string xpair = ohlc.Pairs.Keys.First();
            var ticker = bittrex.GetTicker(pair);

            cout("\n\n---BUY:");
            ticker.Display("ticker:");
            var t = ticker; // ticker.Values.First();

            cout("{0}  buy {1} unit(s) pay {2} (asksize:{3})          [LONG TRADE: {4}]\n\n", pair, m_tradeUnits, t.AskPrice, t.AskVolume, DateTime.Now.ToShortTimeString());
            m_pos += 2;
            // TODO: append trade to file
            m_tradeUnits = 2;                       // after the first trade, we always buy/sell 2 units
        }
示例#3
0
        public void GetTicker_ShouldNotThrowException()
        {
            var         bittrex = new Bittrex();
            Func <Task> action  = async() => { var _ = await bittrex.GetTicker(DefaultMarketName); };

            action.ShouldNotThrow();
        }
示例#4
0
        public async void TickerInvalidOnline()
        {
            var r   = new Maybe <IDownloadData>();
            var b   = new Bittrex(r);
            var res = await b.GetTicker("NotValid");

            Assert.Equal("INVALID_MARKET", res.Message);
        }
示例#5
0
        public async Task <decimal> GetPrice(string baseCcy, string termsCurrency)
        {
            var apiKey    = "...";
            var apiSecret = "...";
            var bittrex   = new Bittrex(apiKey, apiSecret);

            Ticker tcik = null;

            try
            {
                tcik = await bittrex.GetTicker(baseCcy, termsCurrency);
            }
            catch (Exception ex)
            {
                // should log
            }

            if (tcik != null && tcik.Last.HasValue)
            {
                return(tcik.Last.Value);
            }

            var btcPrice = await bittrex.GetTicker("BTC", termsCurrency);

            if (btcPrice?.Last != null)
            {
                var btcBasePrice = await bittrex.GetTicker("BTC", baseCcy);

                if (btcBasePrice?.Last != null)
                {
                    return(btcPrice.Last.Value * btcBasePrice.Last.Value);
                }
                else
                {
                    var baseBtcPrice = await bittrex.GetTicker(baseCcy, "BTC");

                    if (baseBtcPrice?.Last != null)
                    {
                        return(baseBtcPrice.Last.Value * btcPrice.Last.Value);
                    }
                }
            }
            return(0);
        }
示例#6
0
        public async Task <decimal> GetPrice(string baseCcy, string termsCurrency)
        {
            Ticker tcik = null;

            try
            {
                tcik = await _exchange.GetTicker(baseCcy, termsCurrency);
            }
            catch (Exception e)
            {
                _log.LogError("Error in getting ticker from bittrex: " + e.Message);
            }

            if (tcik != null && tcik.Last.HasValue)
            {
                return(tcik.Last.Value);
            }

            var btcPrice = await _exchange.GetTicker("BTC", termsCurrency);

            if (btcPrice?.Last != null)
            {
                var btcBasePrice = await _exchange.GetTicker("BTC", baseCcy);

                if (btcBasePrice?.Last != null)
                {
                    return(btcPrice.Last.Value * btcBasePrice.Last.Value);
                }
                else
                {
                    var baseBtcPrice = await _exchange.GetTicker(baseCcy, "BTC");

                    if (baseBtcPrice?.Last != null)
                    {
                        return(baseBtcPrice.Last.Value * btcPrice.Last.Value);
                    }
                }
            }
            return(0);
        }
示例#7
0
        private static async Task <ResponseWrapper <IEnumerable <TickerV2> > > GetBittrixTickerDataAsync()
        {
            Console.WriteLine("before");  // Step Out from here
            var apiKey    = "b6261f5e794f4c5fb0fcd8ede10eaea8";
            var apiSecret = "7c8e55b4d0b245779e4d645f7a5bc92f";
            var bittrex   = new Bittrex(apiKey, apiSecret);


            string DefaultMarketName = "BTC-ETH";
            string tickInterval      = "thirtyMin";
            UInt64 timeStamp         = 1500915289433;

            var result = await bittrex.GetTicker(DefaultMarketName, tickInterval, timeStamp);

            Console.WriteLine("after");  // Step Out from here
            return(result);
        }
示例#8
0
        public async Task <decimal> GetPrice(string baseCcy, string terms)
        {
            // USDT is not terms. But this bittrex library I'm using doesnt let me set it so checking via another method for the time being.
            switch (terms)
            {
            case "USD":
                return(await _priceService.GetDollarAmount(1));

            case "USDT":
                return(await _priceService.GetDollarAmount(1));

            case "BTC":
                return(0);
            }

            var ticker = await _exchange.GetTicker(baseCcy, terms);

            var     price = ticker.Last.ToString();
            decimal priceAsDecimal;

            try
            {
                priceAsDecimal = decimal.Parse(price, NumberStyles.Float);
            }
            catch (Exception)
            {
                try
                {
                    priceAsDecimal = await _priceService.GetPriceInBtc(terms);
                }
                catch (Exception)
                {
                    return(0);
                }
            }
            return(priceAsDecimal);
        }
示例#9
0
        public async void GetTicker()
        {
            var res = await bittrex.GetTicker("BTC-ETH");

            Assert.NotNull(res.Result);
        }