public void SetCredentials(string aApiKey, string aApiSecret)
        {
            ApiCredentials lCredentials = new ApiCredentials(aApiKey, aApiSecret);

            BittrexClientOptions lClientOptions = new Bittrex.Net.Objects.BittrexClientOptions {
                ApiCredentials = lCredentials
            };
            BittrexSocketClientOptions lSocketOptions = new Bittrex.Net.Objects.BittrexSocketClientOptions {
                ApiCredentials = lCredentials
            };

            BittrexClient.SetDefaultOptions(lClientOptions);
            BittrexSocketClient.SetDefaultOptions(lSocketOptions);

            using (BittrexClient lClient = new BittrexClient())
            {
                CallResult <BittrexBalance> lResponse = lClient.GetBalanceAsync("BTC").Result;
                if (!lResponse.Success)
                {
                    throw new PandoraExchangeExceptions.InvalidExchangeCredentials("Incorrect Key Pair for selected exchange");
                }
            }
            //Note: I generate a new instance of ApiCredentials because internally the library dispose it
            FUserCredentials = new Tuple <string, string>(aApiKey, aApiSecret);
            IsCredentialsSet = true;
        }
示例#2
0
        static void Main(string[] args)
        {
            BittrexClient.SetDefaultOptions(new BittrexClientOptions()
            {
                ApiCredentials = new ApiCredentials("APIKEY", "APISECRET"),
                LogVerbosity   = LogVerbosity.Info,
                LogWriters     = new List <TextWriter>()
                {
                    Console.Out
                }
            });

            var client = new BittrexClient();

            // public
            var markets         = client.GetSymbols();
            var currencies      = client.GetCurrencies();
            var price           = client.GetTicker("BTC-ETH");
            var marketSummary   = client.GetSymbolSummary("BTC-ETH");
            var marketSummaries = client.GetSymbolSummaries();
            var orderbook       = client.GetOrderBook("BTC-ETH");
            var marketHistory   = client.GetSymbolTrades("BTC-ETH");

            // private
            // Commented to prevent accidental order placement
            //var placedOrder =
            //    client.PlaceOrder("BTC-USDT", OrderSide.Sell, OrderTypeV3.Limit, TimeInForce.GoodTillCancelled, 1, 1);
            //var orderInfo = client.GetOrder(placedOrder.Data.Id);
            //var canceledOrder = client.CancelOrder(placedOrder.Data.Id);
            var openOrders  = client.GetOpenOrders("BTC-USDT");
            var orderTrades = client.GetExecutions("BTC-NEO");

            var balance         = client.GetBalance("NEO");
            var balances        = client.GetBalances();
            var depositAddress  = client.GetDepositAddress("BTC");
            var withdraw        = client.Withdraw("TEST", 1, "TEST", "TEST");
            var withdrawHistory = client.GetClosedWithdrawals();
            var depositHistory  = client.GetClosedDeposits();


            // Websocket
            var socketClient = new BittrexSocketClient();
            var subscription = socketClient.SubscribeToSymbolTickerUpdatesAsync("ETH-BTC", ticker =>
            {
                Console.WriteLine($"ETH-BTC: {ticker.LastTradeRate}");
            });

            var subscription2 = socketClient.SubscribeToOrderBookUpdatesAsync("ETH-BTC", 25, state =>
            {
                // Order book update
            });

            var subscription3 = socketClient.SubscribeToBalanceUpdatesAsync(data =>
            {
                // Balance update
            });

            Console.ReadLine();
            socketClient.UnsubscribeAll();
        }
        private BittrexSocketClient PrepareClient()
        {
            proxy = new Mock <IHubProxy>();
            proxy.Setup(r => r.Invoke <bool>(It.IsAny <string>())).Returns(Task.FromResult(true));
            proxy.Setup(r => r.Subscribe(It.IsAny <string>())).Returns(new Subscription());

            socket = new Mock <Interfaces.IHubConnection>();
            socket.Setup(s => s.Stop(It.IsAny <TimeSpan>()));
            socket.Setup(s => s.Start()).Returns(Task.Run(() => Thread.Sleep(1))).Callback(() => { socket.Raise(s => s.StateChanged += null, new StateChange(ConnectionState.Connecting, ConnectionState.Connected)); });
            socket.Setup(s => s.State).Returns(ConnectionState.Connected);
            socket.Setup(s => s.CreateHubProxy(It.IsAny <string>())).Returns(proxy.Object);

            var factory = new Mock <IConnectionFactory>();

            factory.Setup(s => s.Create(It.IsAny <Log>(), It.IsAny <string>())).Returns(socket.Object);

            var client = new BittrexSocketClient {
                ConnectionFactory = factory.Object
            };

            client.GetType().GetField("connection", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).SetValue(client, null);
            client.GetType().GetField("registrations", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).SetValue(client, new List <BittrexRegistration>());
            client.GetType().GetField("reconnecting", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).SetValue(client, false);

            return(client);
        }
