Пример #1
0
        /// <summary>
        /// Cryptocurrency order book.
        /// Process order book data from one source per one target pair.
        /// </summary>
        /// <param name="targetPair">Select target pair</param>
        /// <param name="source">Provide order book data source</param>
        /// <param name="targetType">Select target precision (default: All - accepts every type of data)</param>
        public CryptoOrderBook(string targetPair, IOrderBookSource source, CryptoOrderBookType targetType = CryptoOrderBookType.All)
        {
            CryptoValidations.ValidateInput(targetPair, nameof(targetPair));
            CryptoValidations.ValidateInput(source, nameof(source));

            TargetPairOriginal = targetPair;
            TargetPair         = CryptoPairsHelper.Clean(targetPair);
            _source            = source;
            TargetType         = targetType;

            if (targetType == CryptoOrderBookType.L1 || targetType == CryptoOrderBookType.L2)
            {
                // save memory, only one order at price level
                _priceLevelInitialCapacity = 1;
            }
            else if (targetType == CryptoOrderBookType.L3)
            {
                // better performance, could be multiple orders at price level
                _priceLevelInitialCapacity = 5;
            }

            Subscribe();
            RestartAutoSnapshotReloading();
            RestartValidityChecking();
        }
Пример #2
0
        /// <summary>
        /// Change client and resubscribe to the new streams
        /// </summary>
        public void ChangeClient(BitmexWebsocketClient client)
        {
            CryptoValidations.ValidateInput(client, nameof(client));

            _client = client;
            _subscription?.Dispose();
            Subscribe();
        }
Пример #3
0
        /// <summary>
        /// Change client and resubscribe to the new streams
        /// </summary>
        public void ChangeClient(IHuobiMarketByPriceWebsocketClient client)
        {
            CryptoValidations.ValidateInput(client, nameof(client));

            _client = client;
            _subscriptionSnapshot?.Dispose();
            _subscription?.Dispose();
            Subscribe();
        }
Пример #4
0
        /// <summary>
        /// Change client and resubscribe to the new streams
        /// </summary>
        public void ChangeClient(BitfinexWebsocketClient client)
        {
            CryptoValidations.ValidateInput(client, nameof(client));

            _client = client;
            _subscriptionCanceled?.Dispose();
            _subscriptionCreated?.Dispose();
            _subscriptionUpdated?.Dispose();
            _subscriptionSnapshot?.Dispose();
            Subscribe();
        }
Пример #5
0
        /// <summary>
        /// Orders manager
        /// </summary>
        /// <param name="source">Orders source</param>
        /// <param name="orderPrefix">Select prefix if you want to distinguish orders</param>
        /// <param name="targetPair">Select target pair, if you want to filter monitored orders</param>
        public CryptoOrders(IOrderSource source, long?orderPrefix = null, string targetPair = null)
        {
            CryptoValidations.ValidateInput(source, nameof(source));

            _source            = source;
            TargetPair         = CryptoPairsHelper.Clean(targetPair);
            TargetPairOriginal = targetPair;
            _source.SetExistingOrders(_idToOrder);
            _orderPrefix = orderPrefix;

            Subscribe();
        }
        /// <summary>
        /// Cryptocurrency order book.
        /// Process order book data from one source per one target pair.
        /// </summary>
        /// <param name="targetPair">Select target pair</param>
        /// <param name="source">Provide level 2 source data</param>
        public CryptoOrderBookL2(string targetPair, IOrderBookSource source)
        {
            CryptoValidations.ValidateInput(targetPair, nameof(targetPair));
            CryptoValidations.ValidateInput(source, nameof(source));

            TargetPairOriginal = targetPair;
            TargetPair         = CryptoPairsHelper.Clean(targetPair);
            _source            = source;

            Subscribe();
            RestartAutoSnapshotReloading();
            RestartValidityChecking();
        }
Пример #7
0
        /// <summary>
        /// Request a new order book snapshot, will be fakely streamed via communicator (WebsocketClient)
        /// Method doesn't throw exception, just logs it
        /// </summary>
        /// <param name="communicator">Target communicator</param>
        /// <param name="pair">Target pair</param>
        /// <param name="count">Max level count</param>
        public async Task LoadSnapshot(BinanceWebsocketCommunicator communicator, string pair, int count = 1000)
        {
            CryptoValidations.ValidateInput(communicator, nameof(communicator));

            var snapshot = await LoadSnapshotRaw(pair, count);

            if (snapshot == null)
            {
                return;
            }

            OrderBookPartialResponse.StreamFakeSnapshot(snapshot, communicator);
        }