コード例 #1
0
 public GdaxWssApiClientTests()
 {
     _configuration = GdaxHelpers.GetGdaxConfiguration();
     _logger        = new LogToConsole();
     _api           = new GdaxWebSocketApi(_logger, _configuration.ApiKey,
                                           _configuration.ApiSecret, _configuration.PassPhrase, _configuration.WssEndpointUrl);
 }
コード例 #2
0
        private GdaxWebSocketApi CreateWebSocketsApiClient()
        {
            var websocketApi = new GdaxWebSocketApi(LykkeLog, _configuration.ApiKey,
                                                    _configuration.ApiSecret, _configuration.PassPhrase, _configuration.WssEndpointUrl);

            websocketApi.Ticker        += OnWebSocketTickerAsync;
            websocketApi.OrderReceived += OnWebSocketOrderReceivedAsync;
            websocketApi.OrderChanged  += OnOrderChangedAsync;
            websocketApi.OrderDone     += OnWebSocketOrderDoneAsync;

            return(websocketApi);
        }
コード例 #3
0
        public GdaxOrderBooksHarvester(GdaxExchangeConfiguration configuration, ILog log,
                                       IHandler <OrderBook> orderBookHandler)
            : base(GdaxExchange.Name, configuration, log, orderBookHandler)
        {
            _configuration = configuration;
            _symbolsLastSequenceNumbers = new ConcurrentDictionary <string, long>();
            _queuedOrderBookItems       = new Dictionary <string, Queue <GdaxQueueOrderItem> >();

            _websocketApi = CreateWebSocketsApiClient();
            _restApi      = CreateRestApiClient();
            _converters   = new GdaxConverters(_configuration.SupportedCurrencySymbols,
                                               ExchangeName, configuration);
        }
コード例 #4
0
        public GdaxExchange(GdaxExchangeConfiguration configuration, TranslatedSignalsRepository translatedSignalsRepository,
                            GdaxOrderBooksHarvester orderBookHarvester, IHandler <TickPrice> tickPriceHandler, IHandler <ExecutionReport> tradeHandler, ILog log)
            : base(Name, configuration, translatedSignalsRepository, log)
        {
            _configuration = configuration;
            _converters    = new GdaxConverters(configuration.SupportedCurrencySymbols, Name);

            _orderBooksHarvester = orderBookHarvester;
            _tickPriceHandler    = tickPriceHandler;
            _tradeHandler        = tradeHandler;


            _restApi      = CreateRestApiClient();
            _websocketApi = CreateWebSocketsApiClient();
        }
コード例 #5
0
        public async Task SubscribeAndHandleAnonymousTickerEvent()
        {
            _api = new GdaxWebSocketApi(_logger, string.Empty, string.Empty,
                                        string.Empty, _configuration.WssEndpointUrl);
            var cancellationToken = new CancellationTokenSource().Token;

            var tcsTicker = new TaskCompletionSource <GdaxWssTicker>();

            _api.Ticker += (sender, ticker) => {
                tcsTicker.SetResult(ticker);
                return(tcsTicker.Task);
            };

            // Connect and subscribe to web socket events
            await _api.ConnectAsync(cancellationToken);

            try
            {
                // Subscribe
                var subscribed = await SubscribeToOrderBookUpdatesAsync(10000, cancellationToken);

                Assert.True(subscribed);

                // Wait maximum n seconds the received and done events to be received
                await WhenAllTaskAreDone(10000, tcsTicker.Task);
            }
            finally
            {
                await _api.CloseConnectionAsync(cancellationToken);
            }

            // Check if events were received successfuly
            // Ticker event
            Assert.NotNull(tcsTicker.Task);
            Assert.True(tcsTicker.Task.IsCompletedSuccessfully);
            var tick = tcsTicker.Task.Result;

            Assert.Equal(_btcUsd, tick.ProductId);
        }