From 8ee2befcb7a918bc5a2c2b4a91a004cac30db2d3 Mon Sep 17 00:00:00 2001 From: Mariusz Kotas Date: Mon, 4 Feb 2019 20:21:58 +0100 Subject: [PATCH] Remove dependency to Serilog and use logging abstraction LibLog. Release version 2.0 --- .travis.yml | 2 +- README.md | 4 +- .../Bitmex.Client.Websocket.csproj | 13 +++-- .../Client/BitmexClientStreams.cs | 53 +++++++++++++++++-- .../Client/BitmexWebsocketClient.cs | 18 +++++-- .../Files/BitmexFileCommunicator.cs | 1 + .../Json/BitmexStringEnumConverter.cs | 6 ++- .../Requests/InstrumentSubscribeRequest.cs | 2 +- .../App.config | 4 ++ ...lient.Websocket.Sample.NetFramework.csproj | 23 +++++--- .../packages.config | 11 ++-- .../App.config | 14 ++++- ...ex.Client.Websocket.Sample.WinForms.csproj | 23 +++++--- .../packages.config | 11 ++-- .../Bitmex.Client.Websocket.Sample/Program.cs | 2 +- 15 files changed, 145 insertions(+), 42 deletions(-) diff --git a/.travis.yml b/.travis.yml index 409ad8d..59db97c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,6 @@ deploy: provider: script skip_cleanup: true script: - - cd src/Bitmex.Client.Websocket && dotnet pack /p:PackageVersion=1.0.$TRAVIS_BUILD_NUMBER -c Release && cd bin/Release && dotnet nuget push **/*.1.0.$TRAVIS_BUILD_NUMBER.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json + - cd src/Bitmex.Client.Websocket && dotnet pack /p:PackageVersion=2.0.$TRAVIS_BUILD_NUMBER -c Release && cd bin/Release && dotnet nuget push **/*.2.0.$TRAVIS_BUILD_NUMBER.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json on: branch: master \ No newline at end of file diff --git a/README.md b/README.md index 2399e5d..f5d9a75 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ This is a C# implementation of the Bitmex websocket API found here: https://www.bitmex.com/app/wsAPI +[Releases and breaking changes](https://github.com/Marfusios/bitmex-client-websocket/releases) + ### License: Apache License 2.0 @@ -14,7 +16,7 @@ https://www.bitmex.com/app/wsAPI * public and authenticated API * targeting .NET Standard 2.0 (.NET Core, Linux/MacOS compatible) * reactive extensions ([Rx.NET](https://github.com/Reactive-Extensions/Rx.NET)) -* integrated logging ([Serilog](https://serilog.net/)) +* integrated logging abstraction ([LibLog](https://github.com/damianh/LibLog)) ### Usage diff --git a/src/Bitmex.Client.Websocket/Bitmex.Client.Websocket.csproj b/src/Bitmex.Client.Websocket/Bitmex.Client.Websocket.csproj index 2ca993b..e0df6ee 100644 --- a/src/Bitmex.Client.Websocket/Bitmex.Client.Websocket.csproj +++ b/src/Bitmex.Client.Websocket/Bitmex.Client.Websocket.csproj @@ -3,7 +3,7 @@ netstandard2.0 Bitmex.Client.Websocket - 1.0.0 + 2.0.0 Mariusz Kotas Client for Bitmex websocket API false @@ -17,15 +17,18 @@ Git true true - 1.0.0.0 - 1.0.0.0 + 2.0.0.0 + 2.0.0.0 + + all + runtime; build; native; contentfiles; analyzers + - - + diff --git a/src/Bitmex.Client.Websocket/Client/BitmexClientStreams.cs b/src/Bitmex.Client.Websocket/Client/BitmexClientStreams.cs index a34119b..14b8f31 100644 --- a/src/Bitmex.Client.Websocket/Client/BitmexClientStreams.cs +++ b/src/Bitmex.Client.Websocket/Client/BitmexClientStreams.cs @@ -15,6 +15,10 @@ namespace Bitmex.Client.Websocket.Client { + /// + /// All provided streams. + /// You need to send subscription request in advance (via method `Send()` on BitmexWebsocketClient) + /// public class BitmexClientStreams { internal readonly Subject ErrorSubject = new Subject(); @@ -36,17 +40,51 @@ public class BitmexClientStreams internal readonly Subject MarginSubject = new Subject(); + // PUBLIC + /// + /// Server errors stream + /// public IObservable ErrorStream => ErrorSubject.AsObservable(); + + /// + /// Info stream, sends initial information after reconnection + /// public IObservable InfoStream => InfoSubject.AsObservable(); + + /// + /// Response stream to every ping request + /// public IObservable PongStream => PongSubject.AsObservable(); + + /// + /// Subscription info stream, emits status after sending subscription request + /// public IObservable SubscribeStream => SubscribeSubject.AsObservable(); - public IObservable AuthenticationStream => AuthenticationSubject.AsObservable(); + /// + /// Trades stream - emits every executed trade on Bitmex + /// public IObservable TradesStream => TradesSubject.AsObservable(); + + /// + /// Chunk of trades - emits grouped trades together + /// public IObservable TradeBinStream => TradeBinSubject.AsObservable(); + + /// + /// Order book stream - emits every update in the order book + /// public IObservable BookStream => BookSubject.AsObservable(); + + /// + /// Quotes stream - emits on every change of top level of order book + /// public IObservable QuoteStream => QuoteSubject.AsObservable(); + + /// + /// Liquidation stream - emits message whenever liquidation happens on Bitmex + /// public IObservable LiquidationStream => LiquidationSubject.AsObservable(); /// @@ -54,18 +92,27 @@ public class BitmexClientStreams /// public IObservable InstrumentStream => InstrumentSubject.AsObservable(); + + + // PRIVATE + + /// + /// Authentication info stream, emits status after sending authentication request + /// + public IObservable AuthenticationStream => AuthenticationSubject.AsObservable(); + /// /// Stream for every wallet balance update /// public IObservable WalletStream => WalletSubject.AsObservable(); /// - /// Stream of all active orders + /// Stream of all your active orders /// public IObservable OrderStream => OrderSubject.AsObservable(); /// - /// Stream of all active positions + /// Stream of all your active positions /// public IObservable PositionStream => PositionSubject.AsObservable(); diff --git a/src/Bitmex.Client.Websocket/Client/BitmexWebsocketClient.cs b/src/Bitmex.Client.Websocket/Client/BitmexWebsocketClient.cs index ff84192..4c95e23 100644 --- a/src/Bitmex.Client.Websocket/Client/BitmexWebsocketClient.cs +++ b/src/Bitmex.Client.Websocket/Client/BitmexWebsocketClient.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Bitmex.Client.Websocket.Communicator; using Bitmex.Client.Websocket.Json; +using Bitmex.Client.Websocket.Logging; using Bitmex.Client.Websocket.Requests; using Bitmex.Client.Websocket.Responses; using Bitmex.Client.Websocket.Responses.Books; @@ -14,23 +15,30 @@ using Bitmex.Client.Websocket.Responses.Wallets; using Bitmex.Client.Websocket.Validations; using Newtonsoft.Json.Linq; -using Serilog; using Bitmex.Client.Websocket.Responses.Instruments; using Bitmex.Client.Websocket.Responses.Margins; namespace Bitmex.Client.Websocket.Client { + /// + /// Bitmex websocket client. + /// Use method `Send()` to subscribe to channels. + /// And `Streams` to subscribe. + /// public class BitmexWebsocketClient : IDisposable { + private static readonly ILog Log = LogProvider.GetCurrentClassLogger(); + private readonly IBitmexCommunicator _communicator; - private readonly IDisposable _messageReceivedSubsciption; + private readonly IDisposable _messageReceivedSubscription; + /// public BitmexWebsocketClient(IBitmexCommunicator communicator) { BmxValidations.ValidateInput(communicator, nameof(communicator)); _communicator = communicator; - _messageReceivedSubsciption = _communicator.MessageReceived.Subscribe(HandleMessage); + _messageReceivedSubscription = _communicator.MessageReceived.Subscribe(HandleMessage); } /// @@ -43,7 +51,7 @@ public BitmexWebsocketClient(IBitmexCommunicator communicator) /// public void Dispose() { - _messageReceivedSubsciption?.Dispose(); + _messageReceivedSubscription?.Dispose(); } /// @@ -102,7 +110,7 @@ private void HandleMessage(string message) if (handled) return; - Log.Warning(L($"Unhandled response: '{messageSafe}'")); + Log.Warn(L($"Unhandled response: '{messageSafe}'")); } catch (Exception e) { diff --git a/src/Bitmex.Client.Websocket/Files/BitmexFileCommunicator.cs b/src/Bitmex.Client.Websocket/Files/BitmexFileCommunicator.cs index 4327db1..6d65b08 100644 --- a/src/Bitmex.Client.Websocket/Files/BitmexFileCommunicator.cs +++ b/src/Bitmex.Client.Websocket/Files/BitmexFileCommunicator.cs @@ -19,6 +19,7 @@ public class BitmexFileCommunicator : IBitmexCommunicator public int ReconnectTimeoutMs { get; set; } = 60 * 1000; public int ErrorReconnectTimeoutMs { get; set; } = 60 * 1000; + public string Name { get; set; } public bool IsStarted { get; private set; } public bool IsRunning { get; private set; } diff --git a/src/Bitmex.Client.Websocket/Json/BitmexStringEnumConverter.cs b/src/Bitmex.Client.Websocket/Json/BitmexStringEnumConverter.cs index ef721d8..c207003 100644 --- a/src/Bitmex.Client.Websocket/Json/BitmexStringEnumConverter.cs +++ b/src/Bitmex.Client.Websocket/Json/BitmexStringEnumConverter.cs @@ -1,12 +1,14 @@ using System; +using Bitmex.Client.Websocket.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Converters; -using Serilog; namespace Bitmex.Client.Websocket.Json { public class BitmexStringEnumConverter : StringEnumConverter { + private static readonly ILog Log = LogProvider.GetCurrentClassLogger(); + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { try @@ -21,7 +23,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } catch { - Log.Warning($"Can't parse enum, value: {reader.Value}, target type: {objectType}, using default '{existingValue}'"); + Log.Warn($"Can't parse enum, value: {reader.Value}, target type: {objectType}, using default '{existingValue}'"); return existingValue; } } diff --git a/src/Bitmex.Client.Websocket/Requests/InstrumentSubscribeRequest.cs b/src/Bitmex.Client.Websocket/Requests/InstrumentSubscribeRequest.cs index b80278f..400cfc0 100644 --- a/src/Bitmex.Client.Websocket/Requests/InstrumentSubscribeRequest.cs +++ b/src/Bitmex.Client.Websocket/Requests/InstrumentSubscribeRequest.cs @@ -13,7 +13,7 @@ public InstrumentSubscribeRequest() } /// - /// Subscribe toinstrument updates including turnover and bid/ask from selected pair ('XBTUSD', etc) + /// Subscribe to instrument updates including turnover and bid/ask from selected pair ('XBTUSD', etc) /// public InstrumentSubscribeRequest(string pair) { diff --git a/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/App.config b/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/App.config index ee8b7ae..9553d0d 100644 --- a/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/App.config +++ b/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/App.config @@ -9,6 +9,10 @@ + + + + \ No newline at end of file diff --git a/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/Bitmex.Client.Websocket.Sample.NetFramework.csproj b/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/Bitmex.Client.Websocket.Sample.NetFramework.csproj index 0541636..c3f00a9 100644 --- a/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/Bitmex.Client.Websocket.Sample.NetFramework.csproj +++ b/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/Bitmex.Client.Websocket.Sample.NetFramework.csproj @@ -32,11 +32,11 @@ 4 - - ..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll - ..\..\packages\Serilog.2.7.1\lib\net46\Serilog.dll + ..\..\packages\Serilog.2.8.0\lib\net46\Serilog.dll ..\..\packages\Serilog.Sinks.ColoredConsole.3.0.1\lib\net45\Serilog.Sinks.ColoredConsole.dll @@ -49,8 +49,17 @@ - - ..\..\packages\System.Reactive.4.0.0\lib\net46\System.Reactive.dll + + ..\..\packages\System.Reactive.4.1.2\lib\net46\System.Reactive.dll + + + ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + + + ..\..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + + + ..\..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll @@ -60,8 +69,8 @@ - - ..\..\packages\Websocket.Client.1.0.5\lib\netstandard2.0\Websocket.Client.dll + + ..\..\packages\Websocket.Client.2.0.10\lib\netstandard2.0\Websocket.Client.dll diff --git a/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/packages.config b/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/packages.config index f2937a8..0e96eb1 100644 --- a/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/packages.config +++ b/test_integration/Bitmex.Client.Websocket.Sample.NetFramework/packages.config @@ -1,10 +1,13 @@  - - + + - - + + + + + \ No newline at end of file diff --git a/test_integration/Bitmex.Client.Websocket.Sample.WinForms/App.config b/test_integration/Bitmex.Client.Websocket.Sample.WinForms/App.config index 787dcbe..e862795 100644 --- a/test_integration/Bitmex.Client.Websocket.Sample.WinForms/App.config +++ b/test_integration/Bitmex.Client.Websocket.Sample.WinForms/App.config @@ -1,6 +1,18 @@ - + + + + + + + + + + + + + \ No newline at end of file diff --git a/test_integration/Bitmex.Client.Websocket.Sample.WinForms/Bitmex.Client.Websocket.Sample.WinForms.csproj b/test_integration/Bitmex.Client.Websocket.Sample.WinForms/Bitmex.Client.Websocket.Sample.WinForms.csproj index 66b9294..65248a3 100644 --- a/test_integration/Bitmex.Client.Websocket.Sample.WinForms/Bitmex.Client.Websocket.Sample.WinForms.csproj +++ b/test_integration/Bitmex.Client.Websocket.Sample.WinForms/Bitmex.Client.Websocket.Sample.WinForms.csproj @@ -33,11 +33,11 @@ 4 - - ..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll - ..\..\packages\Serilog.2.7.1\lib\net46\Serilog.dll + ..\..\packages\Serilog.2.8.0\lib\net46\Serilog.dll ..\..\packages\Serilog.Sinks.Console.3.1.1\lib\net45\Serilog.Sinks.Console.dll @@ -50,8 +50,17 @@ - - ..\..\packages\System.Reactive.4.0.0\lib\net46\System.Reactive.dll + + ..\..\packages\System.Reactive.4.1.2\lib\net46\System.Reactive.dll + + + ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + + + ..\..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + + + ..\..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -63,8 +72,8 @@ - - ..\..\packages\Websocket.Client.1.0.6\lib\netstandard2.0\Websocket.Client.dll + + ..\..\packages\Websocket.Client.2.0.10\lib\netstandard2.0\Websocket.Client.dll diff --git a/test_integration/Bitmex.Client.Websocket.Sample.WinForms/packages.config b/test_integration/Bitmex.Client.Websocket.Sample.WinForms/packages.config index 1395c9c..ec47074 100644 --- a/test_integration/Bitmex.Client.Websocket.Sample.WinForms/packages.config +++ b/test_integration/Bitmex.Client.Websocket.Sample.WinForms/packages.config @@ -1,11 +1,14 @@  - - + + - - + + + + + \ No newline at end of file diff --git a/test_integration/Bitmex.Client.Websocket.Sample/Program.cs b/test_integration/Bitmex.Client.Websocket.Sample/Program.cs index 259a10f..4537bfa 100644 --- a/test_integration/Bitmex.Client.Websocket.Sample/Program.cs +++ b/test_integration/Bitmex.Client.Websocket.Sample/Program.cs @@ -42,8 +42,8 @@ static void Main(string[] args) var url = BitmexValues.ApiWebsocketUrl; using (var communicator = new BitmexWebsocketCommunicator(url)) { + communicator.Name = "Bitmex-1"; communicator.ReconnectTimeoutMs = (int)TimeSpan.FromMinutes(10).TotalMilliseconds; - communicator.ReconnectionHappened.Subscribe(type => Log.Information($"Reconnection happened, type: {type}"));