コード例 #1
0
        public BittrexWebsocket(
            string connectionUrl,
            BittrexCallback updateExchangeState,
            BittrexCallback updateOrderState,
            BittrexCallback updateBalanceState
            )
        {
            // Set delegates
            _updateExchangeState = updateExchangeState;
            _updateOrderState    = updateOrderState;
            _updateBalanceState  = updateBalanceState;

            // Create connection to c2 SignalR hub
            _hubConnection = new HubConnection(connectionUrl);
            _hubProxy      = _hubConnection.CreateHubProxy("c2");

            // Register callback for uE (exchange state delta) events
            _hubProxy.On(
                "uE",
                exchangeStateDelta => _updateExchangeState?.Invoke(exchangeStateDelta)
                );

            // Register callback for uO (order status change) events
            _hubProxy.On(
                "uO",
                orderStateDelta => _updateOrderState?.Invoke(orderStateDelta)
                );

            // Register callback for uB (balance status change) events
            _hubProxy.On(
                "uB",
                balanceStateDelta => _updateBalanceState?.Invoke(balanceStateDelta)
                );

            _hubConnection.Start().Wait();
        }
コード例 #2
0
ファイル: BittrexClient.cs プロジェクト: logosha/AWS
        private async Task <bool?> ConnectToSignalR()
        {
            _hubConnection = new HubConnection(baseUrl);
            _hubProxy      = _hubConnection.CreateHubProxy("c2");

            _hubConnection.Closed         += _hubConnection_Closed;
            _hubConnection.ConnectionSlow += _hubConnection_ConnectionSlow;
            _hubConnection.Error          += _hubConnection_Error;
            _hubConnection.Received       += _hubConnection_Received;
            _hubConnection.Reconnected    += _hubConnection_Reconnected;
            _hubConnection.Reconnecting   += _hubConnection_Reconnecting;
            _hubConnection.StateChanged   += _hubConnection_StateChanged;

            try
            {
                await _hubConnection.Start().ConfigureAwait(false);

                #region obsolete
                if (_hubConnection.State == ConnectionState.Connected)
                {
                    _hubProxy.On(
                        "uE",
                        exchangeStateDelta => _updateExchangeState?.Invoke(exchangeStateDelta)
                        );
                    _client.OnEvent(Name, BrokerEvent.SessionLogon, string.Empty);

                    using (await _lock.LockAsync())
                    {
                        if (_subscribeList.Count > 0)
                        {
                            foreach (var i in _subscribeList)
                            {
                                if (i.Value.market != null)
                                {
                                    i.Value.market.ask_list.Clear();
                                    i.Value.market.bid_list.Clear();
                                    i.Value.market.nonce = 0;
                                }
                                try
                                {
                                    var res = await QueryExchangeState(i.Key);

                                    ParseMessage(Decode(res));
                                    await SubscribeToExchangeDeltas(i.Key);
                                }
                                catch (Exception ex)
                                {
                                    _logger.Log(LogPriority.Error, $"Connection error {ex.Message}", Name);
                                }
                            }
                        }
                    }
                    _client.OnEvent(Name, BrokerEvent.SessionLogon, string.Empty);
                    _client.OnEvent(Name, BrokerEvent.ConnectorStarted, string.Empty);
                }
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Log(LogPriority.Error, $"Exception - {ex.Message}", Name);
                return(false);
            }
        }