Пример #1
0
        /// <summary>
        /// Add the IBitfinexClient and IBitfinexSocketClient to the sevice collection so they can be injected
        /// </summary>
        /// <param name="services">The service collection</param>
        /// <param name="defaultOptionsCallback">Set default options for the client</param>
        /// <param name="socketClientLifeTime">The lifetime of the IBitfinexSocketClient for the service collection. Defaults to Scoped.</param>
        /// <returns></returns>
        public static IServiceCollection AddBitfinex(
            this IServiceCollection services,
            Action <BitfinexClientOptions, BitfinexSocketClientOptions>?defaultOptionsCallback = null,
            ServiceLifetime?socketClientLifeTime = null)
        {
            if (defaultOptionsCallback != null)
            {
                var options       = new BitfinexClientOptions();
                var socketOptions = new BitfinexSocketClientOptions();
                defaultOptionsCallback?.Invoke(options, socketOptions);

                BitfinexClient.SetDefaultOptions(options);
                BitfinexSocketClient.SetDefaultOptions(socketOptions);
            }

            services.AddTransient <IBitfinexClient, BitfinexClient>();
            if (socketClientLifeTime == null)
            {
                services.AddScoped <IBitfinexSocketClient, BitfinexSocketClient>();
            }
            else
            {
                services.Add(new ServiceDescriptor(typeof(IBitfinexSocketClient), typeof(BitfinexSocketClient), socketClientLifeTime.Value));
            }
            return(services);
        }
Пример #2
0
        /// <summary>
        /// Create a new instance of BitfinexSocketClient using provided options
        /// </summary>
        /// <param name="options">The options to use for this client</param>
        public BitfinexSocketClient(BitfinexSocketClientOptions options) : base(options, options.ApiCredentials == null ? null : new BitfinexAuthenticationProvider(options.ApiCredentials))
        {
            Configure(options);

            AddGenericHandler("HB", (wrapper, msg) => { });
            AddGenericHandler("Info", InfoHandler);
        }
Пример #3
0
        /// <summary>
        /// Create a new instance of BitfinexSocketClient using provided options
        /// </summary>
        /// <param name="options">The options to use for this client</param>
        public BitfinexSocketClient(BitfinexSocketClientOptions options) : base(options, options.ApiCredentials == null ? null : new BitfinexAuthenticationProvider(options.ApiCredentials))
        {
            ContinueOnQueryResponse = true;
            _bookSerializer.Converters.Add(new OrderBookEntryConverter());

            AddGenericHandler("HB", (wrapper, msg) => { });
            AddGenericHandler("Info", InfoHandler);
            AddGenericHandler("Conf", ConfHandler);
        }
Пример #4
0
        /// <summary>
        /// Create a new instance of BitfinexSocketClient using provided options
        /// </summary>
        /// <param name="options">The options to use for this client</param>
        public BitfinexSocketClient(BitfinexSocketClientOptions options) : base("Bitfinex", options, options.ApiCredentials == null ? null : new BitfinexAuthenticationProvider(options.ApiCredentials))
        {
            if (options == null)
            {
                throw new ArgumentException("Cant pass null options, use empty constructor for default");
            }

            ContinueOnQueryResponse = true;
            _bookSerializer.Converters.Add(new OrderBookEntryConverter());
            _affCode = options.AffiliateCode;

            AddGenericHandler("HB", (wrapper, msg) => { });
            AddGenericHandler("Info", InfoHandler);
            AddGenericHandler("Conf", ConfHandler);
        }
 /// <summary>
 /// Create a new instance of BinanceClient using provided options
 /// </summary>
 /// <param name="options">The options to use for this client</param>
 public BitfinexSocketClient(BitfinexSocketClientOptions options) : base(options, options.ApiCredentials == null ? null : new BitfinexAuthenticationProvider(options.ApiCredentials))
 {
     Init();
     Configure(options);
 }
        private void Configure(BitfinexSocketClientOptions options)
        {
            base.Configure(options);

            baseAddress = options.BaseAddress;
        }
 /// <summary>
 /// Sets the default options to use for new clients
 /// </summary>
 /// <param name="options">The options to use for new clients</param>
 public static void SetDefaultOptions(BitfinexSocketClientOptions options)
 {
     defaultOptions = options;
 }