Beispiel #1
0
        public static void RunExample(Dictionary <string, string> dict)
        {
            ExchangeKrakenAPI api    = new ExchangeKrakenAPI();
            ExchangeTicker    ticker = api.GetTicker("XXBTZUSD");

            Console.WriteLine("On the Kraken exchange, 1 bitcoin is worth {0} USD.", ticker.Bid);

            // load API keys created from ExchangeSharpConsole.exe keys mode=create path=keys.bin keylist=public_key,private_key
            api.LoadAPIKeys("keys.bin");

            /// place limit order for 0.01 bitcoin at ticker.Ask USD
            ExchangeOrderResult result = api.PlaceOrder(new ExchangeOrderRequest
            {
                Amount = 0.01m,
                IsBuy  = true,
                Price  = ticker.Ask,
                Symbol = "XXBTZUSD"
            });

            // Kraken is a bit funny in that they don't return the order details in the initial request, so you have to follow up with an order details request
            //  if you want to know more info about the order - most other exchanges don't return until they have the order details for you.
            // I've also found that Kraken tends to fail if you follow up too quickly with an order details request, so sleep a bit to give them time to get
            //  their house in order.
            System.Threading.Thread.Sleep(500);
            result = api.GetOrderDetails(result.OrderId);

            Console.WriteLine("Placed an order on Kraken for 0.01 bitcoin at {0} USD. Status is {1}. Order id is {2}.", ticker.Ask, result.Result, result.OrderId);
        }
Beispiel #2
0
        public static async Task RunShowExchangeStats(Dictionary <string, string> dict)
        {
            string       marketSymbol  = "BTC-USD";
            string       marketSymbol2 = "XXBTZUSD";
            IExchangeAPI apiCoinbase   = new ExchangeCoinbaseAPI();
            IExchangeAPI apiGemini     = new ExchangeGeminiAPI();
            IExchangeAPI apiKraken     = new ExchangeKrakenAPI();
            IExchangeAPI apiBitfinex   = new ExchangeBitfinexAPI();

            while (true)
            {
                ExchangeTicker ticker = await apiCoinbase.GetTickerAsync(marketSymbol);

                ExchangeOrderBook orders = await apiCoinbase.GetOrderBookAsync(marketSymbol);

                decimal askAmountSum = orders.Asks.Values.Sum(o => o.Amount);
                decimal askPriceSum  = orders.Asks.Values.Sum(o => o.Price);
                decimal bidAmountSum = orders.Bids.Values.Sum(o => o.Amount);
                decimal bidPriceSum  = orders.Bids.Values.Sum(o => o.Price);

                ExchangeTicker ticker2 = await apiGemini.GetTickerAsync(marketSymbol);

                ExchangeOrderBook orders2 = await apiGemini.GetOrderBookAsync(marketSymbol);

                decimal askAmountSum2 = orders2.Asks.Values.Sum(o => o.Amount);
                decimal askPriceSum2  = orders2.Asks.Values.Sum(o => o.Price);
                decimal bidAmountSum2 = orders2.Bids.Values.Sum(o => o.Amount);
                decimal bidPriceSum2  = orders2.Bids.Values.Sum(o => o.Price);

                ExchangeTicker ticker3 = await apiKraken.GetTickerAsync(marketSymbol2);

                ExchangeOrderBook orders3 = await apiKraken.GetOrderBookAsync(marketSymbol2);

                decimal askAmountSum3 = orders3.Asks.Values.Sum(o => o.Amount);
                decimal askPriceSum3  = orders3.Asks.Values.Sum(o => o.Price);
                decimal bidAmountSum3 = orders3.Bids.Values.Sum(o => o.Amount);
                decimal bidPriceSum3  = orders3.Bids.Values.Sum(o => o.Price);

                ExchangeTicker ticker4 = await apiBitfinex.GetTickerAsync(marketSymbol);

                ExchangeOrderBook orders4 = await apiBitfinex.GetOrderBookAsync(marketSymbol);

                decimal askAmountSum4 = orders4.Asks.Values.Sum(o => o.Amount);
                decimal askPriceSum4  = orders4.Asks.Values.Sum(o => o.Price);
                decimal bidAmountSum4 = orders4.Bids.Values.Sum(o => o.Amount);
                decimal bidPriceSum4  = orders4.Bids.Values.Sum(o => o.Price);

                Console.Clear();
                Console.WriteLine("GDAX: {0:0.00}, {1:0.00}, {2:0.00}, {3:0.00}, {4:0.00}, {5:0.00}", ticker.Last, ticker.Volume.QuoteCurrencyVolume, askAmountSum, askPriceSum, bidAmountSum, bidPriceSum);
                Console.WriteLine("GEMI: {0:0.00}, {1:0.00}, {2:0.00}, {3:0.00}, {4:0.00}, {5:0.00}", ticker2.Last, ticker2.Volume.QuoteCurrencyVolume, askAmountSum2, askPriceSum2, bidAmountSum2, bidPriceSum2);
                Console.WriteLine("KRAK: {0:0.00}, {1:0.00}, {2:0.00}, {3:0.00}, {4:0.00}, {5:0.00}", ticker3.Last, ticker3.Volume.QuoteCurrencyVolume, askAmountSum3, askPriceSum3, bidAmountSum3, bidPriceSum3);
                Console.WriteLine("BITF: {0:0.00}, {1:0.00}, {2:0.00}, {3:0.00}, {4:0.00}, {5:0.00}", ticker4.Last, ticker4.Volume.QuoteCurrencyVolume, askAmountSum4, askPriceSum4, bidAmountSum4, bidPriceSum4);
                Thread.Sleep(5000);
            }
        }
