static void Vwap(IExchangeAPI api, string exchange, string global_symbol, bool displayTrades = false)
 {
     try
     {
         var symbol = api.GlobalSymbolToExchangeSymbol(global_symbol);                       // "BTC-KRW" for Bithumb?
         //api.GetSymbols().ToList().ForEach(s => Console.WriteLine(s));
         //var ticker = api.GetTicker(symbol);
         //Console.WriteLine("On the {0} exchange, 1 bitcoin is worth {0} USD.", exchange, ticker.Bid);
         var trades = api.GetRecentTrades(symbol);
         if (displayTrades)
         {
             trades.ToList().ForEach(t => t.Print());
         }
         int tradeCount = trades.Count();
         if (tradeCount == 0)
         {
             Console.WriteLine("Zero trades returned for [{0} {1}].", exchange, symbol);
             //Console.WriteLine("[{0} {1}] ({2} trades)", exchange, symbol, tradeCount);
             return;
         }
         var sumPQ        = trades.Sum(t => t.Price * t.Amount);
         var sumQ         = trades.Sum(t => t.Amount);
         var vwap         = sumPQ / sumQ;
         var sortedTrades = trades.OrderBy(t => t.Timestamp);
         var firstTime    = sortedTrades.First().Timestamp;
         var lastTime     = sortedTrades.Last().Timestamp;
         var minutes      = lastTime.Subtract(firstTime).TotalMinutes;
         Console.WriteLine("[{0} {1}] ({2} trades) VWAP = {3:0.00000000}           first:{4}  last:{5}  ({6:0.0} minutes)", exchange, symbol, tradeCount, vwap, firstTime, lastTime, minutes);
     }
     catch (Exception ex)
     {
         Console.WriteLine("***[{0} {1}] ERROR: {2}***", exchange, global_symbol, ex.Message);
     }
 }
Example #2
0
 static string Vwap(IExchangeAPI api, string exchange, string global_symbol, bool displayTrades = false)
 {
     try
     {
         var symbol = api.GlobalSymbolToExchangeSymbol(global_symbol);       // "BTC-KRW" for Bithumb?
         var trades = api.GetRecentTrades(symbol);
         if (displayTrades)
         {
             trades.ToList().ForEach(t => t.Print());
         }
         int tradeCount = trades.Count();
         if (tradeCount == 0)
         {
             return($"Zero trades returned for [{exchange} {symbol}].\n");
         }
         var sumPQ        = trades.Sum(t => t.Price * t.Amount);
         var sumQ         = trades.Sum(t => t.Amount);
         var vwap         = sumPQ / sumQ;
         var sortedTrades = trades.OrderBy(t => t.Timestamp);
         var firstTime    = sortedTrades.First().Timestamp;
         var lastTime     = sortedTrades.Last().Timestamp;
         var minutes      = lastTime.Subtract(firstTime).TotalMinutes;
         return(string.Format("[{0} {1}] ({2} trades) VWAP = {3:0.00000000}           first:{4}  last:{5}  ({6:0.0} minutes)\n", exchange, symbol, tradeCount, vwap, firstTime, lastTime, minutes));
     }
     catch (Exception ex)
     {
         return(string.Format("***[{0} {1}] ERROR: {2}***\n", exchange, global_symbol, ex.Message));
     }
 }
Example #3
0
        public string GlobalToExchangeSymbol(string exchange, string symbol)
        {
            IExchangeAPI api            = ExchangeAPI.GetExchangeAPI(exchange.ToLower());
            string       exchangeSymbol = api.GlobalSymbolToExchangeSymbol(symbol);

            return(exchangeSymbol);
        }
Example #4
0
        public string GlobalToTradingViewSymbol(string exchange, string symbol)
        {
            //Trading view use same format as Binance -> BTC-ETH is ETHBTC
            IExchangeAPI api            = ExchangeAPI.GetExchangeAPI("binance");
            string       exchangeSymbol = api.GlobalSymbolToExchangeSymbol(symbol);

            return(exchangeSymbol);
        }
