Skip to content

Commit

Permalink
Remove dependency to Serilog and use logging abstraction LibLog.
Browse files Browse the repository at this point in the history
Release version 2.0
  • Loading branch information
Marfusios committed Feb 4, 2019
1 parent 2a2515b commit 8ee2bef
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
13 changes: 8 additions & 5 deletions src/Bitmex.Client.Websocket/Bitmex.Client.Websocket.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Bitmex.Client.Websocket</PackageId>
<Version>1.0.0</Version>
<Version>2.0.0</Version>
<Authors>Mariusz Kotas</Authors>
<Description>Client for Bitmex websocket API</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
Expand All @@ -17,15 +17,18 @@
<RepositoryType>Git</RepositoryType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LibLog" Version="5.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Serilog" Version="2.7.1" />
<PackageReference Include="System.Reactive" Version="4.0.0" />
<PackageReference Include="Websocket.Client" Version="1.0.6" />
<PackageReference Include="Websocket.Client" Version="2.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
53 changes: 50 additions & 3 deletions src/Bitmex.Client.Websocket/Client/BitmexClientStreams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

namespace Bitmex.Client.Websocket.Client
{
/// <summary>
/// All provided streams.
/// You need to send subscription request in advance (via method `Send()` on BitmexWebsocketClient)
/// </summary>
public class BitmexClientStreams
{
internal readonly Subject<ErrorResponse> ErrorSubject = new Subject<ErrorResponse>();
Expand All @@ -36,36 +40,79 @@ public class BitmexClientStreams
internal readonly Subject<MarginResponse> MarginSubject = new Subject<MarginResponse>();


// PUBLIC

/// <summary>
/// Server errors stream
/// </summary>
public IObservable<ErrorResponse> ErrorStream => ErrorSubject.AsObservable();

/// <summary>
/// Info stream, sends initial information after reconnection
/// </summary>
public IObservable<InfoResponse> InfoStream => InfoSubject.AsObservable();

/// <summary>
/// Response stream to every ping request
/// </summary>
public IObservable<PongResponse> PongStream => PongSubject.AsObservable();

/// <summary>
/// Subscription info stream, emits status after sending subscription request
/// </summary>
public IObservable<SubscribeResponse> SubscribeStream => SubscribeSubject.AsObservable();
public IObservable<AuthenticationResponse> AuthenticationStream => AuthenticationSubject.AsObservable();

/// <summary>
/// Trades stream - emits every executed trade on Bitmex
/// </summary>
public IObservable<TradeResponse> TradesStream => TradesSubject.AsObservable();

/// <summary>
/// Chunk of trades - emits grouped trades together
/// </summary>
public IObservable<TradeBinResponse> TradeBinStream => TradeBinSubject.AsObservable();

/// <summary>
/// Order book stream - emits every update in the order book
/// </summary>
public IObservable<BookResponse> BookStream => BookSubject.AsObservable();

/// <summary>
/// Quotes stream - emits on every change of top level of order book
/// </summary>
public IObservable<QuoteResponse> QuoteStream => QuoteSubject.AsObservable();

/// <summary>
/// Liquidation stream - emits message whenever liquidation happens on Bitmex
/// </summary>
public IObservable<LiquidationResponse> LiquidationStream => LiquidationSubject.AsObservable();

/// <summary>
/// Stream of all Trade-able Contracts, Indices, and History
/// </summary>
public IObservable<InstrumentResponse> InstrumentStream => InstrumentSubject.AsObservable();



// PRIVATE

/// <summary>
/// Authentication info stream, emits status after sending authentication request
/// </summary>
public IObservable<AuthenticationResponse> AuthenticationStream => AuthenticationSubject.AsObservable();

/// <summary>
/// Stream for every wallet balance update
/// </summary>
public IObservable<WalletResponse> WalletStream => WalletSubject.AsObservable();

/// <summary>
/// Stream of all active orders
/// Stream of all your active orders
/// </summary>
public IObservable<OrderResponse> OrderStream => OrderSubject.AsObservable();

/// <summary>
/// Stream of all active positions
/// Stream of all your active positions
/// </summary>
public IObservable<PositionResponse> PositionStream => PositionSubject.AsObservable();

Expand Down
18 changes: 13 additions & 5 deletions src/Bitmex.Client.Websocket/Client/BitmexWebsocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
/// <summary>
/// Bitmex websocket client.
/// Use method `Send()` to subscribe to channels.
/// And `Streams` to subscribe.
/// </summary>
public class BitmexWebsocketClient : IDisposable
{
private static readonly ILog Log = LogProvider.GetCurrentClassLogger();

private readonly IBitmexCommunicator _communicator;
private readonly IDisposable _messageReceivedSubsciption;
private readonly IDisposable _messageReceivedSubscription;

/// <inheritdoc />
public BitmexWebsocketClient(IBitmexCommunicator communicator)
{
BmxValidations.ValidateInput(communicator, nameof(communicator));

_communicator = communicator;
_messageReceivedSubsciption = _communicator.MessageReceived.Subscribe(HandleMessage);
_messageReceivedSubscription = _communicator.MessageReceived.Subscribe(HandleMessage);
}

/// <summary>
Expand All @@ -43,7 +51,7 @@ public BitmexWebsocketClient(IBitmexCommunicator communicator)
/// </summary>
public void Dispose()
{
_messageReceivedSubsciption?.Dispose();
_messageReceivedSubscription?.Dispose();
}

/// <summary>
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
6 changes: 4 additions & 2 deletions src/Bitmex.Client.Websocket/Json/BitmexStringEnumConverter.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public InstrumentSubscribeRequest()
}

/// <summary>
/// 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)
/// </summary>
public InstrumentSubscribeRequest(string pair)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<assemblyIdentity name="Serilog.Sinks.Console" publicKeyToken="24c2f752a8e58a10" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.1.0" newVersion="3.1.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reactive" publicKeyToken="94bc3704cddfc263" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\..\packages\Serilog.2.7.1\lib\net46\Serilog.dll</HintPath>
<HintPath>..\..\packages\Serilog.2.8.0\lib\net46\Serilog.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.ColoredConsole, Version=3.0.1.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\..\packages\Serilog.Sinks.ColoredConsole.3.0.1\lib\net45\Serilog.Sinks.ColoredConsole.dll</HintPath>
Expand All @@ -49,8 +49,17 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Reactive, Version=4.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reactive.4.0.0\lib\net46\System.Reactive.dll</HintPath>
<Reference Include="System.Reactive, Version=4.1.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reactive.4.1.2\lib\net46\System.Reactive.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
Expand All @@ -60,8 +69,8 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Websocket.Client, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Websocket.Client.1.0.5\lib\netstandard2.0\Websocket.Client.dll</HintPath>
<Reference Include="Websocket.Client, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Websocket.Client.2.0.10\lib\netstandard2.0\Websocket.Client.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net471" />
<package id="Serilog" version="2.7.1" targetFramework="net471" />
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net471" />
<package id="Serilog" version="2.8.0" targetFramework="net471" />
<package id="Serilog.Sinks.ColoredConsole" version="3.0.1" targetFramework="net471" />
<package id="Serilog.Sinks.Console" version="3.1.1" targetFramework="net471" />
<package id="Serilog.Sinks.File" version="4.0.0" targetFramework="net471" />
<package id="System.Reactive" version="4.0.0" targetFramework="net471" />
<package id="Websocket.Client" version="1.0.5" targetFramework="net471" />
<package id="System.Reactive" version="4.1.2" targetFramework="net471" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net471" />
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net471" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net471" />
<package id="Websocket.Client" version="2.0.10" targetFramework="net471" />
</packages>
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Reactive" publicKeyToken="94bc3704cddfc263" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\..\packages\Serilog.2.7.1\lib\net46\Serilog.dll</HintPath>
<HintPath>..\..\packages\Serilog.2.8.0\lib\net46\Serilog.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.Console, Version=3.1.1.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\..\packages\Serilog.Sinks.Console.3.1.1\lib\net45\Serilog.Sinks.Console.dll</HintPath>
Expand All @@ -50,8 +50,17 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Reactive, Version=4.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reactive.4.0.0\lib\net46\System.Reactive.dll</HintPath>
<Reference Include="System.Reactive, Version=4.1.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reactive.4.1.2\lib\net46\System.Reactive.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -63,8 +72,8 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Websocket.Client, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Websocket.Client.1.0.6\lib\netstandard2.0\Websocket.Client.dll</HintPath>
<Reference Include="Websocket.Client, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Websocket.Client.2.0.10\lib\netstandard2.0\Websocket.Client.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 8ee2bef

Please sign in to comment.