Beispiel #3
0
        public KrakenConnector()
        {
            api = new ExchangeKrakenAPI();
            var symbols = api.GetSymbols();

            Debug.Print("{0}: ", api.Name);
            foreach (var s in symbols)
            {
                Debug.Print("\t{0}", s);
            }
            base.Register(this);
        }
Beispiel #4
0
        private static void RunShowExchangeStats(Dictionary <string, string> dict)
        {
            string       symbol      = "BTC-USD";
            string       symbol2     = "XXBTZUSD";
            IExchangeAPI apiGDAX     = new ExchangeGdaxAPI();
            IExchangeAPI apiGemini   = new ExchangeGeminiAPI();
            IExchangeAPI apiKraken   = new ExchangeKrakenAPI();
            IExchangeAPI apiBitfinex = new ExchangeBitfinexAPI();

            while (true)
            {
                ExchangeTicker    ticker       = apiGDAX.GetTicker(symbol);
                ExchangeOrderBook orders       = apiGDAX.GetOrderBook(symbol);
                decimal           askAmountSum = orders.Asks.Sum(o => o.Amount);
                decimal           askPriceSum  = orders.Asks.Sum(o => o.Price);
                decimal           bidAmountSum = orders.Bids.Sum(o => o.Amount);
                decimal           bidPriceSum  = orders.Bids.Sum(o => o.Price);

                ExchangeTicker    ticker2       = apiGemini.GetTicker(symbol);
                ExchangeOrderBook orders2       = apiGemini.GetOrderBook(symbol);
                decimal           askAmountSum2 = orders2.Asks.Sum(o => o.Amount);
                decimal           askPriceSum2  = orders2.Asks.Sum(o => o.Price);
                decimal           bidAmountSum2 = orders2.Bids.Sum(o => o.Amount);
                decimal           bidPriceSum2  = orders2.Bids.Sum(o => o.Price);

                ExchangeTicker    ticker3       = apiKraken.GetTicker(symbol2);
                ExchangeOrderBook orders3       = apiKraken.GetOrderBook(symbol2);
                decimal           askAmountSum3 = orders3.Asks.Sum(o => o.Amount);
                decimal           askPriceSum3  = orders3.Asks.Sum(o => o.Price);
                decimal           bidAmountSum3 = orders3.Bids.Sum(o => o.Amount);
                decimal           bidPriceSum3  = orders3.Bids.Sum(o => o.Price);

                ExchangeTicker    ticker4       = apiBitfinex.GetTicker(symbol);
                ExchangeOrderBook orders4       = apiBitfinex.GetOrderBook(symbol);
                decimal           askAmountSum4 = orders4.Asks.Sum(o => o.Amount);
                decimal           askPriceSum4  = orders4.Asks.Sum(o => o.Price);
                decimal           bidAmountSum4 = orders4.Bids.Sum(o => o.Amount);
                decimal           bidPriceSum4  = orders4.Bids.Sum(o => o.Price);

                Console.Clear();
                Console.WriteLine("GDAX: {0:0.00}, {1:0.00}, {2:0.00}, {3:0.00}, {4:0.00}, {5:0.00}", ticker.Last, ticker.Volume.PriceAmount, askAmountSum, askPriceSum, bidAmountSum, bidPriceSum);
                Console.WriteLine("GEMI: {0:0.00}, {1:0.00}, {2:0.00}, {3:0.00}, {4:0.00}, {5:0.00}", ticker2.Last, ticker2.Volume.PriceAmount, askAmountSum2, askPriceSum2, bidAmountSum2, bidPriceSum2);
                Console.WriteLine("KRAK: {0:0.00}, {1:0.00}, {2:0.00}, {3:0.00}, {4:0.00}, {5:0.00}", ticker3.Last, ticker3.Volume.PriceAmount, askAmountSum3, askPriceSum3, bidAmountSum3, bidPriceSum3);
                Console.WriteLine("BITF: {0:0.00}, {1:0.00}, {2:0.00}, {3:0.00}, {4:0.00}, {5:0.00}", ticker4.Last, ticker4.Volume.PriceAmount, askAmountSum4, askPriceSum4, bidAmountSum4, bidPriceSum4);
                Thread.Sleep(5000);
            }
        }
        public override async Task RunCommand()
        {
            using var api = new ExchangeKrakenAPI();
            var ticker = await api.GetTickerAsync("XXBTZUSD");

            Console.WriteLine("On the Kraken exchange, 1 bitcoin is worth {0} USD.", ticker.Bid);

            try
            {
                // load API keys created from ExchangeSharpConsole.exe keys mode=create path=keys.bin keylist=public_key,private_key
                api.LoadAPIKeys(KeyPath);
            }
            catch (ArgumentException)
            {
                Console.Error.WriteLine(
                    "Invalid key file.\n" +
                    "Try generating a key file with the \"keys\" utility."
                    );
                Environment.Exit(Program.ExitCodeError);
                return;
            }

            // place limit order for 0.01 bitcoin at ticker.Ask USD
            var result = await api.PlaceOrderAsync(new ExchangeOrderRequest
            {
                Amount       = 0.01m,
                IsBuy        = true,
                Price        = ticker.Ask,
                MarketSymbol = "XXBTZUSD"
            });

            // Kraken is a bit funny in that they don't return the order details in the initial request, so you have to follow up with an order details request
            //  if you want to know more info about the order - most other exchanges don't return until they have the order details for you.
            // I've also found that Kraken tends to fail if you follow up too quickly with an order details request, so sleep a bit to give them time to get
            //  their house in order.
            await Task.Delay(500);

            result = await api.GetOrderDetailsAsync(result.OrderId);

            Console.WriteLine(
                "Placed an order on Kraken for 0.01 bitcoin at {0} USD. Status is {1}. Order id is {2}.",
                ticker.Ask, result.Result, result.OrderId
                );
        }
