diff --git a/QuantConnect.BinanceBrokerage/BinanceBrokerage.Messaging.cs b/QuantConnect.BinanceBrokerage/BinanceBrokerage.Messaging.cs index 8650515..7fc0514 100644 --- a/QuantConnect.BinanceBrokerage/BinanceBrokerage.Messaging.cs +++ b/QuantConnect.BinanceBrokerage/BinanceBrokerage.Messaging.cs @@ -115,6 +115,7 @@ private void OnDataMessage(WebSocketMessage webSocketMessage) switch (eventType) { case "trade": + case "aggTrade": var trade = objData.ToObject(); // futures feed send upper and lower case T confusing json trade.Time = objData["T"].ToObject(); diff --git a/QuantConnect.BinanceBrokerage/BinanceBrokerage.cs b/QuantConnect.BinanceBrokerage/BinanceBrokerage.cs index 3848019..0af5b2e 100644 --- a/QuantConnect.BinanceBrokerage/BinanceBrokerage.cs +++ b/QuantConnect.BinanceBrokerage/BinanceBrokerage.cs @@ -37,6 +37,7 @@ using QuantConnect.Brokerages; using RestSharp; using Timer = System.Timers.Timer; +using QuantConnect.BinanceBrokerage.Constants; namespace QuantConnect.BinanceBrokerage { @@ -68,6 +69,19 @@ public partial class BinanceBrokerage : BaseWebsocketsBrokerage, IDataQueueHandl protected BinanceBaseRestApiClient ApiClient => _apiClientLazy?.Value; protected string MarketName { get; set; } + /// + /// Gets or sets the trade channel used for streaming trade information. + /// + /// + /// The property represents the specific trade channel utilized for streaming trade data. + /// It is initialized with the constant value , indicating the use of + /// Spot Trade Streams by default. + /// + /// + /// The default value is the channel name for Spot Trade Streams: trade. + /// + protected virtual string TradeChannelName { get; } = TradeChannels.SpotTradeChannelName; + /// /// Parameterless constructor for brokerage /// @@ -595,7 +609,7 @@ private bool Subscribe(IWebSocket webSocket, Symbol symbol) method = "SUBSCRIBE", @params = new[] { - $"{brokerageSymbol.ToLowerInvariant()}@trade", + $"{brokerageSymbol.ToLowerInvariant()}@{TradeChannelName}", $"{brokerageSymbol.ToLowerInvariant()}@bookTicker" }, id = GetNextRequestId() @@ -619,7 +633,7 @@ private bool Unsubscribe(IWebSocket webSocket, Symbol symbol) method = "UNSUBSCRIBE", @params = new[] { - $"{brokerageSymbol.ToLowerInvariant()}@trade", + $"{brokerageSymbol.ToLowerInvariant()}@{TradeChannelName}", $"{brokerageSymbol.ToLowerInvariant()}@bookTicker" }, id = GetNextRequestId() diff --git a/QuantConnect.BinanceBrokerage/BinanceCoinFuturesBrokerage.cs b/QuantConnect.BinanceBrokerage/BinanceCoinFuturesBrokerage.cs index a8f5826..1547f96 100644 --- a/QuantConnect.BinanceBrokerage/BinanceCoinFuturesBrokerage.cs +++ b/QuantConnect.BinanceBrokerage/BinanceCoinFuturesBrokerage.cs @@ -20,6 +20,7 @@ using QuantConnect.Brokerages; using QuantConnect.Interfaces; using QuantConnect.Configuration; +using QuantConnect.BinanceBrokerage.Constants; namespace QuantConnect.BinanceBrokerage { @@ -29,6 +30,19 @@ namespace QuantConnect.BinanceBrokerage [BrokerageFactory(typeof(BinanceCoinFuturesBrokerageFactory))] public class BinanceCoinFuturesBrokerage : BinanceBrokerage { + /// + /// Gets the trade channel name used for streaming trade information in the overridden context. + /// + /// + /// The property represents the specific trade channel name utilized for streaming + /// trade data in the overridden context. In this specific implementation, it returns the constant value + /// , indicating the use of Future Trade Streams. + /// + /// + /// The value is the channel name for Future Trade Streams: aggTrade. + /// + protected override string TradeChannelName => TradeChannels.FutureTradeChannelName; + public BinanceCoinFuturesBrokerage() : base(Market.Binance) { } diff --git a/QuantConnect.BinanceBrokerage/BinanceFuturesBrokerage.cs b/QuantConnect.BinanceBrokerage/BinanceFuturesBrokerage.cs index 8f6d1ac..391969c 100644 --- a/QuantConnect.BinanceBrokerage/BinanceFuturesBrokerage.cs +++ b/QuantConnect.BinanceBrokerage/BinanceFuturesBrokerage.cs @@ -20,6 +20,7 @@ using QuantConnect.Brokerages; using QuantConnect.Interfaces; using QuantConnect.Configuration; +using QuantConnect.BinanceBrokerage.Constants; namespace QuantConnect.BinanceBrokerage { @@ -29,6 +30,19 @@ namespace QuantConnect.BinanceBrokerage [BrokerageFactory(typeof(BinanceFuturesBrokerageFactory))] public class BinanceFuturesBrokerage : BinanceBrokerage { + /// + /// Gets the trade channel name used for streaming trade information in the overridden context. + /// + /// + /// The property represents the specific trade channel name utilized for streaming + /// trade data in the overridden context. In this specific implementation, it returns the constant value + /// , indicating the use of Future Trade Streams. + /// + /// + /// The value is the channel name for Future Trade Streams: aggTrade. + /// + protected override string TradeChannelName => TradeChannels.FutureTradeChannelName; + public BinanceFuturesBrokerage() : base(Market.Binance) { } diff --git a/QuantConnect.BinanceBrokerage/Constants/TradeChannels.cs b/QuantConnect.BinanceBrokerage/Constants/TradeChannels.cs new file mode 100644 index 0000000..9c9e48e --- /dev/null +++ b/QuantConnect.BinanceBrokerage/Constants/TradeChannels.cs @@ -0,0 +1,43 @@ +/* + * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. + * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +namespace QuantConnect.BinanceBrokerage.Constants +{ + /// + /// The class contains constant values representing trade channels in different markets. + /// + public sealed class TradeChannels + { + /// + /// The channel name for Spot Trade Streams. Spot Trade Streams push raw trade information, where each trade + /// involves a unique buyer and seller. + /// + /// + /// Stream Name Format: {symbol}@trade + /// Update Speed: Real-time + /// + public const string SpotTradeChannelName = "trade"; + + /// + /// The channel name for Aggregate Trade Streams. Aggregate Trade Streams push market trade information that is + /// aggregated for fills with the same price, updating every 100 milliseconds. + /// + /// + /// Stream Name Format: {symbol}@aggTrade + /// Update Speed: 100ms + /// + public const string FutureTradeChannelName = "aggTrade"; + } +}