Пример #1
0
        private void Subscribe(BitmexWebsocketClient client, MTAccount acc)
        {
            client
            .Streams
            .MarginStream
            .Select(trade => Observable.FromAsync(async() => {
                HandleMarginResponse(trade);
            }))
            .Concat()
            .Subscribe();

            client
            .Streams
            .OrderStream
            .Select(ord => Observable.FromAsync(async() => {
                HandleOrderResponse(ord);
            }))
            .Concat()
            .Subscribe();

            //client
            //    .Streams
            //    .PositionStream
            //    .Select(pos => Observable.FromAsync(async () => {
            //        HandlePositionResponse(pos);
            //    }))
            //    .Concat()
            //    .Subscribe();

            //client.Streams.ErrorStream.ObserveOn(TaskPoolScheduler.Default).Subscribe(HandleErrorResponse);

            if (acc == MTAccount.A)
            {
                client.Streams.TradesStream.ObserveOn(TaskPoolScheduler.Default).Subscribe(HandleTrades);
                client.Streams.BookStream.ObserveOn(TaskPoolScheduler.Default).Subscribe(HandleOrderBook);
                client.Streams.PongStream.ObserveOn(TaskPoolScheduler.Default).Subscribe(HandlePongA);
                client.Streams.PositionStream.ObserveOn(TaskPoolScheduler.Default).Subscribe(HandlePositionResponse);
            }
            else
            {
                client.Streams.PongStream.ObserveOn(TaskPoolScheduler.Default).Subscribe(HandlePongB);
            }
        }
Пример #2
0
        private void ComputePing(DateTime current, DateTime before, MTAccount acc)
        {
            try
            {
                ErrorStatsMutex.WaitOne();

                var diff = current.Subtract(before);

                if (acc == MTAccount.A)
                {
                    _view.PingL = $"{diff.TotalMilliseconds:###} ms";
                    _view.StatusA("Connected", StatusType.Info);
                    _view.DisconnectionsA = $"{_errorStatsHandler.GetDisconnections(ZoneRecoveryAccount.A)}";
                    _view.ReconnectionsA  = $"{_errorStatsHandler.GetReconnections(ZoneRecoveryAccount.A)}";
                    _view.ErrorsCounterA  = $"{_errorStatsHandler.GetErrorCnt(ZoneRecoveryAccount.A)}";
                }
                else
                {
                    _view.PingS = $"{diff.TotalMilliseconds:###} ms";
                    _view.StatusB("Connected", StatusType.Info);
                    _view.DisconnectionsB = $"{_errorStatsHandler.GetDisconnections(ZoneRecoveryAccount.B)}";
                    _view.ReconnectionsB  = $"{_errorStatsHandler.GetReconnections(ZoneRecoveryAccount.B)}";
                    _view.ErrorsCounterB  = $"{_errorStatsHandler.GetErrorCnt(ZoneRecoveryAccount.B)}";
                }
                _view.TimeConnected      = $"{_generalStatsHandler.GetTimeActive()}";
                _view.ErrorsCounterTotal = $"{_errorStatsHandler.GetErrorCnt(ZoneRecoveryAccount.A) + _errorStatsHandler.GetErrorCnt(ZoneRecoveryAccount.B)}";
            }
            catch (Exception exc)
            {
                Log.Error($"ComputePing: {exc.Message}");
            }
            finally
            {
                ErrorStatsMutex.ReleaseMutex();
            }
        }
Пример #3
0
        /// <summary>
        /// Send the requests for the subscriptions needed.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="pair"></param>
        /// <param name="acc"></param>
        /// <returns></returns>
        private async Task SendSubscriptions(BitmexWebsocketClient client, string pair, MTAccount acc)
        {
            var    appSettings = ConfigurationManager.AppSettings;
            string api, sec;

            if (acc == MTAccount.A)
            {
                if (_view.isTest)
                {
                    api = appSettings["API_KEY_BITMEX_A_TEST"] ?? string.Empty;
                    sec = appSettings["API_SECRET_BITMEX_A_TEST"] ?? string.Empty;
                }
                else
                {
                    api = appSettings["API_KEY_BITMEX_A_LIVE"] ?? string.Empty;
                    sec = appSettings["API_SECRET_BITMEX_A_LIVE"] ?? string.Empty;
                }

                // Trade stats
                //await client.Send(new TradesSubscribeRequest(pair));

                // Bid and Ask
                await client.Send(new BookSubscribeRequest(pair));
            }
            else
            {
                if (_view.isTest)
                {
                    api = appSettings["API_KEY_BITMEX_B_TEST"] ?? string.Empty;
                    sec = appSettings["API_SECRET_BITMEX_B_TEST"] ?? string.Empty;
                }
                else
                {
                    api = appSettings["API_KEY_BITMEX_B_LIVE"] ?? string.Empty;
                    sec = appSettings["API_SECRET_BITMEX_B_LIVE"] ?? string.Empty;
                }
            }

            if (!string.IsNullOrEmpty(api) && !string.IsNullOrEmpty(sec))
            {
                await client.Send(new AuthenticationRequest(api, sec));
            }

            await client.Send(new OrderSubscribeRequest());

            await client.Send(new PositionSubscribeRequest());

            await client.Send(new MarginSubscribeRequest());

            //await client.Send(new ExecutionSubscribeRequest());
        }