Beispiel #6
0
 public KrakenExchangeRateProvider()
 {
     _Helper = new ExchangeKrakenAPI();
 }
Beispiel #7
0
        public override async Task RunCommand()
        {
            var marketSymbol  = "BTC-USD";
            var marketSymbol2 = "XXBTZUSD";

            IExchangeAPI
                apiCoinbase = new ExchangeCoinbaseAPI(),
                apiGemini   = new ExchangeGeminiAPI(),
                apiKraken   = new ExchangeKrakenAPI(),
                apiBitfinex = new ExchangeBitfinexAPI();

            //TODO: Make this multi-threaded and add parameters
            Console.WriteLine("Use CTRL-C to stop.");

            while (true)
            {
                var ticker = await apiCoinbase.GetTickerAsync(marketSymbol);

                var orders = await apiCoinbase.GetOrderBookAsync(marketSymbol);

                var askAmountSum = orders.Asks.Values.Sum(o => o.Amount);
                var askPriceSum  = orders.Asks.Values.Sum(o => o.Price);
                var bidAmountSum = orders.Bids.Values.Sum(o => o.Amount);
                var bidPriceSum  = orders.Bids.Values.Sum(o => o.Price);

                var ticker2 = await apiGemini.GetTickerAsync(marketSymbol);

                var orders2 = await apiGemini.GetOrderBookAsync(marketSymbol);

                var askAmountSum2 = orders2.Asks.Values.Sum(o => o.Amount);
                var askPriceSum2  = orders2.Asks.Values.Sum(o => o.Price);
                var bidAmountSum2 = orders2.Bids.Values.Sum(o => o.Amount);
                var bidPriceSum2  = orders2.Bids.Values.Sum(o => o.Price);

                var ticker3 = await apiKraken.GetTickerAsync(marketSymbol2);

                var orders3 = await apiKraken.GetOrderBookAsync(marketSymbol2);

                var askAmountSum3 = orders3.Asks.Values.Sum(o => o.Amount);
                var askPriceSum3  = orders3.Asks.Values.Sum(o => o.Price);
                var bidAmountSum3 = orders3.Bids.Values.Sum(o => o.Amount);
                var bidPriceSum3  = orders3.Bids.Values.Sum(o => o.Price);

                var ticker4 = await apiBitfinex.GetTickerAsync(marketSymbol);

                var orders4 = await apiBitfinex.GetOrderBookAsync(marketSymbol);

                var askAmountSum4 = orders4.Asks.Values.Sum(o => o.Amount);
                var askPriceSum4  = orders4.Asks.Values.Sum(o => o.Price);
                var bidAmountSum4 = orders4.Bids.Values.Sum(o => o.Amount);
                var bidPriceSum4  = orders4.Bids.Values.Sum(o => o.Price);

                Console.Clear();
                Console.WriteLine("GDAX: {0,13:N}, {1,15:N}, {2,8:N}, {3,13:N}, {4,8:N}, {5,13:N}", ticker.Last,
                                  ticker.Volume.QuoteCurrencyVolume, askAmountSum, askPriceSum, bidAmountSum, bidPriceSum);
                Console.WriteLine("GEMI: {0,13:N}, {1,15:N}, {2,8:N}, {3,13:N}, {4,8:N}, {5,13:N}", ticker2.Last,
                                  ticker2.Volume.QuoteCurrencyVolume, askAmountSum2, askPriceSum2, bidAmountSum2, bidPriceSum2);
                Console.WriteLine("KRAK: {0,13:N}, {1,15:N}, {2,8:N}, {3,13:N}, {4,8:N}, {5,13:N}", ticker3.Last,
                                  ticker3.Volume.QuoteCurrencyVolume, askAmountSum3, askPriceSum3, bidAmountSum3, bidPriceSum3);
                Console.WriteLine("BITF: {0,13:N}, {1,15:N}, {2,8:N}, {3,13:N}, {4,8:N}, {5,13:N}", ticker4.Last,
                                  ticker4.Volume.QuoteCurrencyVolume, askAmountSum4, askPriceSum4, bidAmountSum4, bidPriceSum4);
                Thread.Sleep(IntervalMs);
            }
        }