Example #5
0
        // Get currency value in BTC for the given amount
        // where currency like "ETH", "NEO", "TRX", ...
        public static decimal BtcValue(this IExchangeAPI api, string currency, decimal amount)
        {
            var globalSymbol = currency + "-BTC";
            var symbol       = api.GlobalSymbolToExchangeSymbol(globalSymbol);
            var t            = api.GetTicker(symbol);
            var btcAmount    = t.MidPrice() * amount;

            Console.WriteLine("{0,-8} {1,-6} {2,13:0.00000000}        btc:{3,13:0.00000000}", api.Name, currency, amount, btcAmount);
            return(btcAmount);
        }
Example #6
0
        /*private bool callback(IEnumerable<ExchangeTrade> trades)
         *      {
         *              trades.ToList().ForEach(t => t.Print());
         *              return true;
         *      }*/

        public void Candles(IExchangeAPI api, string global_symbol)
        {
            var      symbol    = api.GlobalSymbolToExchangeSymbol(global_symbol);
            int?     limit     = null;
            DateTime?startDate = null;
            DateTime?endDate   = null;
            var      candles   = api.GetCandles(symbol, 60, startDate, endDate, limit);

            foreach (var c in candles)
            {
                Console.WriteLine("{0} {1} [{2} {3}] o:{4} h:{5} l:{6} c:{7} vol:{8}", c.Timestamp, c.PeriodSeconds, c.ExchangeName, c.Name, c.OpenPrice, c.HighPrice, c.LowPrice, c.ClosePrice, c.BaseVolume);
            }
        }
Example #7
0
        private async Task Ticker(IExchangeAPI api, string exchange, string global_symbol)
        {
            try
            {
                var symbol = api.GlobalSymbolToExchangeSymbol(global_symbol);
                var ticker = await api.GetTickerAsync(symbol);

                //var ticker = api.GetTicker(symbol);
                Console.WriteLine("[{0,-10} {1,9}]      b:{2:0.00000000}      a:{3:0.00000000}", exchange, symbol, ticker.Bid, ticker.Ask);
            }
            catch (Exception ex)
            {
                //Console.WriteLine("***[{0} {1}] ERROR: {2}***", exchange, global_symbol, ""); //ex.Message);
            }
        }
Example #8
0
        private async Task <ExchangeOrderBook> OrderBook(IExchangeAPI api, string exchange, string global_symbol)
        {
            try
            {
                var symbol = api.GlobalSymbolToExchangeSymbol(global_symbol);
                var ob     = await api.GetOrderBookAsync(symbol);

                Console.WriteLine("[{0,-10} {1,9}]    {2,5} bids: {3:0.00000000}    {4,5} asks: {5:0.00000000} ", exchange, symbol, ob.Bids.Count, ob.Bids.First().Price, ob.Asks.Count, ob.Asks.First().Price);
                return(ob);
            }
            catch (Exception ex)
            {
                //Console.WriteLine("***[{0} {1}] ERROR: {2}***", exchange, global_symbol, ""); //ex.Message);
            }
            return(null);
        }
Example #9
0
        private void RecentTrades(IExchangeAPI api, string exchange, string global_symbol, bool displayTrades = false)
        {
            try
            {
                var symbol = api.GlobalSymbolToExchangeSymbol(global_symbol);                       // "BTC-KRW" for Bithumb?

                var trades = api.GetRecentTrades(symbol);
                if (displayTrades)
                {
                    trades.ToList().ForEach(t => t.Print());
                }
                int tradeCount = trades.Count();
                if (tradeCount == 0)
                {
                    //Console.WriteLine("[{0,-10} {1,9}]  {2,5} trades", exchange, symbol, tradeCount);
                    return;
                }
                Console.WriteLine("[{0,-10} {1,9}]  {2,5} trades", exchange, symbol, tradeCount);
            }
            catch (Exception ex)
            {
                //Console.WriteLine("***[{0} {1}] ERROR: {2}***", exchange, global_symbol, ""); //ex.Message);
            }
        }