Skip to content

Commit

Permalink
Feature: Add AppLogger to support more features such as logging level
Browse files Browse the repository at this point in the history
  • Loading branch information
eynzhang committed May 7, 2020
1 parent f1a7a20 commit bcc302c
Show file tree
Hide file tree
Showing 39 changed files with 545 additions and 325 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Account;

namespace Huobi.SDK.Core.Client
Expand Down Expand Up @@ -26,7 +27,11 @@ public RequestAccountWebSocketV1ClientV(string accessKey, string secretKey, stri
/// <param name="clientId">Client id</param>
public void Request(string clientId = "")
{
_WebSocket.Send($"{{ \"op\":\"req\", \"cid\":\"{clientId}\", \"topic\": \"accounts.list\" }}");
string topic = "accounts.list";

_WebSocket.Send($"{{ \"op\":\"req\", \"cid\":\"{clientId}\", \"topic\": \"{topic}\" }}");

AppLogger.Info($"WebSocket requested, topic={topic}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Account;

namespace Huobi.SDK.Core.Client
Expand Down Expand Up @@ -29,7 +30,11 @@ public SubscribeAccountWebSocketV1Client(string accessKey, string secretKey, str
/// <param name="clientId">Client id</param>
public void Subscribe(string model, string clientId = "")
{
_WebSocket.Send($"{{ \"op\":\"sub\", \"cid\": \"{clientId}\", \"topic\":\"accounts\", \"model\": \"{model}\" }}");
string topic = "accounts";

_WebSocket.Send($"{{ \"op\":\"sub\", \"cid\": \"{clientId}\", \"topic\":\"{topic}\", \"model\": \"{model}\" }}");

AppLogger.Info($"WebSocket subscribed, topic={topic}, model={model}");
}

/// <summary>
Expand All @@ -39,7 +44,11 @@ public void Subscribe(string model, string clientId = "")
/// <param name="clientId">Client id</param>
public void UnSubscribe(string model, string clientId = "")
{
_WebSocket.Send($"{{ \"op\":\"unsub\", \"cid\": \"{clientId}\", \"topic\":\"accounts\", \"model\": \"{model}\" }}");
string topic = "accounts";

_WebSocket.Send($"{{ \"op\":\"unsub\", \"cid\": \"{clientId}\", \"topic\":\"{topic}\", \"model\": \"{model}\" }}");

AppLogger.Info($"WebSocket unsubscribed, topic={topic}, model={model}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Account;

namespace Huobi.SDK.Core.Client
Expand Down Expand Up @@ -29,7 +30,11 @@ public SubscribeAccountWebSocketV2Client(string accessKey, string secretKey, str
/// <param name="clientId">Client id</param>
public void Subscribe(string mode, string clientId = "")
{
_WebSocket.Send($"{{\"action\":\"sub\", \"cid\": \"{clientId}\", \"ch\":\"accounts.update#{mode}\"}}");
string topic = $"accounts.update#{mode}";

_WebSocket.Send($"{{\"action\":\"sub\", \"cid\": \"{clientId}\", \"ch\":\"{topic}\"}}");

AppLogger.Info($"WebSocket subscribed, topic={topic}");
}

/// <summary>
Expand All @@ -39,7 +44,11 @@ public void Subscribe(string mode, string clientId = "")
/// <param name="clientId">Client id</param>
public void UnSubscribe(string mode, string clientId = "")
{
_WebSocket.Send($"{{\"action\":\"unsub\", \"cid\": \"{clientId}\", \"ch\":\"accounts.update#{mode}\" }}");
string topic = $"accounts.update#{mode}";

_WebSocket.Send($"{{\"action\":\"unsub\", \"cid\": \"{clientId}\", \"ch\":\"{topic}\" }}");

AppLogger.Info($"WebSocket unsubscribed, topic={topic}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Market;

namespace Huobi.SDK.Core.Client
Expand All @@ -25,7 +26,11 @@ public BestBidOfferWebSocketClient(string host = DEFAULT_HOST)
/// <param name="clientId">Client id</param>
public void Subscribe(string symbol, string clientId = "")
{
_WebSocket.Send($"{{\"sub\": \"market.{symbol}.bbo\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.bbo";

_WebSocket.Send($"{{\"sub\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}

/// <summary>
Expand All @@ -35,7 +40,11 @@ public void Subscribe(string symbol, string clientId = "")
/// <param name="clientId">Client id</param>
public void UnSubscribe(string symbol, string clientId = "")
{
_WebSocket.Send($"{{\"unsub\": \"market.{symbol}.bbo\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.bbo";

_WebSocket.Send($"{{\"unsub\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket unsubscribed, topic={topic}, clientId={clientId}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Market;

namespace Huobi.SDK.Core.Client
Expand Down Expand Up @@ -28,9 +29,11 @@ public CandlestickWebSocketClient(string host = DEFAULT_HOST)
/// <param name="clientId">Client id</param>
public void Req(string symbol, string period, int from, int to, string clientId = "")
{
string req = $"{{\"req\": \"market.{symbol}.kline.{period}\",\"id\": \"{clientId}\", \"from\":{from}, \"to\":{to} }}";
string topic = $"market.{symbol}.kline.{period}";

_WebSocket.Send(req);
_WebSocket.Send($"{{ \"req\": \"{topic}\",\"id\": \"{clientId}\", \"from\":{from}, \"to\":{to} }}");

AppLogger.Info($"WebSocket requested, topic={topic}, clientId={clientId}");
}

/// <summary>
Expand All @@ -41,7 +44,11 @@ public void Req(string symbol, string period, int from, int to, string clientId
/// <param name="clientId">Client id</param>
public void Subscribe(string symbol, string period, string clientId = "")
{
_WebSocket.Send($"{{\"sub\": \"market.{symbol}.kline.{period}\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.kline.{period}";

_WebSocket.Send($"{{ \"sub\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}

/// <summary>
Expand All @@ -52,7 +59,11 @@ public void Subscribe(string symbol, string period, string clientId = "")
/// <param name="clientId">Client id</param>
public void UnSubscribe(string symbol, string period, string clientId = "")
{
_WebSocket.Send($"{{\"unsub\": \"market.{symbol}.kline.{period}\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.kline.{period}";

_WebSocket.Send($"{{ \"unsub\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket unsubscribed, topic={topic}, clientId={clientId}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Market;

namespace Huobi.SDK.Core.Client
Expand Down Expand Up @@ -27,9 +28,11 @@ public DepthWebSocketClient(string host = DEFAULT_HOST)
/// <param name="clientId">Client id</param>
public void Req(string symbol, string type, string clientId = "")
{
string req = $"{{\"req\": \"market.{symbol}.depth.{type}\",\"id\": \"{clientId}\" }}";
string topic = $"market.{symbol}.depth.{type}";

_WebSocket.Send(req);
_WebSocket.Send($"{{\"req\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket requested, topic={topic}, clientId={clientId}");
}


Expand All @@ -41,7 +44,11 @@ public void Req(string symbol, string type, string clientId = "")
/// <param name="clientId">Client id</param>
public void Subscribe(string symbol, string type, string clientId = "")
{
_WebSocket.Send($"{{\"sub\": \"market.{symbol}.depth.{type}\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.depth.{type}";

_WebSocket.Send($"{{\"sub\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}

/// <summary>
Expand All @@ -52,7 +59,11 @@ public void Subscribe(string symbol, string type, string clientId = "")
/// <param name="clientId">Client id</param>
public void UnSubscribe(string symbol, string type, string clientId = "")
{
_WebSocket.Send($"{{\"unsub\": \"market.{symbol}.depth.{type}\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.depth.{type}";

_WebSocket.Send($"{{\"unsub\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Market;

namespace Huobi.SDK.Core.Client
Expand All @@ -25,7 +26,11 @@ public Last24hCandlestickWebSocketClient(string host = DEFAULT_HOST)
/// <param name="clientId">Client id</param>
public void Req(string symbol, string clientId = "")
{
_WebSocket.Send($"{{\"req\": \"market.{symbol}.detail\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.detail";

_WebSocket.Send($"{{\"req\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket requested, topic={topic}, clientId={clientId}");
}


Expand All @@ -36,7 +41,11 @@ public void Req(string symbol, string clientId = "")
/// <param name="clientId">Client id</param>
public void Subscribe(string symbol, string clientId = "")
{
string topic = $"market.{symbol}.detail";

_WebSocket.Send($"{{\"sub\": \"market.{symbol}.detail\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}

/// <summary>
Expand All @@ -46,7 +55,11 @@ public void Subscribe(string symbol, string clientId = "")
/// <param name="clientId">Client id</param>
public void UnSubscribe(string symbol, string clientId = "")
{
string topic = $"market.{symbol}.detail";

_WebSocket.Send($"{{\"unsub\": \"market.{symbol}.detail\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket unsubscribed, topic={topic}, clientId={clientId}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Market;

namespace Huobi.SDK.Core.Client
Expand Down Expand Up @@ -30,7 +31,11 @@ public MarketByPriceWebSocketClient(string host = DEFAULT_HOST)
/// <param name="clientId">Client id</param>
public void Req(string symbol, string clientId = "")
{
_WebSocket.Send($"{{\"req\": \"market.{symbol}.mbp.150\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.mbp.150";

_WebSocket.Send($"{{\"req\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket request, topic={topic}, clientId={clientId}");
}

/// <summary>
Expand All @@ -40,31 +45,41 @@ public void Req(string symbol, string clientId = "")
/// <param name="clientId">Client id</param>
public void Subscribe(string symbol, string clientId = "")
{
_WebSocket.Send($"{{\"sub\": \"market.{symbol}.mbp.150\",\"id\": \"{clientId}\" }}");
}
string topic = $"market.{symbol}.mbp.150";

_WebSocket.Send($"{{\"sub\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}

/// <summary>
/// Subscribe full Market By Price order book
/// Unsubscribe Market By Price order book
/// </summary>
/// <param name="symbol">Trading symbol</param>
/// <param name="level">Number of price levels: 5, 10, 20</param>
/// <param name="clientId">Client id</param>
public void SubscribeFull(string symbol, int level, string clientId = "")
public void UnSubscribe(string symbol, string clientId = "")
{
_WebSocket.Send($"{{\"sub\": \"market.{symbol}.mbp.refresh.{level}\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.mbp.150";

_WebSocket.Send($"{{\"unsub\": \"market.{symbol}.mbp.150\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket unsubscribed, topic={topic}, clientId={clientId}");
}

/// <summary>
/// Unsubscribe Market By Price order book
/// Subscribe full Market By Price order book
/// </summary>
/// <param name="symbol">Trading symbol</param>
/// <param name="level">Number of price levels: 5, 10, 20</param>
/// <param name="clientId">Client id</param>
public void UnSubscribe(string symbol, string clientId = "")
public void SubscribeFull(string symbol, int level, string clientId = "")
{
_WebSocket.Send($"{{\"unsub\": \"market.{symbol}.mbp.150\",\"id\": \"{clientId}\" }}");
}
string topic = $"market.{symbol}.mbp.refresh.{level}";

_WebSocket.Send($"{{\"sub\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}

/// <summary>
/// Unsubscribe full Market By Price order book
Expand All @@ -74,7 +89,11 @@ public void UnSubscribe(string symbol, string clientId = "")
/// <param name="clientId">Client id</param>
public void UnSubscribeFull(string symbol, int level, string clientId = "")
{
string topic = $"market.{symbol}.mbp.refresh.{level}";

_WebSocket.Send($"{{\"unsub\": \"market.{symbol}.mbp.refresh.{level}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket unsubscribed, topic={topic}, clientId={clientId}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Market;

namespace Huobi.SDK.Core.Client
Expand All @@ -25,7 +26,11 @@ public TradeWebSocketClient(string host = DEFAULT_HOST)
/// <param name="clientId">Client id</param>
public void Req(string symbol, string clientId = "")
{
_WebSocket.Send($"{{\"req\": \"market.{symbol}.trade.detail\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.trade.detail";

_WebSocket.Send($"{{\"req\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket requested, topic={topic}, clientId={clientId}");
}


Expand All @@ -36,7 +41,11 @@ public void Req(string symbol, string clientId = "")
/// <param name="clientId">Client id</param>
public void Subscribe(string symbol, string clientId = "")
{
_WebSocket.Send($"{{\"sub\": \"market.{symbol}.trade.detail\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.trade.detail";

_WebSocket.Send($"{{ \"sub\": \"{topic}\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}

/// <summary>
Expand All @@ -46,7 +55,11 @@ public void Subscribe(string symbol, string clientId = "")
/// <param name="clientId">Client id</param>
public void UnSubscribe(string symbol, string clientId = "")
{
_WebSocket.Send($"{{\"unsub\": \"market.{symbol}.trade.detail\",\"id\": \"{clientId}\" }}");
string topic = $"market.{symbol}.trade.detail";

_WebSocket.Send($"{{ \"unsub\": \"market.{symbol}.trade.detail\",\"id\": \"{clientId}\" }}");

AppLogger.Info($"WebSocket unsubscribed, topic={topic}, clientId={clientId}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Order;

namespace Huobi.SDK.Core.Client
Expand Down Expand Up @@ -27,7 +28,11 @@ public RequestOrderWebSocketV1Client(string accessKey, string secretKey, string
/// <param name="clientId">Client id</param>
public void Request(string orderId, string clientId = "")
{
_WebSocket.Send($"{{ \"op\":\"req\", \"cid\": \"{clientId}\", \"topic\":\"orders.detail\", \"order-id\":\"{orderId}\" }}");
string topic = "orders.detail";

_WebSocket.Send($"{{ \"op\":\"req\", \"cid\": \"{clientId}\", \"topic\":\"{topic}\", \"order-id\":\"{orderId}\" }}");

AppLogger.Info($"WebSocket requested, topic={topic}, orderId={orderId}");
}
}
}
Loading

0 comments on commit bcc302c

Please sign in to comment.