diff --git a/Huobi.SDK.Core/Client/AccountWebSocketClient/RequestAccountWebSocketV1Client.cs b/Huobi.SDK.Core/Client/AccountWebSocketClient/RequestAccountWebSocketV1Client.cs
index 4254495..a12f443 100644
--- a/Huobi.SDK.Core/Client/AccountWebSocketClient/RequestAccountWebSocketV1Client.cs
+++ b/Huobi.SDK.Core/Client/AccountWebSocketClient/RequestAccountWebSocketV1Client.cs
@@ -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
@@ -26,7 +27,11 @@ public RequestAccountWebSocketV1ClientV(string accessKey, string secretKey, stri
/// Client id
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}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/AccountWebSocketClient/SubscribeAccountWebSocketV1Client.cs b/Huobi.SDK.Core/Client/AccountWebSocketClient/SubscribeAccountWebSocketV1Client.cs
index f7b33ea..55886b6 100644
--- a/Huobi.SDK.Core/Client/AccountWebSocketClient/SubscribeAccountWebSocketV1Client.cs
+++ b/Huobi.SDK.Core/Client/AccountWebSocketClient/SubscribeAccountWebSocketV1Client.cs
@@ -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
@@ -29,7 +30,11 @@ public SubscribeAccountWebSocketV1Client(string accessKey, string secretKey, str
/// Client id
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}");
}
///
@@ -39,7 +44,11 @@ public void Subscribe(string model, string clientId = "")
/// Client id
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}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/AccountWebSocketClient/SubscribeAccountWebSocketV2Client.cs b/Huobi.SDK.Core/Client/AccountWebSocketClient/SubscribeAccountWebSocketV2Client.cs
index 71ffa60..dcab56c 100644
--- a/Huobi.SDK.Core/Client/AccountWebSocketClient/SubscribeAccountWebSocketV2Client.cs
+++ b/Huobi.SDK.Core/Client/AccountWebSocketClient/SubscribeAccountWebSocketV2Client.cs
@@ -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
@@ -29,7 +30,11 @@ public SubscribeAccountWebSocketV2Client(string accessKey, string secretKey, str
/// Client id
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}");
}
///
@@ -39,7 +44,11 @@ public void Subscribe(string mode, string clientId = "")
/// Client id
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}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/MarketWebSocketClient/BestBidOfferWebSocketClient.cs b/Huobi.SDK.Core/Client/MarketWebSocketClient/BestBidOfferWebSocketClient.cs
index bd647bd..4490a3d 100644
--- a/Huobi.SDK.Core/Client/MarketWebSocketClient/BestBidOfferWebSocketClient.cs
+++ b/Huobi.SDK.Core/Client/MarketWebSocketClient/BestBidOfferWebSocketClient.cs
@@ -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
@@ -25,7 +26,11 @@ public BestBidOfferWebSocketClient(string host = DEFAULT_HOST)
/// Client id
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}");
}
///
@@ -35,7 +40,11 @@ public void Subscribe(string symbol, string clientId = "")
/// Client id
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}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/MarketWebSocketClient/CandlestickWebSocketClient.cs b/Huobi.SDK.Core/Client/MarketWebSocketClient/CandlestickWebSocketClient.cs
index cf6c57f..a2f40a8 100644
--- a/Huobi.SDK.Core/Client/MarketWebSocketClient/CandlestickWebSocketClient.cs
+++ b/Huobi.SDK.Core/Client/MarketWebSocketClient/CandlestickWebSocketClient.cs
@@ -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
@@ -28,9 +29,11 @@ public CandlestickWebSocketClient(string host = DEFAULT_HOST)
/// Client id
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}");
}
///
@@ -41,7 +44,11 @@ public void Req(string symbol, string period, int from, int to, string clientId
/// Client id
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}");
}
///
@@ -52,7 +59,11 @@ public void Subscribe(string symbol, string period, string clientId = "")
/// Client id
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}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/MarketWebSocketClient/DepthWebSocketClient.cs b/Huobi.SDK.Core/Client/MarketWebSocketClient/DepthWebSocketClient.cs
index 54fe452..d4085b0 100644
--- a/Huobi.SDK.Core/Client/MarketWebSocketClient/DepthWebSocketClient.cs
+++ b/Huobi.SDK.Core/Client/MarketWebSocketClient/DepthWebSocketClient.cs
@@ -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
@@ -27,9 +28,11 @@ public DepthWebSocketClient(string host = DEFAULT_HOST)
/// Client id
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}");
}
@@ -41,7 +44,11 @@ public void Req(string symbol, string type, string clientId = "")
/// Client id
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}");
}
///
@@ -52,7 +59,11 @@ public void Subscribe(string symbol, string type, string clientId = "")
/// Client id
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}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/MarketWebSocketClient/Last24hCandlestickWebSocketClient.cs b/Huobi.SDK.Core/Client/MarketWebSocketClient/Last24hCandlestickWebSocketClient.cs
index 31cc46e..a694ade 100644
--- a/Huobi.SDK.Core/Client/MarketWebSocketClient/Last24hCandlestickWebSocketClient.cs
+++ b/Huobi.SDK.Core/Client/MarketWebSocketClient/Last24hCandlestickWebSocketClient.cs
@@ -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
@@ -25,7 +26,11 @@ public Last24hCandlestickWebSocketClient(string host = DEFAULT_HOST)
/// Client id
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}");
}
@@ -36,7 +41,11 @@ public void Req(string symbol, string clientId = "")
/// Client id
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}");
}
///
@@ -46,7 +55,11 @@ public void Subscribe(string symbol, string clientId = "")
/// Client id
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}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/MarketWebSocketClient/MarketByPriceWebSocketClient.cs b/Huobi.SDK.Core/Client/MarketWebSocketClient/MarketByPriceWebSocketClient.cs
index 05d4f4c..f526048 100644
--- a/Huobi.SDK.Core/Client/MarketWebSocketClient/MarketByPriceWebSocketClient.cs
+++ b/Huobi.SDK.Core/Client/MarketWebSocketClient/MarketByPriceWebSocketClient.cs
@@ -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
@@ -30,7 +31,11 @@ public MarketByPriceWebSocketClient(string host = DEFAULT_HOST)
/// Client id
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}");
}
///
@@ -40,31 +45,41 @@ public void Req(string symbol, string clientId = "")
/// Client id
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}");
+ }
///
- /// Subscribe full Market By Price order book
+ /// Unsubscribe Market By Price order book
///
/// Trading symbol
- /// Number of price levels: 5, 10, 20
/// Client id
- 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}");
}
///
- /// Unsubscribe Market By Price order book
+ /// Subscribe full Market By Price order book
///
/// Trading symbol
+ /// Number of price levels: 5, 10, 20
/// Client id
- 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}");
+ }
///
/// Unsubscribe full Market By Price order book
@@ -74,7 +89,11 @@ public void UnSubscribe(string symbol, string clientId = "")
/// Client id
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}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/MarketWebSocketClient/TradeWebSocketClient.cs b/Huobi.SDK.Core/Client/MarketWebSocketClient/TradeWebSocketClient.cs
index 35b9fde..54ba574 100644
--- a/Huobi.SDK.Core/Client/MarketWebSocketClient/TradeWebSocketClient.cs
+++ b/Huobi.SDK.Core/Client/MarketWebSocketClient/TradeWebSocketClient.cs
@@ -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
@@ -25,7 +26,11 @@ public TradeWebSocketClient(string host = DEFAULT_HOST)
/// Client id
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}");
}
@@ -36,7 +41,11 @@ public void Req(string symbol, string clientId = "")
/// Client id
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}");
}
///
@@ -46,7 +55,11 @@ public void Subscribe(string symbol, string clientId = "")
/// Client id
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}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/OrderWebSocketClient/RequestOrderWebSocketV1Client.cs b/Huobi.SDK.Core/Client/OrderWebSocketClient/RequestOrderWebSocketV1Client.cs
index 243b304..83538cd 100644
--- a/Huobi.SDK.Core/Client/OrderWebSocketClient/RequestOrderWebSocketV1Client.cs
+++ b/Huobi.SDK.Core/Client/OrderWebSocketClient/RequestOrderWebSocketV1Client.cs
@@ -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
@@ -27,7 +28,11 @@ public RequestOrderWebSocketV1Client(string accessKey, string secretKey, string
/// Client id
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}");
}
}
}
\ No newline at end of file
diff --git a/Huobi.SDK.Core/Client/OrderWebSocketClient/RequestOrdersWebSocketV1Client.cs b/Huobi.SDK.Core/Client/OrderWebSocketClient/RequestOrdersWebSocketV1Client.cs
index 3652229..299afc9 100644
--- a/Huobi.SDK.Core/Client/OrderWebSocketClient/RequestOrdersWebSocketV1Client.cs
+++ b/Huobi.SDK.Core/Client/OrderWebSocketClient/RequestOrdersWebSocketV1Client.cs
@@ -1,6 +1,7 @@
using Huobi.SDK.Core.Client.WebSocketClientBase;
using Huobi.SDK.Model.Response.Order;
using Huobi.SDK.Model.Request;
+using Huobi.SDK.Log;
namespace Huobi.SDK.Core.Client
{
@@ -28,6 +29,8 @@ public RequestOrdersWebSocketV1Client(string accessKey, string secretKey, string
public void Request(RequestOrdersRequest request)
{
_WebSocket.Send(request.ToJson());
+
+ AppLogger.Info($"WebSocket requested, topic={request.topic}, accountId={request.AccountId} symbol={request.symbol}");
}
}
}
\ No newline at end of file
diff --git a/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeOrderWebSocketV1Client.cs b/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeOrderWebSocketV1Client.cs
index a119cf6..caf4033 100644
--- a/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeOrderWebSocketV1Client.cs
+++ b/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeOrderWebSocketV1Client.cs
@@ -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
@@ -27,7 +28,11 @@ public SubscribeOrderWebSocketV1Client(string accessKey, string secretKey, strin
/// Client id
public void Subscribe(string symbol, string clientId = "")
{
- _WebSocket.Send($"{{ \"op\":\"sub\", \"cid\": \"{clientId}\", \"topic\":\"orders.{symbol}.update\" }}");
+ string topic = $"orders.{symbol}.update";
+
+ _WebSocket.Send($"{{ \"op\":\"sub\", \"cid\": \"{clientId}\", \"topic\":\"{topic}\" }}");
+
+ AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}
///
@@ -37,7 +42,11 @@ public void Subscribe(string symbol, string clientId = "")
/// Client id
public void UnSubscribe(string symbol, string clientId = "")
{
- _WebSocket.Send($"{{ \"op\":\"unsub\", \"cid\": \"{clientId}\", \"topic\":\"orders.{symbol}.update\" }}");
+ string topic = $"orders.{symbol}.update";
+
+ _WebSocket.Send($"{{ \"op\":\"unsub\", \"cid\": \"{clientId}\", \"topic\":\"{topic}\" }}");
+
+ AppLogger.Info($"WebSocket unsubscribed, topic={topic}, clientId={clientId}");
}
}
}
\ No newline at end of file
diff --git a/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeOrderWebSocketV2Client.cs b/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeOrderWebSocketV2Client.cs
index eeb2c60..61bf237 100644
--- a/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeOrderWebSocketV2Client.cs
+++ b/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeOrderWebSocketV2Client.cs
@@ -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
@@ -27,7 +28,11 @@ public SubscribeOrderWebSocketV2Client(string accessKey, string secretKey, strin
///
public void Subscribe(string symbol, string clientId = "")
{
- _WebSocket.Send($"{{\"action\":\"sub\", \"ch\":\"orders#{symbol}\", \"cid\": \"{clientId}\" }}");
+ string topic = $"orders#{symbol}";
+
+ _WebSocket.Send($"{{\"action\":\"sub\", \"ch\":\"{topic}\", \"cid\": \"{clientId}\" }}");
+
+ AppLogger.Info($"WebSocket subscribed, topic={topic}");
}
///
@@ -37,7 +42,11 @@ public void Subscribe(string symbol, string clientId = "")
/// Client id
public void UnSubscribe(string symbol, string clientId = "")
{
- _WebSocket.Send($"{{\"action\":\"unsub\", \"ch\":\"orders#{symbol}\", \"cid\": \"{clientId}\" }}");
+ string topic = $"orders#{symbol}";
+
+ _WebSocket.Send($"{{\"action\":\"unsub\", \"ch\":\"{topic}\", \"cid\": \"{clientId}\" }}");
+
+ AppLogger.Info($"WebSocket unsubscribed, topic={topic}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeTradeClearWebSocketV2Client.cs b/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeTradeClearWebSocketV2Client.cs
index 0e96be2..03eb315 100644
--- a/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeTradeClearWebSocketV2Client.cs
+++ b/Huobi.SDK.Core/Client/OrderWebSocketClient/SubscribeTradeClearWebSocketV2Client.cs
@@ -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
@@ -28,7 +29,11 @@ public SubscribeTradeClearWebSocketV2Client(string accessKey, string secretKey,
///
public void Subscribe(string symbol, string clientId = "")
{
- _WebSocket.Send($"{{\"action\":\"sub\", \"cid\": \"{clientId}\", \"ch\":\"trade.clearing#{symbol}\" }}");
+ string topic = $"trade.clearing#{symbol}";
+
+ _WebSocket.Send($"{{\"action\":\"sub\", \"cid\": \"{clientId}\", \"ch\":\"{topic}\" }}");
+
+ AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}
///
@@ -38,7 +43,11 @@ public void Subscribe(string symbol, string clientId = "")
/// Client id
public void UnSubscribe(string symbol, string clientId = "")
{
- _WebSocket.Send($"{{\"action\":\"unsub\", \"cid\": \"{clientId}\", \"ch\":\"trade.clearing#{symbol}\" }}");
+ string topic = $"trade.clearing#{symbol}";
+
+ _WebSocket.Send($"{{\"action\":\"unsub\", \"cid\": \"{clientId}\", \"ch\":\"{topic}\" }}");
+
+ AppLogger.Info($"WebSocket subscribed, topic={topic}, clientId={clientId}");
}
}
}
diff --git a/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketClientBase.cs b/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketClientBase.cs
index dfd6c28..3d30afe 100644
--- a/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketClientBase.cs
+++ b/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketClientBase.cs
@@ -1,6 +1,7 @@
using System;
using System.Timers;
using Huobi.SDK.Core.Model;
+using Huobi.SDK.Log;
using Newtonsoft.Json;
using WebSocketSharp;
@@ -46,17 +47,17 @@ public WebSocketClientBase(string host = DEFAULT_HOST)
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
double elapsedSecond = (DateTime.UtcNow - _lastReceivedTime).TotalSeconds;
- Console.WriteLine($"WebSocket received data {elapsedSecond} sec ago");
+ AppLogger.Trace($"WebSocket received data {elapsedSecond.ToString("0.00")} sec ago");
if (elapsedSecond > RECONNECT_WAIT_SECOND && elapsedSecond <= RENEW_WAIT_SECOND)
{
- Console.WriteLine("WebSocket reconnecting...");
+ AppLogger.Info("WebSocket reconnecting...");
_WebSocket.Close();
_WebSocket.Connect();
}
else if (elapsedSecond > RENEW_WAIT_SECOND)
{
- Console.WriteLine("WebSocket re-initialize...");
+ AppLogger.Info("WebSocket re-initialize...");
Disconnect();
UninitializeWebSocket();
InitializeWebSocket();
@@ -113,7 +114,7 @@ public void Disconnect()
private void _WebSocket_OnOpen(object sender, EventArgs e)
{
- Console.WriteLine("WebSocket Opened");
+ AppLogger.Debug("WebSocket opened");
_lastReceivedTime = DateTime.UtcNow;
@@ -131,10 +132,10 @@ private void _WebSocket_OnMessage(object sender, MessageEventArgs e)
var pingMessage = JsonConvert.DeserializeObject(data);
if (pingMessage != null && pingMessage.ping != 0)
{
- Console.WriteLine($"received ping:{pingMessage.ping}");
+ AppLogger.Trace($"WebSocekt received data, ping={pingMessage.ping}");
string pongData = $"{{\"pong\":{pingMessage.ping}}}";
_WebSocket.Send(pongData);
- Console.WriteLine($"replied pong:{pingMessage.ping}");
+ AppLogger.Trace($"WebSocket replied data, pong={pingMessage.ping}");
}
else
{
@@ -147,7 +148,7 @@ private void _WebSocket_OnMessage(object sender, MessageEventArgs e)
private void _WebSocket_OnError(object sender, ErrorEventArgs e)
{
- Console.WriteLine($"WebSocket Error: {e.Message}");
+ AppLogger.Error($"WebSocket Error: {e.Message}");
}
}
}
\ No newline at end of file
diff --git a/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketV1ClientBase.cs b/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketV1ClientBase.cs
index d24d1f5..65abf3e 100644
--- a/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketV1ClientBase.cs
+++ b/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketV1ClientBase.cs
@@ -2,6 +2,7 @@
using System.Timers;
using Huobi.SDK.Core.Model;
using Huobi.SDK.Core.RequestBuilder;
+using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Auth;
using Huobi.SDK.Model.Response.WebSocket;
using Newtonsoft.Json;
@@ -55,17 +56,17 @@ public WebSocketV1ClientBase(string accessKey, string secretKey, string host = D
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
double elapsedSecond = (DateTime.UtcNow - _lastReceivedTime).TotalSeconds;
- Console.WriteLine($"WebSocket received data {elapsedSecond} sec ago");
+ AppLogger.Trace($"WebSocket received data {elapsedSecond.ToString("0.00")} sec ago");
if (elapsedSecond > RECONNECT_WAIT_SECOND && elapsedSecond <= RENEW_WAIT_SECOND)
{
- Console.WriteLine("WebSocket reconnecting...");
+ AppLogger.Info("WebSocket reconnecting...");
_WebSocket.Close();
_WebSocket.Connect();
}
else if (elapsedSecond > RENEW_WAIT_SECOND)
{
- Console.WriteLine("WebSocket re-initialize...");
+ AppLogger.Info("WebSocket re-initialize...");
Disconnect();
UninitializeWebSocket();
InitializeWebSocket();
@@ -122,13 +123,13 @@ public void Disconnect()
private void _WebSocket_OnOpen(object sender, EventArgs e)
{
- Console.WriteLine("WebSocket opened");
+ AppLogger.Debug("WebSocket opened");
_lastReceivedTime = DateTime.UtcNow;
string authRequest = _wsV1ReqBuilder.Build();
_WebSocket.Send(authRequest);
- Console.WriteLine("Authentication sent");
+ AppLogger.Debug("WebSocket authentication sent");
}
private void _WebSocket_OnMessage(object sender, MessageEventArgs e)
@@ -142,10 +143,10 @@ private void _WebSocket_OnMessage(object sender, MessageEventArgs e)
var pingMessage = JsonConvert.DeserializeObject(data);
if (pingMessage.IsPing())
{
- Console.WriteLine($"Received ping:{pingMessage.ts}");
+ AppLogger.Trace($"WebSocket received data, ping={pingMessage.ts}");
string pongData = $"{{\"op\":\"pong\", \"ts\":{pingMessage.ts}}}";
_WebSocket.Send(pongData);
- Console.WriteLine($"Replied pong:{pingMessage.ts}");
+ AppLogger.Trace($"WebSocket repied data, pong={pingMessage.ts}");
}
else
{
@@ -169,7 +170,7 @@ private void _WebSocket_OnMessage(object sender, MessageEventArgs e)
private void _WebSocket_OnError(object sender, ErrorEventArgs e)
{
- Console.WriteLine($"WebSocket error: {e.Message}");
+ AppLogger.Error($"WebSocket error: {e.Message}");
}
}
}
\ No newline at end of file
diff --git a/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketV2ClientBase.cs b/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketV2ClientBase.cs
index 51f3488..f959e09 100644
--- a/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketV2ClientBase.cs
+++ b/Huobi.SDK.Core/Client/WebSocketClientBase/WebSocketV2ClientBase.cs
@@ -2,6 +2,7 @@
using System.Timers;
using Huobi.SDK.Core.Model;
using Huobi.SDK.Core.RequestBuilder;
+using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Auth;
using Huobi.SDK.Model.Response.WebSocket;
using Newtonsoft.Json;
@@ -56,17 +57,17 @@ public WebSocketV2ClientBase(string accessKey, string secretKey, string host = D
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
double elapsedSecond = (DateTime.UtcNow - _lastReceivedTime).TotalSeconds;
- Console.WriteLine($"WebSocket received data {elapsedSecond} sec ago");
+ AppLogger.Trace($"WebSocket received data {elapsedSecond.ToString("0.00")} sec ago");
if (elapsedSecond > RECONNECT_WAIT_SECOND && elapsedSecond <= RENEW_WAIT_SECOND)
{
- Console.WriteLine("WebSocket reconnecting...");
+ AppLogger.Info("WebSocket reconnecting...");
_WebSocket.Close();
_WebSocket.Connect();
}
else if (elapsedSecond > RENEW_WAIT_SECOND)
{
- Console.WriteLine("WebSocket re-initialize...");
+ AppLogger.Info("WebSocket re-initialize...");
Disconnect();
UninitializeWebSocket();
InitializeWebSocket();
@@ -123,7 +124,7 @@ public void Disconnect()
private void _WebSocket_OnOpen(object sender, EventArgs e)
{
- Console.WriteLine("WebSocket opened");
+ AppLogger.Debug("WebSocket opened");
_lastReceivedTime = DateTime.UtcNow;
@@ -153,12 +154,12 @@ private void _WebSocket_OnMessage(object sender, MessageEventArgs e)
{
long ts = pingMessageV2.data.ts;
- Console.WriteLine($"received ping:{ts}");
+ AppLogger.Trace($"WebSocket received data, ping={ts}");
string pongData = $"{{\"action\": \"pong\", \"data\": {{\"ts\":{ts} }} }}";
_WebSocket.Send(pongData);
- Console.WriteLine($"replied pong:{ts}");
+ AppLogger.Trace($"WebSocket replied data, pong={ts}");
}
break;
}
@@ -185,7 +186,7 @@ private void _WebSocket_OnMessage(object sender, MessageEventArgs e)
private void _WebSocket_OnError(object sender, ErrorEventArgs e)
{
- Console.WriteLine($"WebSocket error: {e.Message}");
+ AppLogger.Error($"WebSocket error: {e.Message}");
}
}
}
diff --git a/Huobi.SDK.Example/AccountClientExample.cs b/Huobi.SDK.Example/AccountClientExample.cs
index 981346a..d306ff3 100644
--- a/Huobi.SDK.Example/AccountClientExample.cs
+++ b/Huobi.SDK.Example/AccountClientExample.cs
@@ -47,7 +47,7 @@ private static void GetAccountInfo()
{
foreach (var a in result.data)
{
- Console.WriteLine($"account id: {a.id}, type: {a.type}, state: {a.state}");
+ AppLogger.Info($"account id: {a.id}, type: {a.type}, state: {a.state}");
}
}
}
@@ -74,16 +74,16 @@ private static void GetAccountBalance()
if (Math.Abs(float.Parse(b.balance)) > 0.00001)
{
availableCount++;
- Console.WriteLine($"currency: {b.currency}, type: {b.type}, balance: {b.balance}");
+ AppLogger.Info($"currency: {b.currency}, type: {b.type}, balance: {b.balance}");
}
}
- Console.WriteLine($"There are total {result.data.list.Length} currencys and available {availableCount} currencys in this account");
+ AppLogger.Info($"There are total {result.data.list.Length} currencys and available {availableCount} currencys in this account");
}
break;
}
case "error":
{
- Console.WriteLine($"Get fail, error code: {result.errorCode}, error message: {result.errorMessage}");
+ AppLogger.Info($"Get fail, error code: {result.errorCode}, error message: {result.errorMessage}");
break;
}
}
@@ -108,14 +108,14 @@ private static void GetAccountHistory()
{
foreach (var h in result.data)
{
- Console.WriteLine($"currency: {h.currency}, amount: {h.transactAmt}, type: {h.transactType}, time: {h.transactTime}");
+ AppLogger.Info($"currency: {h.currency}, amount: {h.transactAmt}, type: {h.transactType}, time: {h.transactTime}");
}
- Console.WriteLine($"There are total {result.data.Length} transactions");
+ AppLogger.Info($"There are total {result.data.Length} transactions");
break;
}
case "error":
{
- Console.WriteLine($"Get fail, error code: {result.errorCode}, error message: {result.errorMessage}");
+ AppLogger.Info($"Get fail, error code: {result.errorCode}, error message: {result.errorMessage}");
break;
}
}
@@ -138,12 +138,12 @@ private static void GetAccountLedger()
{
foreach (var l in result.data)
{
- Console.WriteLine($"Get account ledger, accountId: {l.accountId}, currency: {l.currency}, amount: {l.transactAmt}, transferer: {l.transferer}, transferee: {l.transferee}");
+ AppLogger.Info($"Get account ledger, accountId: {l.accountId}, currency: {l.currency}, amount: {l.transactAmt}, transferer: {l.transferer}, transferee: {l.transferee}");
}
}
else
{
- Console.WriteLine($"Get account ledger error: {result.message}");
+ AppLogger.Info($"Get account ledger error: {result.message}");
}
}
}
@@ -162,12 +162,12 @@ private static void TransferFromSpotToFuture()
{
case "ok":
{
- Console.WriteLine($"Transfer successfully, trade id: {result.data}");
+ AppLogger.Info($"Transfer successfully, trade id: {result.data}");
break;
}
case "error":
{
- Console.WriteLine($"Transfer fail, error code: {result.errorCode}, error message: {result.errorMessage}");
+ AppLogger.Info($"Transfer fail, error code: {result.errorCode}, error message: {result.errorMessage}");
break;
}
}
@@ -188,12 +188,12 @@ private static void TransferFromFutureToSpot()
{
case "ok":
{
- Console.WriteLine($"Transfer successfully, trade id: {result.data}");
+ AppLogger.Info($"Transfer successfully, trade id: {result.data}");
break;
}
case "error":
{
- Console.WriteLine($"Transfer fail, error code: {result.errorCode}, error message: {result.errorMessage}");
+ AppLogger.Info($"Transfer fail, error code: {result.errorCode}, error message: {result.errorMessage}");
break;
}
}
@@ -214,12 +214,12 @@ private static void TransferCurrencyFromMasterToSub()
{
case "ok":
{
- Console.WriteLine($"Transfer successfully, trade id: {result.data}");
+ AppLogger.Info($"Transfer successfully, trade id: {result.data}");
break;
}
case "error":
{
- Console.WriteLine($"Transfer fail, error code: {result.errorCode}, error message: {result.errorMessage}");
+ AppLogger.Info($"Transfer fail, error code: {result.errorCode}, error message: {result.errorMessage}");
break;
}
}
@@ -242,10 +242,10 @@ private static void GetSubuserAccountBalances()
if (Math.Abs(float.Parse(b.balance)) > 0.00001)
{
availableCount++;
- Console.WriteLine($"currency: {b.currency}, type: {b.type}, balance: {b.balance}");
+ AppLogger.Info($"currency: {b.currency}, type: {b.type}, balance: {b.balance}");
}
}
- Console.WriteLine($"There are total {result.data.Length} currencys and available {availableCount} currencys in this account");
+ AppLogger.Info($"There are total {result.data.Length} currencys and available {availableCount} currencys in this account");
}
}
@@ -262,18 +262,18 @@ private static void GetSubuserAccountBalance()
foreach (var a in result.data)
{
int availableCount = 0;
- Console.WriteLine($"account id: {a.id}, type: {a.type}");
+ AppLogger.Info($"account id: {a.id}, type: {a.type}");
foreach (var b in a.list)
{
if (Math.Abs(float.Parse(b.balance)) > 0.00001)
{
availableCount++;
- Console.WriteLine($"currency: {b.currency}, type: {b.type}, balance: {b.balance}");
+ AppLogger.Info($"currency: {b.currency}, type: {b.type}, balance: {b.balance}");
}
}
- Console.WriteLine($"There are total {a.list.Length} accounts and available {availableCount} currencys in this account");
+ AppLogger.Info($"There are total {a.list.Length} accounts and available {availableCount} currencys in this account");
}
- Console.WriteLine($"There are total {result.data.Length} accounts");
+ AppLogger.Info($"There are total {result.data.Length} accounts");
}
}
@@ -289,11 +289,11 @@ private static void LockSubUser()
{
if (result.code == (int)ResponseCode.Success && result.data != null)
{
- Console.WriteLine($"Lock sub user ${result.data.subUid} result: {result.data.userState}");
+ AppLogger.Info($"Lock sub user ${result.data.subUid} result: {result.data.userState}");
}
else
{
- Console.WriteLine($"Lock sub user error: {result.code}");
+ AppLogger.Info($"Lock sub user error: {result.code}");
}
}
}
@@ -310,11 +310,11 @@ private static void UnLockSubUser()
{
if (result.code == (int)ResponseCode.Success && result.data != null)
{
- Console.WriteLine($"Unlock sub user ${result.data.subUid} result: {result.data.userState}");
+ AppLogger.Info($"Unlock sub user ${result.data.subUid} result: {result.data.userState}");
}
else
{
- Console.WriteLine($"Unlock sub user error: {result.code}");
+ AppLogger.Info($"Unlock sub user error: {result.code}");
}
}
}
diff --git a/Huobi.SDK.Example/AccountWebSocketClientExample.cs b/Huobi.SDK.Example/AccountWebSocketClientExample.cs
index 577c6d4..7d3484b 100644
--- a/Huobi.SDK.Example/AccountWebSocketClientExample.cs
+++ b/Huobi.SDK.Example/AccountWebSocketClientExample.cs
@@ -1,9 +1,9 @@
using System;
using Huobi.SDK.Core.Client;
+using Huobi.SDK.Log;
using Huobi.SDK.Model.Response;
using Huobi.SDK.Model.Response.Account;
using Huobi.SDK.Model.Response.Auth;
-using Huobi.SDK.Model.Response.WebSocket;
namespace Huobi.SDK.Example
{
@@ -31,7 +31,10 @@ void Client_OnAuthReceived(WebSocketV1AuthResponse response)
{
// Request full data if authentication passed
client.Request();
- Console.WriteLine("Request sent");
+ }
+ else
+ {
+ AppLogger.Error($"Authentication fail, errorCode={response.errCode}");
}
}
@@ -41,14 +44,15 @@ void Client_OnDataReceived(RequestAccountResponse response)
{
if (response != null && response.data != null)
{
+ AppLogger.Info($"WebSocket returned data, topic={response.topic}, count={response.data.Length}");
foreach (var a in response.data)
{
- Console.WriteLine($"account id: {a.id}, type: {a.type}, state: {a.state}");
if (a.list != null)
{
+ AppLogger.Info($"count={a.list.Length}, accountId={a.id}, type={a.type}, state={a.state}");
foreach (var b in a.list)
{
- Console.WriteLine($"currency: {b.currency}, type: {b.type}, balance: {b.balance}");
+ AppLogger.Info($"currency={b.currency}, type={b.type}, balance={b.balance}");
}
}
}
@@ -78,7 +82,6 @@ void Client_OnAuthReceived(WebSocketV1AuthResponse response)
{
// Subscribe the specific topic
client.Subscribe("1");
- Console.WriteLine("Subscription sent");
}
}
@@ -88,12 +91,13 @@ void Client_OnDataReceived(SubscribeAccountV1Response response)
{
if (response != null && response.data != null)
{
- Console.WriteLine($"Account update: {response.data.@event}");
+ AppLogger.Info($"WebSocket received data, topic={response.topic}, event={response.data.@event}");
if (response.data.list != null)
{
+ AppLogger.Info($"count={response.data.list.Length}");
foreach (var b in response.data.list)
{
- Console.WriteLine($"account id: {b.accountId}, currency: {b.currency}, type: {b.type}, balance: {b.balance}");
+ AppLogger.Info($"account id: {b.accountId}, currency: {b.currency}, type: {b.type}, balance: {b.balance}");
}
}
}
@@ -125,7 +129,10 @@ void Client_OnAuthReceived(WebSocketV2AuthResponse response)
{
// Subscribe the specific topic
client.Subscribe("1");
- Console.WriteLine("Subscription sent");
+ }
+ else
+ {
+ AppLogger.Error($"WebSocket authentication fail, code={response.code}, message={response.message}");
}
}
@@ -139,11 +146,11 @@ void Client_OnDataReceived(SubscribeAccountV2Response response)
{
if (response.code == (int)ResponseCode.Success)
{
- Console.WriteLine($"Subscribe topic {response.ch} successfully");
+ AppLogger.Info($"WebSocket subscribed successfully, topic={response.ch} ");
}
else
{
- Console.WriteLine($"Subscribe topic {response.ch} fail, error code: {response.code}, error message: {response.message}");
+ AppLogger.Info($"WebSocket subscribed topic fail, topic={response.ch}, errorCode={response.code}, errorMessage={response.message}");
}
}
else if (response.action.Equals("push") && response.data != null)
@@ -151,11 +158,11 @@ void Client_OnDataReceived(SubscribeAccountV2Response response)
var b = response.data;
if (b.changeTime == null)
{
- Console.WriteLine($"Account overview, currency: {b.currency}, id: {b.accountId}, balance: {b.balance}");
+ AppLogger.Info($"WebSocket returned data, topic={response.ch}, currency={b.currency}, id={b.accountId}, balance={b.balance}, available={b.available}");
}
else
{
- Console.WriteLine($"Account update, currency: {b.currency}, id: {b.accountId}, balance: {b.balance}, time: {b.changeTime}");
+ AppLogger.Info($"WebSocket received data, topic={response.ch}, currency={b.currency}, id={b.accountId}, balance={b.balance}, available={b.available}, time={b.changeTime}");
}
}
}
diff --git a/Huobi.SDK.Example/CommonClientExample.cs b/Huobi.SDK.Example/CommonClientExample.cs
index dd584f0..ec9136a 100644
--- a/Huobi.SDK.Example/CommonClientExample.cs
+++ b/Huobi.SDK.Example/CommonClientExample.cs
@@ -30,7 +30,7 @@ private static void GetSystemStatus()
string result = client.GetSystemStatus().Result;
_logger.StopAndLog();
- Console.WriteLine($"Get system status: {result}");
+ AppLogger.Info($"Get system status: {result}");
}
private static void GetSymbols()
@@ -45,9 +45,9 @@ private static void GetSymbols()
{
foreach (var d in symbolsResponse.data)
{
- Console.WriteLine($"{d.symbol}: {d.baseCurrency} {d.quoteCurrency}");
+ AppLogger.Info($"{d.symbol}: {d.baseCurrency} {d.quoteCurrency}");
}
- Console.WriteLine($"there are total {symbolsResponse.data.Length} symbols");
+ AppLogger.Info($"there are total {symbolsResponse.data.Length} symbols");
}
}
@@ -63,9 +63,9 @@ private static void GetCurrencys()
{
foreach (var d in currencysResponse.data)
{
- Console.WriteLine(d);
+ AppLogger.Info(d);
}
- Console.WriteLine($"there are total {currencysResponse.data.Length} currencys");
+ AppLogger.Info($"there are total {currencysResponse.data.Length} currencys");
}
}
@@ -83,16 +83,16 @@ private static void GetCurrency()
{
foreach (var d in currencyResponse.data)
{
- Console.WriteLine($"Currency: {d.currency}");
+ AppLogger.Info($"Currency: {d.currency}");
foreach (var c in d.chains)
{
- Console.WriteLine($"Chain name: {c.chain}, base chain: {c.baseChain}, base chain protocol: {c.baseChainProtocol}");
+ AppLogger.Info($"Chain name: {c.chain}, base chain: {c.baseChain}, base chain protocol: {c.baseChainProtocol}");
}
}
}
else
{
- Console.WriteLine(currencyResponse.message);
+ AppLogger.Info(currencyResponse.message);
}
}
}
@@ -105,8 +105,8 @@ private static void GetTimestamp()
var timestampResponse = client.GetTimestampAsync().Result;
_logger.StopAndLog();
- Console.WriteLine($"timestamp (ms): {timestampResponse.data}");
- Console.WriteLine($"Local time: {Timestamp.MSToLocal(timestampResponse.data)}");
+ AppLogger.Info($"timestamp (ms): {timestampResponse.data}");
+ AppLogger.Info($"Local time: {Timestamp.MSToLocal(timestampResponse.data)}");
}
}
}
diff --git a/Huobi.SDK.Example/Config.cs b/Huobi.SDK.Example/Config.cs
index 685a6c0..595797c 100644
--- a/Huobi.SDK.Example/Config.cs
+++ b/Huobi.SDK.Example/Config.cs
@@ -15,7 +15,7 @@ public class Config
/// Load Accesskey and AccountId from 'appsettings.json' and SecretKey from 'key.json'.
///
/// To prevent submitting SecretKey into repository by accident, the 'key.json' file
- /// is added in the .gitignore file
+ /// is already added in the .gitignore file
///
/// You should create the key.json file and include it into your solution with below definition
///
@@ -26,15 +26,15 @@ public class Config
///
public static void LoadConfig()
{
+ // Read configs from 'appsettings.json'
var config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
-
Host = config["Host"];
AccessKey = config["AccessKey"];
AccountId = config["AccountId"];
SubUserId = config["SubUserId"];
+ // Read SecretKey from 'key.json'
config = new ConfigurationBuilder().AddJsonFile("key.json").Build();
-
SecretKey = config["SecretKey"];
}
}
diff --git a/Huobi.SDK.Example/CrossMarginClientExample.cs b/Huobi.SDK.Example/CrossMarginClientExample.cs
index 802832b..9784c0e 100644
--- a/Huobi.SDK.Example/CrossMarginClientExample.cs
+++ b/Huobi.SDK.Example/CrossMarginClientExample.cs
@@ -40,12 +40,12 @@ private static void TransferIn()
{
case "ok":
{
- Console.WriteLine($"Transfer successfully, transfer id: {response.data}");
+ AppLogger.Info($"Transfer successfully, transfer id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Transfer fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Transfer fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -66,12 +66,12 @@ private static void TransferOut()
{
case "ok":
{
- Console.WriteLine($"Transfer successfully, transfer id: {response.data}");
+ AppLogger.Info($"Transfer successfully, transfer id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Transfer fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Transfer fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -95,7 +95,7 @@ private static void GetLoanInfo()
{
foreach (var c in response.data)
{
- Console.WriteLine($"Currency: {c.currency}, interest: {c.interestRate}," +
+ AppLogger.Info($"Currency: {c.currency}, interest: {c.interestRate}," +
$" min: {c.maxLoanAmt}, max: {c.maxLoanAmt}, loanable: {c.loanableAmt}");
}
}
@@ -103,7 +103,7 @@ private static void GetLoanInfo()
}
case "error":
{
- Console.WriteLine($"Get loan info fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get loan info fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -124,12 +124,12 @@ private static void ApplyLoan()
{
case "ok":
{
- Console.WriteLine($"Apply successfully, margin order id: {response.data}");
+ AppLogger.Info($"Apply successfully, margin order id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Apply fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Apply fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -150,12 +150,12 @@ private static void RepayLoan()
{
case "ok":
{
- Console.WriteLine($"Repay successfully, margin order id: {response.data}");
+ AppLogger.Info($"Repay successfully, margin order id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Repay fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Repay fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -182,15 +182,15 @@ private static void GetLoanOrders()
{
foreach (var o in response.data)
{
- Console.WriteLine($"Loan order id: {o.id}, currency: {o.currency}, amount: {o.loanAmount}, state: {o.state}");
+ AppLogger.Info($"Loan order id: {o.id}, currency: {o.currency}, amount: {o.loanAmount}, state: {o.state}");
}
- Console.WriteLine($"There are total {response.data.Length} loan orders");
+ AppLogger.Info($"There are total {response.data.Length} loan orders");
}
break;
}
case "error":
{
- Console.WriteLine($"Get loan order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get loan order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -215,12 +215,12 @@ private static void GetMarginAccount()
{
foreach (var a in response.data)
{
- Console.WriteLine($"Account Id: {a.id}");
+ AppLogger.Info($"Account Id: {a.id}");
if (a.list != null)
{
foreach (var c in a.list)
{
- Console.WriteLine($"Currency: {c.currency}, balance: {c.balance}");
+ AppLogger.Info($"Currency: {c.currency}, balance: {c.balance}");
}
}
}
@@ -229,7 +229,7 @@ private static void GetMarginAccount()
}
case "error":
{
- Console.WriteLine($"Get margin account fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get margin account fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
diff --git a/Huobi.SDK.Example/ETFClientExample.cs b/Huobi.SDK.Example/ETFClientExample.cs
index 158e50e..7eb4e58 100644
--- a/Huobi.SDK.Example/ETFClientExample.cs
+++ b/Huobi.SDK.Example/ETFClientExample.cs
@@ -29,12 +29,12 @@ private static void GetETFInfo()
if (response != null && response.data != null)
{
- Console.WriteLine($"ETF name: {response.data.etfName}, purchase min amount: {response.data.purchaseMinAmount}");
+ AppLogger.Info($"ETF name: {response.data.etfName}, purchase min amount: {response.data.purchaseMinAmount}");
if (response.data.unitPrice != null)
{
foreach (var p in response.data.unitPrice)
{
- Console.WriteLine($"Currency: {p.currency}, amount: {p.amount}");
+ AppLogger.Info($"Currency: {p.currency}, amount: {p.amount}");
}
}
}
@@ -54,11 +54,11 @@ private static void SwapETFIn()
if (response.success)
{
- Console.WriteLine($"Swap in success: {message}");
+ AppLogger.Info($"Swap in success: {message}");
}
else
{
- Console.WriteLine($"Swap in fail: {message}");
+ AppLogger.Info($"Swap in fail: {message}");
}
}
}
@@ -77,11 +77,11 @@ private static void SwapETFOut()
if (response.success)
{
- Console.WriteLine($"Swap out success: {message}");
+ AppLogger.Info($"Swap out success: {message}");
}
else
{
- Console.WriteLine($"Swap out fail: {message}");
+ AppLogger.Info($"Swap out fail: {message}");
}
}
}
@@ -104,14 +104,14 @@ private static void GetETFSwapHistory()
{
foreach (var h in response.data)
{
- Console.WriteLine($"Currency: {h.currency}, amount {h.amount}");
+ AppLogger.Info($"Currency: {h.currency}, amount {h.amount}");
}
- Console.WriteLine($"There are total {response.data.Length} ETF swap history");
+ AppLogger.Info($"There are total {response.data.Length} ETF swap history");
}
}
else
{
- Console.WriteLine($"Get Swap history fail: {message}");
+ AppLogger.Info($"Get Swap history fail: {message}");
}
}
}
diff --git a/Huobi.SDK.Example/IsolatedMarginClientExample.cs b/Huobi.SDK.Example/IsolatedMarginClientExample.cs
index f1fbc40..98bf069 100644
--- a/Huobi.SDK.Example/IsolatedMarginClientExample.cs
+++ b/Huobi.SDK.Example/IsolatedMarginClientExample.cs
@@ -40,12 +40,12 @@ private static void TransferIn()
{
case "ok":
{
- Console.WriteLine($"Transfer successfully, transfer id: {response.data}");
+ AppLogger.Info($"Transfer successfully, transfer id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Transfer fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Transfer fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -66,12 +66,12 @@ private static void TransferOut()
{
case "ok":
{
- Console.WriteLine($"Transfer successfully, transfer id: {response.data}");
+ AppLogger.Info($"Transfer successfully, transfer id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Transfer fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Transfer fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -98,10 +98,10 @@ private static void GetLoanInfo()
{
if (d.currencies != null)
{
- Console.WriteLine($"Loan info for symbol: {d.symbol}");
+ AppLogger.Info($"Loan info for symbol: {d.symbol}");
foreach (var c in d.currencies)
{
- Console.WriteLine($"Currency: {c.currency}, interest: {c.interestRate}," +
+ AppLogger.Info($"Currency: {c.currency}, interest: {c.interestRate}," +
$" min: {c.maxLoanAmt}, max: {c.maxLoanAmt}, loanable: {c.loanableAmt}");
}
}
@@ -111,7 +111,7 @@ private static void GetLoanInfo()
}
case "error":
{
- Console.WriteLine($"Get loan info fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get loan info fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -132,12 +132,12 @@ private static void ApplyLoan()
{
case "ok":
{
- Console.WriteLine($"Apply successfully, margin order id: {response.data}");
+ AppLogger.Info($"Apply successfully, margin order id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Apply fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Apply fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -158,12 +158,12 @@ private static void Repay()
{
case "ok":
{
- Console.WriteLine($"Repay successfully, margin order id: {response.data}");
+ AppLogger.Info($"Repay successfully, margin order id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Repay fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Repay fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -191,15 +191,15 @@ private static void GetLoanOrders()
{
foreach (var o in response.data)
{
- Console.WriteLine($"Loan order id: {o.id}, symbol: {o.symbol}, currency: {o.currency}, amount: {o.loanAmount}, state: {o.state}");
+ AppLogger.Info($"Loan order id: {o.id}, symbol: {o.symbol}, currency: {o.currency}, amount: {o.loanAmount}, state: {o.state}");
}
- Console.WriteLine($"There are total {response.data.Length} loan orders");
+ AppLogger.Info($"There are total {response.data.Length} loan orders");
}
break;
}
case "error":
{
- Console.WriteLine($"Get loan order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get loan order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -224,22 +224,22 @@ private static void GetLoanAccount()
{
foreach (var a in response.data)
{
- Console.WriteLine($"Account Id: {a.id}, Symbol: {a.symbol}");
+ AppLogger.Info($"Account Id: {a.id}, Symbol: {a.symbol}");
if (a.list != null)
{
foreach (var c in a.list)
{
- Console.WriteLine($"Currency: {c.currency}, balance: {c.balance}");
+ AppLogger.Info($"Currency: {c.currency}, balance: {c.balance}");
}
}
}
- Console.WriteLine($"There are total {response.data.Length} margin accounts");
+ AppLogger.Info($"There are total {response.data.Length} margin accounts");
}
break;
}
case "error":
{
- Console.WriteLine($"Get margin account fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get margin account fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
diff --git a/Huobi.SDK.Example/MarketClientExample.cs b/Huobi.SDK.Example/MarketClientExample.cs
index 2fe6ce0..4c3159e 100644
--- a/Huobi.SDK.Example/MarketClientExample.cs
+++ b/Huobi.SDK.Example/MarketClientExample.cs
@@ -42,9 +42,9 @@ private static void GetCandlestick()
{
foreach (var c in result.data)
{
- Console.WriteLine($"local time: {Timestamp.SToLocal(c.id)}, count: {c.count}, amount: {c.amount}, volume: {c.vol}");
+ AppLogger.Info($"local time: {Timestamp.SToLocal(c.id)}, count: {c.count}, amount: {c.amount}, volume: {c.vol}");
}
- Console.WriteLine($"there are total {result.data.Length} candlesticks");
+ AppLogger.Info($"there are total {result.data.Length} candlesticks");
}
}
@@ -62,7 +62,7 @@ private static void GetLast24hCandlestickAskBid()
var ts = result.ts;
var t = result.tick;
- Console.WriteLine($"local time: {Timestamp.MSToLocal(ts)}, ask: [{t.ask[0]}, {t.ask[1]}], bid: [{t.bid[0]} {t.bid[1]}]");
+ AppLogger.Info($"local time: {Timestamp.MSToLocal(ts)}, ask: [{t.ask[0]}, {t.ask[1]}], bid: [{t.bid[0]} {t.bid[1]}]");
}
}
@@ -78,10 +78,10 @@ private static void GetAllSymbolsLast24hCandlesticksAskBid()
{
foreach (var t in result.data)
{
- Console.WriteLine($"symbol: {t.symbol}, count {t.count}, amount: {t.amount}, volume: {t.vol}" +
+ AppLogger.Info($"symbol: {t.symbol}, count {t.count}, amount: {t.amount}, volume: {t.vol}" +
$", bid: [{t.bid}, {t.bidSize}], ask: [{t.ask}, {t.askSize}]");
}
- Console.WriteLine($"There are total {result.data.Length} candlesticks");
+ AppLogger.Info($"There are total {result.data.Length} candlesticks");
}
}
@@ -105,16 +105,16 @@ private static void GetDepth()
{
for (int i = asks.Length - 1; i >= 0; i--)
{
- Console.WriteLine($"[{asks[i][0]}, {asks[i][1]}]");
+ AppLogger.Info($"[{asks[i][0]}, {asks[i][1]}]");
}
}
- Console.WriteLine($"----------");
+ AppLogger.Info($"----------");
var bids = result.tick.bids;
if (bids != null)
{
for (int i = 0; i < bids.Length; i++)
{
- Console.WriteLine($"[{bids[i][0]}, {bids[i][1]}]");
+ AppLogger.Info($"[{bids[i][0]}, {bids[i][1]}]");
}
}
}
@@ -135,10 +135,10 @@ private static void GetLastTrade()
{
foreach (var t in data)
{
- Console.WriteLine($"singapore time: {Timestamp.MSToLocal(t.ts)}," +
+ AppLogger.Info($"singapore time: {Timestamp.MSToLocal(t.ts)}," +
$" trade-id: {t.tradeId}, amount: {t.amount}, price: {t.price}, direction: {t.direction}");
}
- Console.WriteLine($"There are latest {data.Length} tradings");
+ AppLogger.Info($"There are latest {data.Length} tradings");
}
}
}
@@ -160,10 +160,10 @@ private static void GetLastTrades()
{
foreach (var t in d.data)
{
- Console.WriteLine($"singapore time: {Timestamp.MSToLocal(t.ts)}," +
+ AppLogger.Info($"singapore time: {Timestamp.MSToLocal(t.ts)}," +
$" trade-id: {t.tradeId}, amount: {t.amount}, price: {t.price}, direction: {t.direction}");
}
- Console.WriteLine($"There are latest {d.data.Length} tradings");
+ AppLogger.Info($"There are latest {d.data.Length} tradings");
}
}
}
@@ -181,7 +181,7 @@ private static void GetLast24Candlestick()
{
var ts = result.ts;
var t = result.tick;
- Console.WriteLine($"local time: {Timestamp.MSToLocal(ts)}, count: {t.count}, amount: {t.amount}, volume: {t.vol}");
+ AppLogger.Info($"local time: {Timestamp.MSToLocal(ts)}, count: {t.count}, amount: {t.amount}, volume: {t.vol}");
}
}
}
diff --git a/Huobi.SDK.Example/MarketWebSocketClientExample.cs b/Huobi.SDK.Example/MarketWebSocketClientExample.cs
index 9f33cb9..11bfa3f 100644
--- a/Huobi.SDK.Example/MarketWebSocketClientExample.cs
+++ b/Huobi.SDK.Example/MarketWebSocketClientExample.cs
@@ -1,5 +1,6 @@
using System;
using Huobi.SDK.Core.Client;
+using Huobi.SDK.Log;
using Huobi.SDK.Model.Response.Market;
namespace Huobi.SDK.Example
@@ -9,9 +10,9 @@ public class MarketWebSocketClientExample
public static void RunAll()
{
ReqAndSubscribeCandlestick();
-
+
ReqAndSubscribeDepth();
-
+
ReqAndSubscribeMBP();
SubscribeFullMBP();
@@ -34,8 +35,6 @@ void Client_OnConnectionOpen()
{
// Subscribe the specific topic
client.Subscribe("btcusdt", "1min");
-
- Console.WriteLine("Subscribed");
}
// Add the response receive handler
@@ -46,21 +45,21 @@ void Client_OnResponseReceived(SubscribeCandlestickResponse response)
{
if (response.tick != null) // Parse subscription data
{
- Console.WriteLine($"id: {response.tick.id}, count: {response.tick.count}, vol: {response.tick.vol}");
+ AppLogger.Info($"WebSocket received data, id={response.tick.id}, count={response.tick.count}, vol={response.tick.vol}");
}
else if (response.data != null) // Parse request data
{
+ AppLogger.Info($"WebSocket returned data, topic={response.ch}, count={response.data.Length}");
foreach (var t in response.data)
{
- Console.WriteLine($"id: {t.id}, count: {t.count}, vol: {t.vol}");
+ AppLogger.Info($"id={t.id}, count={t.count}, vol={t.vol}");
}
- Console.WriteLine($"There are total {response.data.Length} ticks");
}
}
}
// Then connect to server and wait for the handler to handle the response
- client.Connect();
+ client.Connect();
// Request full data
client.Req("btcusdt", "1min", 1569361140, 1569366420);
@@ -72,8 +71,7 @@ void Client_OnResponseReceived(SubscribeCandlestickResponse response)
client.UnSubscribe("btcusdt", "1min");
// Delete handler
- //client.OnResponseReceived -= Client_OnResponseReceived;
- client.Disconnect();
+ client.OnResponseReceived -= Client_OnResponseReceived;
}
private static void ReqAndSubscribeDepth()
@@ -86,8 +84,6 @@ void Client_OnConnectionOpen()
{
// Subscribe the specific topic
client.Subscribe("btcusdt", "step4");
-
- Console.WriteLine("Subscribed");
}
// Add the response receive handler
@@ -98,45 +94,47 @@ void Client_OnResponseReceived(SubscribeDepthResponse response)
{
if (response.tick != null) // Parse subscription data
{
+ AppLogger.Info($"WebSocket received data, topic={response.ch}");
if (response.tick.asks != null)
{
var asks = response.tick.asks;
- for (int i = asks.Length-1; i >= 0; i--)
+ AppLogger.Info($"ask, count={asks.Length}");
+ for (int i = asks.Length - 1; i >= 0; i--)
{
- Console.WriteLine($"[{asks[i][0]} {asks[i][1]}]");
+ AppLogger.Info($"[{asks[i][0]} {asks[i][1]}]");
}
}
- Console.WriteLine("------");
if (response.tick.bids != null)
{
var bids = response.tick.bids;
+ AppLogger.Info($"bids, count={bids.Length}");
for (int i = 0; i < bids.Length; i++)
{
- Console.WriteLine($"[{bids[i][0]} {bids[i][1]}]");
+ AppLogger.Info($"[{bids[i][0]} {bids[i][1]}]");
}
}
- Console.WriteLine();
}
else if (response.data != null) // Parse request data
{
+ AppLogger.Info($"WebSocket returned data, topic={response.ch}");
if (response.data.asks != null)
{
var asks = response.data.asks;
+ AppLogger.Info($"ask, count={asks.Length}");
for (int i = asks.Length - 1; i >= 0; i--)
{
- Console.WriteLine($"[{asks[i][0]} {asks[i][1]}]");
+ AppLogger.Info($"[{asks[i][0]} {asks[i][1]}]");
}
}
- Console.WriteLine("------");
if (response.data.bids != null)
{
var bids = response.data.bids;
+ AppLogger.Info($"bids, count={bids.Length}");
for (int i = 0; i < bids.Length; i++)
{
- Console.WriteLine($"[{bids[i][0]} {bids[i][1]}]");
+ AppLogger.Info($"[{bids[i][0]} {bids[i][1]}]");
}
}
- Console.WriteLine();
}
}
}
@@ -167,8 +165,6 @@ void Client_OnConnectionOpen()
{
// Subscribe the specific topic
client.Subscribe("btcusdt");
-
- Console.WriteLine("Subscribed");
}
// Add the response receive handler
@@ -179,47 +175,47 @@ void Client_OnResponseReceived(SubscribeMarketByPriceResponse response)
{
if (response.tick != null) // Parse subscription data
{
- Console.WriteLine($"Subscription prevSeqNum:{response.tick.prevSeqNum}, seqNum: {response.tick.seqNum}");
+ AppLogger.Info($"WebSocket received data, prevSeqNum={response.tick.prevSeqNum}, seqNum={response.tick.seqNum}");
if (response.tick.asks != null)
{
var asks = response.tick.asks;
+ AppLogger.Info($"ask, count={asks.Length}");
for (int i = asks.Length - 1; i >= 0; i--)
{
- Console.WriteLine($"[{asks[i][0]} {asks[i][1]}]");
+ AppLogger.Info($"[{asks[i][0]} {asks[i][1]}]");
}
}
- Console.WriteLine("------");
if (response.tick.bids != null)
{
var bids = response.tick.bids;
+ AppLogger.Info($"bids, count={bids.Length}");
for (int i = 0; i < bids.Length; i++)
{
- Console.WriteLine($"[{bids[i][0]} {bids[i][1]}]");
+ AppLogger.Info($"[{bids[i][0]} {bids[i][1]}]");
}
}
- Console.WriteLine();
}
else if (response.data != null) // Parse request data
{
- Console.WriteLine($"Request prevSeqNum:{response.data.prevSeqNum}, seqNum: {response.data.seqNum}");
+ Console.WriteLine($"WebSocket returned data, prevSeqNum={response.data.prevSeqNum}, seqNum={response.data.seqNum}");
if (response.data.asks != null)
{
var asks = response.data.asks;
+ AppLogger.Info($"ask, count={asks.Length}");
for (int i = asks.Length - 1; i >= 0; i--)
{
- Console.WriteLine($"[{asks[i][0]} {asks[i][1]}]");
+ AppLogger.Info($"[{asks[i][0]} {asks[i][1]}]");
}
}
- Console.WriteLine("------");
if (response.data.bids != null)
{
var bids = response.data.bids;
+ AppLogger.Info($"bids, count={bids.Length}");
for (int i = 0; i < bids.Length; i++)
{
- Console.WriteLine($"[{bids[i][0]} {bids[i][1]}]");
+ AppLogger.Info($"[{bids[i][0]} {bids[i][1]}]");
}
}
- Console.WriteLine();
}
}
}
@@ -250,8 +246,6 @@ void Client_OnConnectionOpen()
{
// Subscribe the specific topic
client.SubscribeFull("btcusdt", 20);
-
- Console.WriteLine("Subscribed");
}
// Add the response receive handler
@@ -262,25 +256,25 @@ void Client_OnResponseReceived(SubscribeMarketByPriceResponse response)
{
if (response.tick != null) // Parse subscription data
{
- Console.WriteLine($"Subscription seqNum: {response.tick.seqNum}");
+ AppLogger.Info($"WebSocket received data, seqNum={response.tick.seqNum}");
if (response.tick.asks != null)
{
var asks = response.tick.asks;
+ AppLogger.Info($"ask, count={asks.Length}");
for (int i = asks.Length - 1; i >= 0; i--)
{
- Console.WriteLine($"[{asks[i][0]} {asks[i][1]}]");
+ AppLogger.Info($"[{asks[i][0]} {asks[i][1]}]");
}
}
- Console.WriteLine("------");
if (response.tick.bids != null)
{
var bids = response.tick.bids;
+ AppLogger.Info($"bids, count={bids.Length}");
for (int i = 0; i < bids.Length; i++)
{
- Console.WriteLine($"[{bids[i][0]} {bids[i][1]}]");
+ AppLogger.Info($"[{bids[i][0]} {bids[i][1]}]");
}
}
- Console.WriteLine();
}
}
}
@@ -309,8 +303,6 @@ void Client_OnConnectionOpen()
{
// Subscribe the specific topic
client.Subscribe("btcusdt");
-
- Console.WriteLine("Subscribed");
}
// Add the response receive handler
@@ -322,7 +314,7 @@ void Client_OnResponseReceived(SubscribeBestBidOfferResponse response)
if (response.tick != null) // Parse subscription data
{
var t = response.tick;
- Console.WriteLine($"symbol: {t.symbol}, ask: [{t.ask}, {t.askSize}], bid: [{t.bid}, {t.bidSize}]");
+ AppLogger.Info($"WebSocket received data, symbol={t.symbol}, ask=[{t.ask}, {t.askSize}], bid=[{t.bid}, {t.bidSize}]");
}
}
}
@@ -351,8 +343,6 @@ void Client_OnConnectionOpen()
{
// Subscribe the specific topic
client.Subscribe("btcusdt");
-
- Console.WriteLine("Subscribed");
}
// Add the response receive handler
@@ -363,18 +353,19 @@ void Client_OnResponseReceived(SubscribeTradeResponse response)
{
if (response.tick != null && response.tick.data != null) // Parse subscription data
{
+ AppLogger.Info($"WebSocket returned data, count={response.tick.data.Length}");
foreach (var t in response.tick.data)
{
- Console.WriteLine($"tradeid: {t.tradeid}, direction: {t.direction}, [{t.price}, {t.amount}]");
+ AppLogger.Info($"tradeid: {t.tradeid}, direction: {t.direction}, [{t.price}, {t.amount}]");
}
}
else if (response.data != null) // Parse request data
{
+ AppLogger.Info($"WebSocket received data, count={response.data.Length}");
foreach (var t in response.data)
{
- Console.WriteLine($"tradeid: {t.tradeid}, direction: {t.direction}, [{t.price}, {t.amount}]");
+ AppLogger.Info($"tradeid: {t.tradeid}, direction: {t.direction}, [{t.price}, {t.amount}]");
}
- Console.WriteLine($"There are total {response.data.Length} trades");
}
}
}
@@ -384,7 +375,7 @@ void Client_OnResponseReceived(SubscribeTradeResponse response)
// Request full data
client.Req("btcusdt");
-
+
Console.WriteLine("Press ENTER to unsubscribe and stop...\n");
Console.ReadLine();
@@ -406,8 +397,6 @@ void Client_OnConnectionOpen()
{
// Subscribe the specific topic
client.Subscribe("btcusdt");
-
- Console.WriteLine("Subscribed");
}
// Add the response receive handler
@@ -418,11 +407,11 @@ void Client_OnResponseReceived(SubscribeLast24hCandlestickResponse response)
{
if (response.tick != null) // Parse subscription data
{
- Console.WriteLine($"id: {response.tick.id}, count: {response.tick.count}, vol: {response.tick.vol}");
+ AppLogger.Info($"WebSocket received data, id={response.tick.id}, count={response.tick.count}, vol={response.tick.vol}");
}
else if (response.data != null) // Parse request data
{
- Console.WriteLine($"id: {response.data.id}, count: {response.data.count}, vol: {response.data.vol}");
+ AppLogger.Info($"WebSocket returned data, id={response.data.id}, count={response.data.count}, vol={response.data.vol}");
}
}
}
diff --git a/Huobi.SDK.Example/OrderClientExample.cs b/Huobi.SDK.Example/OrderClientExample.cs
index 766150b..0406e2d 100644
--- a/Huobi.SDK.Example/OrderClientExample.cs
+++ b/Huobi.SDK.Example/OrderClientExample.cs
@@ -66,12 +66,12 @@ private static void PlaceOrder()
{
case "ok":
{
- Console.WriteLine($"Place order successfully, order id: {response.data}");
+ AppLogger.Info($"Place order successfully, order id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Place order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Place order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -105,11 +105,11 @@ private static void PlaceOrders()
{
if (r.orderId != 0)
{
- Console.WriteLine($"Place order successfully, order id: {r.orderId}");
+ AppLogger.Info($"Place order successfully, order id: {r.orderId}");
}
else
{
- Console.WriteLine($"Place order fail, error code: {r.errorCode}, error message: {r.errorMessage}");
+ AppLogger.Info($"Place order fail, error code: {r.errorCode}, error message: {r.errorMessage}");
}
}
}
@@ -117,7 +117,7 @@ private static void PlaceOrders()
}
case "error":
{
- Console.WriteLine($"Place multiple orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Place multiple orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -135,12 +135,12 @@ private static void CancelOrderById()
{
case "ok":
{
- Console.WriteLine($"Cancel order successfully, order id: {response.data}");
+ AppLogger.Info($"Cancel order successfully, order id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Cancel order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Cancel order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -158,12 +158,12 @@ private static void CancelOrderByClient()
{
case "ok":
{
- Console.WriteLine($"Cancel order successfully, order id: {response.data}");
+ AppLogger.Info($"Cancel order successfully, order id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Cancel order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Cancel order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -187,15 +187,15 @@ private static void GetOpenOrders()
{
foreach (var o in response.data)
{
- Console.WriteLine($"Order symbol: {o.symbol}, price: {o.price}, amount: {o.amount}");
+ AppLogger.Info($"Order symbol: {o.symbol}, price: {o.price}, amount: {o.amount}");
}
- Console.WriteLine($"There are total {response.data.Length} open orders");
+ AppLogger.Info($"There are total {response.data.Length} open orders");
}
break;
}
case "error":
{
- Console.WriteLine($"Query open orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Query open orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -220,13 +220,13 @@ private static void CancelOrdersByCriteria()
if (response.data != null)
{
var d = response.data;
- Console.WriteLine($"Cancel success: {d.successCount}, fail: {d.failedCount}, next: {d.nextId}");
+ AppLogger.Info($"Cancel success: {d.successCount}, fail: {d.failedCount}, next: {d.nextId}");
}
break;
}
case "error":
{
- Console.WriteLine($"Cancel orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Cancel orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -255,7 +255,7 @@ private static void CancelOrdersByIds()
{
foreach (string s in response.data.success)
{
- Console.WriteLine($"Cancel success: {s}");
+ AppLogger.Info($"Cancel success: {s}");
}
}
if (response.data.failed != null)
@@ -264,7 +264,7 @@ private static void CancelOrdersByIds()
{
string id = !string.IsNullOrWhiteSpace(f.orderId) ? f.orderId : f.clientOrderId;
- Console.WriteLine($"Cancel fail, id: {id}, error: {f.errorMessage}");
+ AppLogger.Info($"Cancel fail, id: {id}, error: {f.errorMessage}");
}
}
}
@@ -272,7 +272,7 @@ private static void CancelOrdersByIds()
}
case "error":
{
- Console.WriteLine($"Cancel orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Cancel orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -293,14 +293,14 @@ private static void GetOrderById()
if (response.data != null)
{
var o = response.data;
- Console.WriteLine($"Order symbol: {o.symbol}, price: {o.price}, amount: {o.amount}," +
+ AppLogger.Info($"Order symbol: {o.symbol}, price: {o.price}, amount: {o.amount}," +
$" filled amount: {o.filledAmount}, filled cash amount: {o.filledCashAmount}, filled fees: {o.filledFees}");
}
break;
}
case "error":
{
- Console.WriteLine($"Get order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -324,13 +324,13 @@ private static void GetOrderByClient()
if (response.data != null)
{
var o = response.data;
- Console.WriteLine($"Order symbol: {o.symbol}, price: {o.price}, amount: {o.amount}");
+ AppLogger.Info($"Order symbol: {o.symbol}, price: {o.price}, amount: {o.amount}");
}
break;
}
case "error":
{
- Console.WriteLine($"Get order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -352,15 +352,15 @@ private static void GetMatchResultsById()
{
foreach (var r in response.data)
{
- Console.WriteLine($"Match result symbol: {r.symbol}, amount: {r.filledAmount}, fee: {r.filledFees}");
+ AppLogger.Info($"Match result symbol: {r.symbol}, amount: {r.filledAmount}, fee: {r.filledFees}");
}
- Console.WriteLine($"There are total {response.data.Length} match results");
+ AppLogger.Info($"There are total {response.data.Length} match results");
}
break;
}
case "error":
{
- Console.WriteLine($"Get match result fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get match result fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -385,15 +385,15 @@ private static void GetHistoryOrders()
{
foreach (var o in response.data)
{
- Console.WriteLine($"Order symbol: {o.symbol}, amount: {o.amount}, state: {o.state}");
+ AppLogger.Info($"Order symbol: {o.symbol}, amount: {o.amount}, state: {o.state}");
}
- Console.WriteLine($"There are total {response.data.Length} history orders");
+ AppLogger.Info($"There are total {response.data.Length} history orders");
}
break;
}
case "error":
{
- Console.WriteLine($"Get history orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get history orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -417,15 +417,15 @@ private static void GetLast48hOrders()
{
foreach (var o in response.data)
{
- Console.WriteLine($"Order symbol: {o.symbol}, amount: {o.amount}, state: {o.state}");
+ AppLogger.Info($"Order symbol: {o.symbol}, amount: {o.amount}, state: {o.state}");
}
- Console.WriteLine($"There are total {response.data.Length} history orders");
+ AppLogger.Info($"There are total {response.data.Length} history orders");
}
break;
}
case "error":
{
- Console.WriteLine($"Get history orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get history orders fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -449,15 +449,15 @@ private static void GetMatchResults()
{
foreach (var r in response.data)
{
- Console.WriteLine($"Match result symbol: {r.symbol}, amount: {r.filledAmount}, fee: {r.filledFees}");
+ AppLogger.Info($"Match result symbol: {r.symbol}, amount: {r.filledAmount}, fee: {r.filledFees}");
}
- Console.WriteLine($"There are total {response.data.Length} match results");
+ AppLogger.Info($"There are total {response.data.Length} match results");
}
break;
}
case "error":
{
- Console.WriteLine($"Get mattch result fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get mattch result fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -479,13 +479,13 @@ private static void GetTransactFeeRate()
{
foreach (var f in response.data)
{
- Console.WriteLine($"Symbol: {f.symbol}, maker-taker fee: {f.makerFeeRate}-{f.takerFeeRate}");
+ AppLogger.Info($"Symbol: {f.symbol}, maker-taker fee: {f.makerFeeRate}-{f.takerFeeRate}");
}
}
}
else
{
- Console.WriteLine($"Get transact fee rate error: {response.message}");
+ AppLogger.Info($"Get transact fee rate error: {response.message}");
}
}
}
diff --git a/Huobi.SDK.Example/OrderWebSocketClientExample.cs b/Huobi.SDK.Example/OrderWebSocketClientExample.cs
index 1f186b4..f0d7655 100644
--- a/Huobi.SDK.Example/OrderWebSocketClientExample.cs
+++ b/Huobi.SDK.Example/OrderWebSocketClientExample.cs
@@ -2,9 +2,9 @@
using Huobi.SDK.Core.Client;
using Huobi.SDK.Model.Response.Order;
using Huobi.SDK.Model.Request;
-using Huobi.SDK.Model.Response.WebSocket;
using Huobi.SDK.Model.Response;
using Huobi.SDK.Model.Response.Auth;
+using Huobi.SDK.Log;
namespace Huobi.SDK.Example
{
@@ -42,7 +42,6 @@ void Client_OnAuthReceived(WebSocketV1AuthResponse response)
states = "submitted,created"
};
client.Request(req);
- Console.WriteLine("Request sent");
}
}
@@ -52,11 +51,11 @@ void Client_OnDataReceived(RequestOrdersResponse response)
{
if (response != null && response.data != null)
{
+ AppLogger.Info($"WebSocket returned data, topic={response.topic}, count={response.data.Length}");
foreach (var o in response.data)
{
- Console.WriteLine($"Order id {o.id}, symbol: {o.symbol}, price: {o.price}, state: {o.state}");
+ AppLogger.Info($"Order id {o.id}, symbol: {o.symbol}, price: {o.price}, state: {o.state}");
}
- Console.WriteLine($"There are total {response.data.Length} orders");
}
}
@@ -83,7 +82,6 @@ void Client_OnAuthReceived(WebSocketV1AuthResponse response)
{
// Request full data if authentication passed
client.Request("64318170222");
- Console.WriteLine("Request sent");
}
}
@@ -94,7 +92,7 @@ void Client_OnDataReceived(RequestOrderResponse response)
if (response != null && response.data != null)
{
var o = response.data;
- Console.WriteLine($"Order id {o.id}, symbol: {o.symbol}, price: {o.price}, filled amount: {o.filledAmount}");
+ AppLogger.Info($"WebSocket received data, topic={response.topic}, orderId={o.id}, symbol={o.symbol}, price={o.price}, filledAmount={o.filledAmount}");
}
}
@@ -121,7 +119,6 @@ void Client_OnAuthReceived(WebSocketV1AuthResponse response)
{
// Subscribe if authentication passed
client.Subscribe("btcusdt");
- Console.WriteLine("Subscription sent");
}
}
@@ -132,7 +129,7 @@ void Client_OnDataReceived(SubscribeOrderV1Response response)
if (response != null && response.data != null)
{
var o = response.data;
- Console.WriteLine($"order update, symbol: {o.symbol}, id: {o.orderId}, role: {o.role}, filled amount: {o.filledAmount}");
+ AppLogger.Info($"WebSocket received data, topic={response.topic}, symbol={o.symbol}, id={o.orderId}, role={o.role}, filledAmount={o.filledAmount}");
}
}
@@ -162,11 +159,10 @@ void Client_OnAuthReceived(WebSocketV2AuthResponse response)
{
// Subscribe if authentication passed
client.Subscribe("btcusdt");
- Console.WriteLine("Subscription sent");
}
else
{
- Console.WriteLine($"Authentication fail, code: {response.code}, message: {response.message}");
+ AppLogger.Error($"WebSocket authentication fail, code={response.code}, message={response.message}");
}
}
@@ -174,23 +170,23 @@ void Client_OnAuthReceived(WebSocketV2AuthResponse response)
client.OnDataReceived += Client_OnDataReceived;
void Client_OnDataReceived(SubscribeOrderV2Response response)
{
- if (response != null)
+ if (response != null)
{
if (response.action.Equals("sub"))
{
if (response.code == (int)ResponseCode.Success)
{
- Console.WriteLine($"Subscribe topic {response.ch} successfully");
+ AppLogger.Info($"WebSocket subscribe successfully, topic={response.ch} ");
}
else
{
- Console.WriteLine($"Subscribe topic {response.ch} fail, error code: {response.code}, error message: {response.message}");
+ AppLogger.Error($"WebSocket subscribed fail, topic={response.ch}, errorCode={response.code}, errorMessage={response.message}");
}
}
else if (response.action.Equals("push") && response.data != null)
{
var o = response.data;
- Console.WriteLine($"order update, event: {o.eventType}, symbol: {o.symbol}, type: {o.type}, status: {o.orderStatus}");
+ AppLogger.Info($"WebSocket received data, topic={response.ch}, event={o.eventType}, symbol={o.symbol}, type={o.type}, status={o.orderStatus}");
}
}
}
@@ -221,7 +217,10 @@ void Client_OnAuthReceived(WebSocketV2AuthResponse response)
{
// Subscribe if authentication passed
client.Subscribe("btcusdt");
- Console.WriteLine("Subscription sent");
+ }
+ else
+ {
+ AppLogger.Error($"WebSocket authentication fail, code={response.code}, message={response.message}");
}
}
@@ -235,17 +234,17 @@ void Client_OnDataReceived(SubscribeTradeClearResponse response)
{
if (response.code == (int)ResponseCode.Success)
{
- Console.WriteLine($"Subscribe topic {response.ch} successfully");
+ AppLogger.Info($"WebSocket subscribe successfully, topic={response.ch}");
}
else
{
- Console.WriteLine($"Subscribe topic {response.ch} fail, error code: {response.code}, error message: {response.message}");
+ AppLogger.Error($"WebSocket subscribe fail, topic={response.ch}, errorCode={response.code}, errorMessage={response.message}");
}
}
else if (response.action.Equals("push") && response.data != null)
{
var t = response.data;
- Console.WriteLine($"trade clear update, symbol: {t.symbol}, id: {t.orderId}, price: {t.tradePrice}, volume: {t.tradeVolume}");
+ AppLogger.Info($"WebSocket received data, topic={response.ch}, symbol={t.symbol}, id={t.orderId}, price={t.tradePrice}, volume={t.tradeVolume}");
}
}
}
diff --git a/Huobi.SDK.Example/Program.cs b/Huobi.SDK.Example/Program.cs
index 8100187..d850834 100644
--- a/Huobi.SDK.Example/Program.cs
+++ b/Huobi.SDK.Example/Program.cs
@@ -6,9 +6,13 @@ class Program
{
static void Main(string[] args)
{
+ AppLogger.Info("Example started");
+
Config.LoadConfig();
RullAllExamples();
+
+ AppLogger.Info("Example stopped");
}
static void RullAllExamples()
diff --git a/Huobi.SDK.Example/StableCoinClientExample.cs b/Huobi.SDK.Example/StableCoinClientExample.cs
index 9f917a1..2b2d907 100644
--- a/Huobi.SDK.Example/StableCoinClientExample.cs
+++ b/Huobi.SDK.Example/StableCoinClientExample.cs
@@ -29,12 +29,12 @@ private static void GetStableCoin()
{
case "ok":
{
- Console.WriteLine($"Get stable coin successfully");
+ AppLogger.Info($"Get stable coin successfully");
break;
}
case "error":
{
- Console.WriteLine($"Get stable coin fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Get stable coin fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
@@ -55,12 +55,12 @@ private static void ExchangeStableCoin()
{
case "ok":
{
- Console.WriteLine($"Exchange successfully");
+ AppLogger.Info($"Exchange successfully");
break;
}
case "error":
{
- Console.WriteLine($"Exchange fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Exchange fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
diff --git a/Huobi.SDK.Example/TraderExample.cs b/Huobi.SDK.Example/TraderExample.cs
index 9eda6a6..234a39f 100644
--- a/Huobi.SDK.Example/TraderExample.cs
+++ b/Huobi.SDK.Example/TraderExample.cs
@@ -4,7 +4,7 @@
using Huobi.SDK.Model.Response;
using Huobi.SDK.Model.Response.Auth;
using Huobi.SDK.Model.Response.Order;
-using Huobi.SDK.Model.Response.WebSocket;
+using Huobi.SDK.Log;
namespace Huobi.SDK.Example
{
@@ -41,11 +41,11 @@ void Client_OnAuthReceived(WebSocketV2AuthResponse response)
{
// Subscribe if authentication passed
client.Subscribe(symbol);
- Console.WriteLine($"Order update {symbol} subscription sent");
+ AppLogger.Info($"Order update {symbol} subscription sent");
}
else
{
- Console.WriteLine($"Authentication fail, code: {response.code}, message: {response.message}");
+ AppLogger.Info($"Authentication fail, code: {response.code}, message: {response.message}");
}
}
@@ -59,17 +59,17 @@ void Client_OnDataReceived(SubscribeOrderV2Response response)
{
if (response.code == (int)ResponseCode.Success)
{
- Console.WriteLine($"Subscribe topic {response.ch} successfully");
+ AppLogger.Info($"Subscribe topic {response.ch} successfully");
}
else
{
- Console.WriteLine($"Subscribe topic {response.ch} fail, error code: {response.code}, error message: {response.message}");
+ AppLogger.Info($"Subscribe topic {response.ch} fail, error code: {response.code}, error message: {response.message}");
}
}
else if (response.action.Equals("push") && response.data != null)
{
var o = response.data;
- Console.WriteLine($"order update, event: {o.eventType}, symbol: {o.symbol}, type: {o.type}, status: {o.orderStatus}");
+ AppLogger.Info($"order update, event: {o.eventType}, symbol: {o.symbol}, type: {o.type}, status: {o.orderStatus}");
}
}
}
@@ -106,12 +106,12 @@ private static void PlaceAnOrder(string symbol, string price, string amount)
{
case "ok":
{
- Console.WriteLine($"Place order successfully, order id: {response.data}");
+ AppLogger.Info($"Place order successfully, order id: {response.data}");
break;
}
case "error":
{
- Console.WriteLine($"Place order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
+ AppLogger.Info($"Place order fail, error code: {response.errorCode}, error message: {response.errorMessage}");
break;
}
}
diff --git a/Huobi.SDK.Example/WalletClientExample.cs b/Huobi.SDK.Example/WalletClientExample.cs
index b926175..62395a1 100644
--- a/Huobi.SDK.Example/WalletClientExample.cs
+++ b/Huobi.SDK.Example/WalletClientExample.cs
@@ -38,9 +38,9 @@ private static void GetDepoistAddress()
{
foreach (var a in result.data)
{
- Console.WriteLine($"currency: {a.currency}, addr: {a.address}, chain: {a.chain}");
+ AppLogger.Info($"currency: {a.currency}, addr: {a.address}, chain: {a.chain}");
}
- Console.WriteLine($"There are total {result.data.Length} addresses");
+ AppLogger.Info($"There are total {result.data.Length} addresses");
}
}
@@ -59,7 +59,7 @@ private static void GetWithdrawQuota()
{
foreach (var c in result.data.chains)
{
- Console.WriteLine($"chain: {c.chain}, max withdraw amount {c.maxWithdrawAmt}, total quota {c.withdrawQuotaTotal}");
+ AppLogger.Info($"chain: {c.chain}, max withdraw amount {c.maxWithdrawAmt}, total quota {c.withdrawQuotaTotal}");
}
}
}
@@ -82,12 +82,12 @@ private static void WithdrawCurrency()
{
case "ok":
{
- Console.WriteLine($"Withdraw successfully, transfer id: {result.data}");
+ AppLogger.Info($"Withdraw successfully, transfer id: {result.data}");
break;
}
case "error":
{
- Console.WriteLine($"Withdraw fail, error code: {result.errorCode}, error message: {result.errorMessage}");
+ AppLogger.Info($"Withdraw fail, error code: {result.errorCode}, error message: {result.errorMessage}");
break;
}
}
@@ -108,12 +108,12 @@ private static void CancelWithdrawCurrency()
{
case "ok":
{
- Console.WriteLine($"Cancel withdraw successfully, transfer id: {result.data}");
+ AppLogger.Info($"Cancel withdraw successfully, transfer id: {result.data}");
break;
}
case "error":
{
- Console.WriteLine($"Cancel withdraw fail, error code: {result.errorCode}, error message: {result.errorMessage}");
+ AppLogger.Info($"Cancel withdraw fail, error code: {result.errorCode}, error message: {result.errorMessage}");
break;
}
}
@@ -134,10 +134,10 @@ private static void GetDepositWithdrawHistory()
{
foreach (var h in result.data)
{
- Console.WriteLine($"type: {h.type}, currency: {h.currency}, amount: {h.amount}, updatedAt: {h.updatedAt}");
+ AppLogger.Info($"type: {h.type}, currency: {h.currency}, amount: {h.amount}, updatedAt: {h.updatedAt}");
}
- Console.WriteLine($"There are {result.data.Length} deposit and withdraw history");
+ AppLogger.Info($"There are {result.data.Length} deposit and withdraw history");
}
}
}
diff --git a/Huobi.SDK.Log/AppLogger.cs b/Huobi.SDK.Log/AppLogger.cs
new file mode 100644
index 0000000..af09b9b
--- /dev/null
+++ b/Huobi.SDK.Log/AppLogger.cs
@@ -0,0 +1,54 @@
+using System;
+using NLog;
+
+namespace Huobi.SDK.Log
+{
+ public class AppLogger
+ {
+ private static readonly ILogger _nLogger = LogManager.GetLogger("appLogger");
+
+ public static void Trace(string message)
+ {
+ _nLogger.Trace(message);
+ }
+
+ public static void Debug(string message)
+ {
+ _nLogger.Debug(message);
+ }
+
+ public static void Info(string message)
+ {
+ _nLogger.Info(message);
+ }
+
+ public static void Warn(string message)
+ {
+ _nLogger.Warn(message);
+ }
+
+ public static void Error(string message, Exception exception = null)
+ {
+ if (exception == null)
+ {
+ _nLogger.Error(message);
+ }
+ else
+ {
+ _nLogger.Error(exception, message);
+ }
+ }
+
+ public static void Fatal(string message, Exception exception = null)
+ {
+ if (exception == null)
+ {
+ _nLogger.Fatal(message);
+ }
+ else
+ {
+ _nLogger.Fatal(exception, message);
+ }
+ }
+ }
+}
diff --git a/Huobi.SDK.Log/Huobi.SDK.Log.csproj b/Huobi.SDK.Log/Huobi.SDK.Log.csproj
index 73a7715..388625c 100644
--- a/Huobi.SDK.Log/Huobi.SDK.Log.csproj
+++ b/Huobi.SDK.Log/Huobi.SDK.Log.csproj
@@ -6,6 +6,11 @@
-
+
+
+
+
+ PreserveNewest
+
diff --git a/Huobi.SDK.Log/LogContent.cs b/Huobi.SDK.Log/LogContent.cs
deleted file mode 100644
index 04794d3..0000000
--- a/Huobi.SDK.Log/LogContent.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace Huobi.SDK.Log
-{
- public struct LogContent
- {
- public int Id;
- public string Endpoint;
- public string Url;
- public long TotalDuration;
- public long NetworkDuration;
- public long SDKDuration;
- }
-}
diff --git a/Huobi.SDK.Log/PerformanceLogger.cs b/Huobi.SDK.Log/PerformanceLogger.cs
index 9c1faf9..f1cfa1a 100644
--- a/Huobi.SDK.Log/PerformanceLogger.cs
+++ b/Huobi.SDK.Log/PerformanceLogger.cs
@@ -1,9 +1,7 @@
using System;
using System.Diagnostics;
-using System.Text;
using NLog;
using NLog.Config;
-using NLog.LayoutRenderers;
using NLog.Targets;
namespace Huobi.SDK.Log
@@ -13,6 +11,16 @@ namespace Huobi.SDK.Log
///
public class PerformanceLogger
{
+ struct LogContent
+ {
+ public int Id;
+ public string Endpoint;
+ public string Url;
+ public long TotalDuration;
+ public long NetworkDuration;
+ public long SDKDuration;
+ }
+
private static PerformanceLogger _pLogger;
private bool _enable;
@@ -33,19 +41,8 @@ private PerformanceLogger()
// Stopwatch
_stopwatch = new Stopwatch();
- // NLog config
- var config = new LoggingConfiguration();
- var logfile = new FileTarget("logfile")
- {
- FileName = $"sdk-perf-{DateTime.Now.ToString("yyyyMMdd-HHmmss")}.txt",
- Layout = "${message}"
- };
-
- config.AddRule(LogLevel.Info, LogLevel.Info, logfile);
-
- LogManager.Configuration = config;
-
- _nLogger = LogManager.GetCurrentClassLogger();
+ // Performance logger
+ _nLogger = LogManager.GetLogger("perfLogger");
// Log content line count
_logContentLineCount = 1;
@@ -86,7 +83,6 @@ public void Start([System.Runtime.CompilerServices.CallerMemberName] string meth
_logContent.Endpoint = methodName;
}
-
}
public void RquestStart(string method, string url, bool stripUrlParams = true)
@@ -130,10 +126,10 @@ public void StopAndLog()
// Log header if it is the first record
if (_logContentLineCount == 1)
{
- _nLogger.Info($"Index, Endpoint, URL, Total Duration(ms), Request Duration(ms), SDK Duration(ms)");
+ _nLogger.Trace($"Index|Endpoint|URL|Total Duration(ms)|Request Duration(ms)|SDK Duration(ms)");
}
- _nLogger.Info($"{_logContent.Id}, {_logContent.Endpoint}, {_logContent.Url}, {totalDuration}, {requestDuration}, {totalDuration - requestDuration}");
+ _nLogger.Trace($"{_logContent.Id}|{_logContent.Endpoint}|{_logContent.Url}|{totalDuration}|{requestDuration}|{totalDuration - requestDuration}");
_logContentLineCount++;
}
diff --git a/Huobi.SDK.Log/nlog.config b/Huobi.SDK.Log/nlog.config
new file mode 100644
index 0000000..4940b76
--- /dev/null
+++ b/Huobi.SDK.Log/nlog.config
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Huobi.SDK.Model/Response/Account/SubscribeAccountV2Response.cs b/Huobi.SDK.Model/Response/Account/SubscribeAccountV2Response.cs
index b9c2573..3e9995a 100644
--- a/Huobi.SDK.Model/Response/Account/SubscribeAccountV2Response.cs
+++ b/Huobi.SDK.Model/Response/Account/SubscribeAccountV2Response.cs
@@ -23,12 +23,17 @@ public class AccountUpdate
/// The account id of this individual balance
///
public int accountId;
-
+
///
- /// The balance of this account, include frozen balance if "model" was set to 1 in subscription
+ /// The account balance (only exists when account balance changed)
///
public string balance;
+ ///
+ /// The available balance (only exists when available balance changed)
+ ///
+ public string available;
+
///
/// Change type
/// Possible values: [order-place,order-match,order-refund,order-cancel,order-fee-refund,
diff --git a/README.md b/README.md
index f9da3a2..df7978a 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,7 @@ The SDK supports both synchronous and asynchronous RESTful API invoking, and sub
- [Folder structure](#Folder-Structure)
- [Client](#Client)
- [Response](#Response)
+ - [Logging](#Logging)
- [Request examples](#Request-examples)
@@ -95,6 +96,7 @@ This is the folder and namespace structure of SDK source code and the descriptio
- **Huobi.SDK.Model**: The data model that user need to care about
- **Request**: The request data model
- **Response**: The response data model
+- **Huobi.SDK.Log**: The logging functionality for application log and performance log, it uses the NLog library with the configuration file *nlog.config*
- **Huobi.SDK.Core.Test**: The unit test of core
- **Huobi.SDK.Example**: The examples how to use **Core** and **Model** to access API and read response.
@@ -218,6 +220,15 @@ if (symbolsResponse != null && symbolsResponse.status != null && symbolsResponse
}
```
+### Logging
+
+This SDK uses **NLog** and the configuration file is *nlog.config*. For basic user, you can update the configuration file to update the logging level and log file name. For advanced user, you can refer to NLog official document to implement more features.
+
+By default there are two loggers:
+
+- **appLogger**: This is the logger for general functional purpose, the target is to *consoleTarget* and *fileTarget*. The related logging class is *Huobi.SDK.Log.AppLogger*
+- **perfLogger**: This is for internal use to measure the SDK performance, the target is to *perfFileTarget*. It is disabled by default. The related logging class is *Huobi.SDK.Log.PerformanceLogger*
+
## Request Examples
### Common data