Exemple #1
0
 private void SocketApi_ConnectionStateChanged(HitSocketApi hitSocketApi, HitEventArgs e)
 {
     if (e.SocketError != null)
     {
         var dealTicket = DealTicketGenerator.CreateRefuseDealTicket(e.SocketError.Message);
         this.PushMessage(dealTicket);
     }
 }
Exemple #2
0
        //[TestMethod]
        //public void GetTradesByTimestampAsyncTest()
        //{
        //    var socketApi = CreateConnectedApi();
        //    string symbol = "ETHBTC";
        //    //DateTime from = new DateTime(2018, 5, 5, 12, 59, 0, DateTimeKind.Utc);
        //    //DateTime till = new DateTime(2018, 5, 5, 13, 0, 0, DateTimeKind.Utc);

        //    var response = socketApi.GetTradesByTimestampAsync(symbol, HitSort.Desc).Result;

        //    ResponseBasicCheck(response);

        //    Assert.AreNotEqual(0, response.Result.Length);
        //}

        //[TestMethod]
        //public void GetTradesByIdAsyncTest()
        //{
        //    var socketApi = CreateConnectedApi();
        //    string symbol = "ETHBTC";

        //    var response = socketApi.GetTradesByIdAsync(symbol, HitSort.Desc, limit: 3).Result;

        //    ResponseBasicCheck(response);

        //    Assert.AreNotEqual(0, response.Result.Length);
        //}

        #region Misc
        private static HitSocketApi CreateConnectedApi()
        {
            var socketApi = new HitSocketApi();

            socketApi.ConnectAsync().Wait();

            Assert.AreEqual(HitConnectionState.Connected, socketApi.ConnectionState);

            return(socketApi);
        }
Exemple #3
0
        private void SocketApi_Notification(HitSocketApi hitSocketApi, HitEventArgs e)
        {
            if (e.SocketError != null)
            {
                this.PushMessage(DealTicketGenerator.CreateRefuseDealTicket(e.SocketError.Message));
                Core.Instance.Loggers.Log(e.SocketError);
                return;
            }

            this.ProcessSocketNotification(e);
        }
Exemple #4
0
        public MarketDataVendor()
        {
            this.restApi   = new HitRestApi();
            this.socketApi = new HitSocketApi();
            this.socketApi.ConnectionStateChanged += this.SocketApi_ConnectionStateChanged;
            this.socketApi.Notification           += this.SocketApi_Notification;

            this.currenciesCache = new Dictionary <string, HitCurrency>();
            this.symbolsCache    = new Dictionary <string, HitSymbol>();

            this.ping    = new Ping();
            this.pingUri = new Uri("https://api.hitbtc.com/api/2");

            this.lastsTimeCache = new Dictionary <string, long>();

            this.aggressorFlagCalculator = new AggressorFlagCalculator();
        }
        public HitBTCClient(string startCoin, decimal waitingTime = 0, string key = "xxx", string sign = "xxx", decimal feeSell = 0.00054m, decimal feeBuy = 0.00054m) : base(startCoin: startCoin, feeBuy: feeBuy, feeSell: feeSell)
        {
            _hitbtcRestClient = new HitRestApi(new HitConfig
            {
                ApiKey = key,
                Secret = sign
            });
            _hitbctSocketApi = new HitSocketApi(new HitConfig
            {
                ApiKey = key,
                Secret = sign,
            });

            _currentAmount = UpdatedAmount;
            _lstMarket     = _hitbtcRestClient.GetSymbolsAsync().Result.Result.ToList();
            _waitingTime   = waitingTime;
        }
Exemple #6
0
        public void ConnectAsyncDisconnectAsyncTest()
        {
            var timeout = TimeSpan.FromSeconds(10);

            var cancellationTokenSource = new CancellationTokenSource(timeout);

            var lastConnectionState = HitConnectionState.PrepareToConnect;

            void ClientConnectionStateChanged(HitSocketApi hitSocketApi, HitEventArgs e)
            {
                lastConnectionState = e.ConnectionState;

                if (lastConnectionState == HitConnectionState.Connected || lastConnectionState == HitConnectionState.Disconnected || lastConnectionState == HitConnectionState.Failed)
                {
                    cancellationTokenSource.Cancel();
                }
            }

            var client = new HitSocketApi();

            client.ConnectionStateChanged += ClientConnectionStateChanged;

            client.ConnectAsync().Wait(cancellationTokenSource.Token);

            try
            {
                Task.Delay(timeout, cancellationTokenSource.Token).Wait(cancellationTokenSource.Token);
            }
            catch
            { }

            Assert.AreEqual(HitConnectionState.Connected, lastConnectionState);

            client.DisconnectAsync().Wait();

            Assert.AreEqual(HitConnectionState.Disconnected, lastConnectionState);
        }
Exemple #7
0
        public override ConnectionResult Connect(ConnectRequestParameters connectRequestParameters)
        {
            // Initialize
            var config = this.HitConfig;

            this.restApi   = new HitRestApi(config);
            this.socketApi = new HitSocketApi(config);
            this.socketApi.ConnectionStateChanged += this.SocketApi_ConnectionStateChanged;
            this.socketApi.Notification           += this.SocketApi_Notification;

            this.currenciesCache = new Dictionary <string, HitCurrency>();
            this.symbolsCache    = new Dictionary <string, HitSymbol>();

            this.ping    = new Ping();
            this.pingUri = new Uri("https://api.hitbtc.com/api/2");

            this.lastsTimeCache = new Dictionary <string, long>();

            this.aggressorFlagCalculator = new AggressorFlagCalculator();

            // Connect
            var token = connectRequestParameters.CancellationToken;

            this.socketApi.ConnectAsync().Wait(token);

            if (token.IsCancellationRequested)
            {
                return(ConnectionResult.CreateCancelled());
            }

            if (this.socketApi.ConnectionState != HitConnectionState.Connected)
            {
                return(ConnectionResult.CreateFail("Can't connect to socket API"));
            }

            var currencies = this.CheckHitResponse(this.restApi.GetCurrenciesAsync(token).Result, out HitError hitError);

            if (hitError != null)
            {
                return(ConnectionResult.CreateFail(hitError.Format()));
            }

            foreach (var currency in currencies)
            {
                this.currenciesCache.Add(currency.Id, currency);
            }

            var symbols = this.CheckHitResponse(this.restApi.GetSymbolsAsync(token).Result, out hitError);

            if (hitError != null)
            {
                return(ConnectionResult.CreateFail(hitError.Format()));
            }

            foreach (var symbol in symbols)
            {
                this.symbolsCache.Add(symbol.Id, symbol);
            }

            return(ConnectionResult.CreateSuccess());
        }