示例#4
0
        private BittrexSocketClient PrepareClient()
        {
            sub = new Subscription();

            proxy = new Mock <IHubProxy>();
            proxy.Setup(r => r.Subscribe(It.IsAny <string>())).Returns(sub);

            socket = new Mock <Interfaces.IHubConnection>();
            socket.Setup(s => s.Stop(It.IsAny <TimeSpan>()));
            socket.Setup(s => s.Start()).Callback(() => { socket.Raise(s => s.StateChanged += null, new StateChange(ConnectionState.Connecting, ConnectionState.Connected)); });
            socket.Setup(s => s.State).Returns(ConnectionState.Connected);
            socket.Setup(s => s.CreateHubProxy(It.IsAny <string>())).Returns(proxy.Object);

            var factory = new Mock <IConnectionFactory>();

            factory.Setup(s => s.Create(It.IsAny <string>())).Returns(socket.Object);

            cloud = new Mock <ICloudFlareAuthenticator>();
            cloud.Setup(c => c.GetCloudFlareCookies(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(new CookieContainer());

            var client = new BittrexSocketClient {
                ConnectionFactory = factory.Object, CloudFlareAuthenticator = cloud.Object
            };

            client.GetType().GetField("connection", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).SetValue(client, null);
            client.GetType().GetField("registrations", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).SetValue(client, new List <BittrexRegistration>());
            client.GetType().GetField("reconnecting", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).SetValue(client, false);

            return(client);
        }
示例#5
0
        static void Main(string[] args)
        {
            BittrexClient.SetDefaultOptions(new BittrexClientOptions()
            {
                ApiCredentials = new ApiCredentials("APIKEY", "APISECRET"),
                LogVerbosity   = LogVerbosity.Info,
                LogWriters     = new List <TextWriter>()
                {
                    Console.Out
                }
            });

            using (var client = new BittrexClient())
            {
                // public
                var markets         = client.GetMarkets();
                var currencies      = client.GetCurrencies();
                var price           = client.GetTicker("BTC-ETH");
                var marketSummary   = client.GetMarketSummary("BTC-ETH");
                var marketSummaries = client.GetMarketSummaries();
                var orderbook       = client.GetOrderBook("BTC-ETH");
                var marketHistory   = client.GetMarketHistory("BTC-ETH");

                // private
                // Commented to prevent accidental order placement
                //var placedOrder = client.PlaceOrder(OrderSide.Sell, "BTC-NEO", 1, 1);
                //var orderInfo = client.GetOrder(placedOrder.Data.Uuid);
                //var canceledOrder = client.CancelOrder(placedOrder.Data.Uuid);
                var openOrders   = client.GetOpenOrders("BTC-NEO");
                var orderHistory = client.GetOrderHistory("BTC-NEO");

                var balance         = client.GetBalance("NEO");
                var balances        = client.GetBalances();
                var depositAddress  = client.GetDepositAddress("BTC");
                var withdraw        = client.Withdraw("TEST", 1, "TEST", "TEST");
                var withdrawHistory = client.GetWithdrawalHistory();
                var depositHistory  = client.GetDepositHistory();
            }

            // Websocket
            var socketClient = new BittrexSocketClient();
            var subscription = socketClient.SubscribeToMarketSummariesUpdate(summaries =>
            {
                Console.WriteLine($"BTC-ETH: {summaries.SingleOrDefault(s => s.MarketName == "BTC-ETH")?.Last}");
            });

            var subscription2 = socketClient.SubscribeToExchangeStateUpdates("BTC-ETH", state =>
            {
            });

            var subscription3 = socketClient.SubscribeToOrderUpdates(order =>
            {
            });

            Console.ReadLine();
            socketClient.UnsubscribeAllStreams();
        }
示例#6
0
        // Assumes use of C# 7.1
        public static async Task Main()
        {
            BittrexDefaults.SetDefaultApiCredentials("APIKEY", "APISECRET");
            BittrexDefaults.SetDefaultLogOutput(Console.Out);
            BittrexDefaults.SetDefaultLogVerbosity(LogVerbosity.Debug);

            using (var client = new BittrexClient())
            {
                // public
                var markets = await client.GetMarketsAsync();

                var currencies = await client.GetCurrenciesAsync();

                var price = await client.GetTickerAsync("BTC-ETH");

                var marketSummary = await client.GetMarketSummaryAsync("BTC-ETH");

                var marketSummaries = await client.GetMarketSummariesAsync();

                var orderbook = await client.GetOrderBookAsync("BTC-ETH");

                var marketHistory = await client.GetMarketHistoryAsync("BTC-ETH");

                // private
                var placedOrder = await client.PlaceOrderAsync(OrderType.Sell, "BTC-NEO", 1, 1);

                var openOrders = await client.GetOpenOrdersAsync("BTC-NEO");

                var orderInfo = await client.GetOrderAsync(placedOrder.Result.Uuid);

                var canceledOrder = await client.CancelOrderAsync(placedOrder.Result.Uuid);

                var orderHistory = await client.GetOrderHistoryAsync("BTC-NEO");

                var balance = await client.GetBalanceAsync("NEO");

                var balances = await client.GetBalancesAsync();

                var depositAddress = await client.GetDepositAddressAsync("BTC");

                var withdraw = await client.WithdrawAsync("TEST", 1, "TEST", "TEST");

                var withdrawHistory = await client.GetWithdrawalHistoryAsync();

                var depositHistory = await client.GetDepositHistoryAsync();
            }

            // Websocket
            var socketClient = new BittrexSocketClient();
            var subcribtion  = socketClient.SubscribeToMarketDeltaStream("BTC-ETH", summary =>
            {
                Console.WriteLine($"BTC-ETH: {summary.Last}");
            });

            Console.ReadLine();
            socketClient.UnsubscribeFromStream(subcribtion.Result);
        }
示例#7
0
        static async Task DemoBittrexSymbolTickerUpdates(BittrexSocketClient sock, int sleepSeconds = 20)
        {
            string exchName = "BITTREX";

            Console.WriteLine($"--- Running {exchName} SymbolTickerUpdates thread for {sleepSeconds} seconds ---");
            var subscription = BittrexSubscribe(sock);

            Thread.Sleep(sleepSeconds * 1000);
            await BittrexUnsubscribe(sock, subscription);
        }
 internal BittrexExchange()
 {
     FBittrexSocket = new BittrexSocketClient();
     FMarketPrices  = new ConcurrentDictionary <string, MarketPriceInfo>();
     FMarketsIDsWithPriceChanged = new ConcurrentBag <string>();
     FCurrencyFees          = new ConcurrentDictionary <string, decimal>();
     FCurrencyConfirmations = new ConcurrentDictionary <string, int>();
     FLocalCacheOfMarkets   = new ConcurrentDictionary <long, IEnumerable <BittrexExchangeMarket> >();
     DoUpdateMarketCoins();
 }
示例#9
0
        public override void SetupConnector()
        {
            this.Client = new BittrexClient(new BittrexClientOptions()
            {
                ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials(this.InParameters["apiKey"].GetValue().ToString(), this.InParameters["apiSecret"].GetValue().ToString())
            });

            this.SocketClient = new BittrexSocketClient();

            this.Next();
        }
示例#10
0
        public void TestSocket()
        {
            var lSocketClient = new BittrexSocketClient();
            var lResult       = lSocketClient.SubscribeToSymbolTickerUpdatesAsync((lBittrexSummaries) =>
            {
            });

            while (true)
            {
                System.Threading.Thread.Sleep(1000);
            }
        }
        public void Clear()
        {
            BittrexClientOptions lClientOptions = new Bittrex.Net.Objects.BittrexClientOptions {
                ApiCredentials = null
            };
            BittrexSocketClientOptions lSocketOptions = new Bittrex.Net.Objects.BittrexSocketClientOptions {
                ApiCredentials = null
            };

            BittrexClient.SetDefaultOptions(lClientOptions);
            BittrexSocketClient.SetDefaultOptions(lSocketOptions);
            IsCredentialsSet = false;
        }
示例#12
0
        private void LoadDone(object sender, EventArgs e)
        {
            socketClient = new BittrexSocketClient();
            socketClient.SubscribeToSymbolTickerUpdatesAsync("ETH-BTC", data =>
            {
                UpdateLastPrice(data.LastTradeRate);
            });

            using (var client = new BittrexClient())
            {
                var result = client.GetTicker("ETH-BTC");
                UpdateLastPrice(result.Data.LastTradeRate);
            }
        }
示例#13
0
        static void CreateBittrexExchange(out BittrexClient exch, out BittrexSocketClient sock)
        {
            var evKeys = Environment.GetEnvironmentVariable("BITTREX_KEY", EnvironmentVariableTarget.User);
            var keys   = evKeys.Split('|');

            var clientOptions = new BittrexClientOptions();

            clientOptions.ApiCredentials = new ApiCredentials(keys[0], keys[1]);
            exch = new BittrexClient(clientOptions);
            //----------
            var socketOptions = new BittrexSocketClientOptions();

            socketOptions.ApiCredentials = clientOptions.ApiCredentials;
            sock = new BittrexSocketClient(socketOptions);
        }
示例#14
0
        static UpdateSubscription BittrexSubscribe(BittrexSocketClient sock)
        {
            string exchName = "BITTREX";

            /*var crSubSymbolTicker = sock.Spot.SubscribeToAllSymbolTickerUpdates((binanceTick) =>
             * {
             *  Console.WriteLine($"[{exchName}]   {binanceTick.Count()} symbol ticker updates received");
             *  var tick = binanceTick.First();
             *  Console.WriteLine($"[{exchName} {tick.Symbol}]   {tick.BidQuantity}x{tick.BidPrice}  {tick.AskPrice}x{tick.AskQuantity}   (example 1st update)");
             * });
             *
             * var subSymbolTicker = crSubSymbolTicker.Data;
             * return subSymbolTicker;*/
            return(null);
        }
        //public BittrexExchange(KafkaProducer p)
        public BittrexExchange(string bootstrapServers, string topic)
        {
            var evKeys = Environment.GetEnvironmentVariable(ApiKeyEnvVar, EnvironmentVariableTarget.User);
            var keys = evKeys.Split('|');

            var clientOptions = new BittrexClientOptions();
            clientOptions.ApiCredentials = new ApiCredentials(keys[0], keys[1]);
            this.exch = new BittrexClient(clientOptions);
            //----------
            var socketOptions = new BittrexSocketClientOptions();
            socketOptions.ApiCredentials = clientOptions.ApiCredentials;
            this.sock = new BittrexSocketClient(socketOptions);

            //_p = p;
            _p = new KafkaProducer(bootstrapServers, topic);
        }
示例#16
0
        public void Init()
        {
            BittrexClient.SetDefaultOptions(new BittrexClientOptions()
            {
                ApiCredentials = new ApiCredentials(_settings.Bittrex.Key, _settings.Bittrex.Secret),
                LogVerbosity   = LogVerbosity.Info,
                LogWriters     = new List <TextWriter>()
                {
                    Console.Out
                }
            });

            _httpClient   = new BittrexClient();
            _socketClient = new BittrexSocketClient();

            _placeOrderWorker.Start();
        }
示例#17
0
        static void Main(string[] args)
        {
            BittrexClient.SetDefaultOptions(new BittrexClientOptions()
            {
                ApiCredentials = new ApiCredentials("APIKEY", "APISECRET"),
                LogVerbosity   = LogVerbosity.Info,
                LogWriter      = Console.Out
            });

            using (var client = new BittrexClient())
            {
                // public
                var markets         = client.GetMarkets();
                var currencies      = client.GetCurrencies();
                var price           = client.GetTicker("BTC-ETH");
                var marketSummary   = client.GetMarketSummary("BTC-ETH");
                var marketSummaries = client.GetMarketSummaries();
                var orderbook       = client.GetOrderBook("BTC-ETH");
                var marketHistory   = client.GetMarketHistory("BTC-ETH");

                // private
                var placedOrder   = client.PlaceOrder(OrderSide.Sell, "BTC-NEO", 1, 1);
                var openOrders    = client.GetOpenOrders("BTC-NEO");
                var orderInfo     = client.GetOrder(placedOrder.Data.Uuid);
                var canceledOrder = client.CancelOrder(placedOrder.Data.Uuid);
                var orderHistory  = client.GetOrderHistory("BTC-NEO");

                var balance         = client.GetBalance("NEO");
                var balances        = client.GetBalances();
                var depositAddress  = client.GetDepositAddress("BTC");
                var withdraw        = client.Withdraw("TEST", 1, "TEST", "TEST");
                var withdrawHistory = client.GetWithdrawalHistory();
                var depositHistory  = client.GetDepositHistory();
            }

            // Websocket
            var socketClient = new BittrexSocketClient();
            var subcribtion  = socketClient.SubscribeToMarketDeltaStream("BTC-ETH", summary =>
            {
                Console.WriteLine($"BTC-ETH: {summary.Last}");
            });

            Console.ReadLine();
            socketClient.UnsubscribeFromStream(subcribtion.Data);
        }
示例#18
0
        public void Initialize(string apiKey, string apiSecret, bool isInTestMode)
        {
            var apiCredentials = new ApiCredentials(apiKey, apiSecret);

            _bittrexClient = new BittrexClient(new BittrexClientOptions
            {
                ApiCredentials = apiCredentials
            });
            _bittrexSocketClient = new BittrexSocketClient(new BittrexSocketClientOptions
            {
                ApiCredentials = apiCredentials
            });

            if (!isInTestMode)
            {
                _bittrexSocketClient.SubscribeToMarketSummariesUpdate(OnMarketsUpdate);
                _bittrexSocketClient.SubscribeToOrderUpdates(OnOrderUpdate);
            }
        }
示例#19
0
        private void LoadDone(object sender, EventArgs e)
        {
            socketClient = new BittrexSocketClient();
            socketClient.SubscribeToMarketSummariesUpdate(data =>
            {
                var eth = data.SingleOrDefault(d => d.MarketName == "BTC-ETH");
                if (eth != null)
                {
                    UpdateLastPrice(eth.Last);
                }
            });

            using (var client = new BittrexClient())
            {
                var result = client.GetMarketSummary("BTC-ETH");
                UpdateLastPrice(result.Data.Last);
                label2.Invoke(new Action(() => { label2.Text = "BTC-ETH Volume: " + result.Data.Volume; }));
            }
        }
示例#20
0
        private void LoadDone(object sender, EventArgs e)
        {
            Task.Run(() =>
            {
                socketClient = new BittrexSocketClient();
                socketClient.SubscribeToMarketDeltaStream("BTC-ETH", data =>
                {
                    UpdateLastPrice(data.Last);
                });
            });

            Task.Run(() =>
            {
                using (var client = new BittrexClient())
                {
                    var result = client.GetMarketSummary("BTC-ETH");
                    UpdateLastPrice(result.Data.Last);
                    label2.Invoke(new Action(() => { label2.Text = "BTC-ETH Volume: " + result.Data.Volume; }));
                }
            });
        }
示例#21
0
 static async Task BittrexUnsubscribe(BittrexSocketClient sock, UpdateSubscription subscription)
 {
     await sock.Unsubscribe(subscription);
 }
示例#22
0
        private void PerformConnect(string url)
        {
            if (_websocket != null)
            {
                DisposeWebSocket();
            }

            _webSocketTokenSource = new CancellationTokenSource();
            _webSocketTokenSource.Token.Register(WebSocketTokenSourceCanceled);
            CancellationTokenSource.CreateLinkedTokenSource(_webSocketTokenSource.Token, _disconnectToken);

            // SignalR uses https, websocket4net uses wss
            url = url.Replace("http://", "ws://").Replace("https://", "wss://");

            IDictionary <string, string> cookies = new Dictionary <string, string>();

            if (_connection.CookieContainer != null)
            {
                var container = _connection.CookieContainer.GetCookies(new Uri(_connection.Url));
                foreach (Cookie cookie in container)
                {
                    cookies.Add(cookie.Name, cookie.Value);
                }
            }

            // Add the header from the connection to the socket connection
            var headers = _connection.Headers.ToList();

//            _websocket = new WebsocketNative(url, _connection.CookieContainer.GetCookieHeader(new Uri(url)), BittrexSocketClient.GetUserAgentString());

#if !NETSTANDARD
            _websocket = new WebsocketSharp(url, _connection.CookieContainer.GetCookieHeader(new Uri(url)), BittrexSocketClient.GetUserAgentString());
#else
            _websocket = new Websocket4Net(url, cookies, _connection.Headers);
#endif

            _websocket.OnError   += WebSocketOnError;
            _websocket.OnOpen    += WebSocketOnOpened;
            _websocket.OnClose   += WebSocketOnClosed;
            _websocket.OnMessage += WebSocketOnMessageReceived;

            _websocket.setProxy(_connection.Proxy);

            _websocket.Open();
        }
示例#23
0
        // Assumes use of C# 7.1
        public static async Task Main()
        {
            BittrexClient.SetDefaultOptions(new BittrexClientOptions()
            {
                ApiCredentials = new ApiCredentials("APIKEY", "APISECRET"),
                LogVerbosity   = LogVerbosity.Info,
                LogWriter      = Console.Out
            });

            using (var client = new BittrexClient())
            {
                // public
                var markets = await client.GetMarketsAsync();

                var currencies = await client.GetCurrenciesAsync();

                var price = await client.GetTickerAsync("BTC-ETH");

                var marketSummary = await client.GetMarketSummaryAsync("BTC-ETH");

                var marketSummaries = await client.GetMarketSummariesAsync();

                var orderbook = await client.GetOrderBookAsync("BTC-ETH");

                var marketHistory = await client.GetMarketHistoryAsync("BTC-ETH");

                // private
                var placedOrder = await client.PlaceOrderAsync(OrderSide.Sell, "BTC-NEO", 1, 1);

                var openOrders = await client.GetOpenOrdersAsync("BTC-NEO");

                var orderInfo = await client.GetOrderAsync(placedOrder.Data.Uuid);

                var canceledOrder = await client.CancelOrderAsync(placedOrder.Data.Uuid);

                var orderHistory = await client.GetOrderHistoryAsync("BTC-NEO");

                var balance = await client.GetBalanceAsync("NEO");

                var balances = await client.GetBalancesAsync();

                var depositAddress = await client.GetDepositAddressAsync("BTC");

                var withdraw = await client.WithdrawAsync("TEST", 1, "TEST", "TEST");

                var withdrawHistory = await client.GetWithdrawalHistoryAsync();

                var depositHistory = await client.GetDepositHistoryAsync();
            }

            // Websocket
            var socketClient = new BittrexSocketClient();
            var subcription  = socketClient.SubscribeToMarketDeltaStream("BTC-ETH", summary =>
            {
                // Handle data
            });

            socketClient.SubscribeToAllMarketDeltaStream(data =>
            {
                // Handle data
            });
            socketClient.SubscribeToExchangeDeltas("BTC-ETH", data =>
            {
                // Handle data
            });

            Console.ReadLine();
            socketClient.UnsubscribeAllStreams();
        }