Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Bitfinex.Client.Websocket.Client
/// </summary>
public class BitfinexWebsocketClient : IDisposable
{
private readonly ILogger<BitfinexWebsocketClient> _logger;
private readonly ILogger _logger;
private readonly IBitfinexCommunicator _communicator;
private readonly IDisposable _messageReceivedSubscription;
private readonly IDisposable _configurationSubscription;
Expand All @@ -32,7 +32,7 @@ public class BitfinexWebsocketClient : IDisposable
private readonly BitfinexPublicHandler _publicHandler;

/// <inheritdoc />
public BitfinexWebsocketClient(IBitfinexCommunicator communicator, ILogger<BitfinexWebsocketClient>? logger = null)
public BitfinexWebsocketClient(IBitfinexCommunicator communicator, ILogger? logger = null)
{
BfxValidations.ValidateInput(communicator, nameof(communicator));

Expand All @@ -58,7 +58,7 @@ public BitfinexWebsocketClient(IBitfinexCommunicator communicator, ILogger<Bitfi
/// <summary>
/// Expose logger for this client
/// </summary>
public ILogger<BitfinexWebsocketClient> Logger => _logger;
public ILogger Logger => _logger;

/// <summary>
/// Cleanup everything
Expand Down
191 changes: 99 additions & 92 deletions src/Bitfinex.Client.Websocket/Responses/TradesPrivate/PrivateTrade.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Reactive.Subjects;
using Bitfinex.Client.Websocket.Json;
using Bitfinex.Client.Websocket.Responses.Configurations;
using Bitfinex.Client.Websocket.Responses.Orders;
using Bitfinex.Client.Websocket.Responses.Trades;
Expand All @@ -9,95 +10,101 @@

namespace Bitfinex.Client.Websocket.Responses.TradesPrivate
{
/// <summary>
/// The order that causes the trade determines if it is a buy or a sell.
/// </summary>
[JsonConverter(typeof(PrivateTradeConverter))]
public class PrivateTrade : ResponseBase
{
/// <summary>
/// Trade id
/// </summary>
public long Id { get; set; }

/// <summary>
/// Symbol (tBTCUSD, etc)
/// </summary>
public string Symbol { get; set; }

/// <summary>
/// Execution timestamp
/// </summary>
public DateTime MtsCreate { get; set; }

/// <summary>
/// Order id
/// </summary>
public long OrderId { get; set; }

/// <summary>
/// How much was bought (positive) or sold (negative).
/// </summary>
public double ExecAmount { get; set; }

/// <summary>
/// Price at which the trade was executed
/// </summary>
public double ExecPrice { get; set; }

/// <summary>
/// Origin order type
/// </summary>
public OrderType OrderType { get; set; }

/// <summary>
/// Origin order target price
/// </summary>
public double OrderPrice { get; set; }

/// <summary>
/// True if maker order (post-only)
/// </summary>
public bool IsMaker { get; set; }

/// <summary>
/// Taken fee
/// </summary>
public double? Fee { get; set; }

/// <summary>
/// Taken fee currency
/// </summary>
public string FeeCurrency { get; set; }

/// <summary>
/// Type of the trade
/// </summary>
[JsonIgnore]
public TradeType Type { get; set; }

/// <summary>
/// Target pair
/// </summary>
[JsonIgnore]
public string Pair => BitfinexSymbolUtils.ExtractPair(Symbol);


internal static void Handle(JToken token, ConfigurationState config, Subject<PrivateTrade> subject, TradeType type)
{
var data = token[2];
if (data?.Type != JTokenType.Array)
{
return;
}

var trade = data.ToObject<PrivateTrade>();
if (trade != null)
{
trade.Type = type;
SetGlobalData(trade, config, token, 2, true);
subject.OnNext(trade);
}
}
}
}
/// <summary>
/// The order that causes the trade determines if it is a buy or a sell.
/// </summary>
[JsonConverter(typeof(PrivateTradeConverter))]
public class PrivateTrade : ResponseBase
{
/// <summary>
/// Trade id
/// </summary>
public long Id { get; set; }

/// <summary>
/// Client Order ID
/// </summary>
public long? Cid { get; set; }

/// <summary>
/// Symbol (tBTCUSD, etc)
/// </summary>
public string Symbol { get; set; }

/// <summary>
/// Execution timestamp
/// </summary>
[JsonConverter(typeof(UnixDateTimeConverter))]
public DateTime MtsCreate { get; set; }

/// <summary>
/// Order id
/// </summary>
public long OrderId { get; set; }

/// <summary>
/// How much was bought (positive) or sold (negative).
/// </summary>
public double ExecAmount { get; set; }

/// <summary>
/// Price at which the trade was executed
/// </summary>
public double ExecPrice { get; set; }

/// <summary>
/// Origin order type
/// </summary>
public OrderType OrderType { get; set; }

/// <summary>
/// Origin order target price
/// </summary>
public double OrderPrice { get; set; }

/// <summary>
/// True if maker order (post-only)
/// </summary>
public bool IsMaker { get; set; }

/// <summary>
/// Taken fee
/// </summary>
public double? Fee { get; set; }

/// <summary>
/// Taken fee currency
/// </summary>
public string FeeCurrency { get; set; }

/// <summary>
/// Type of the trade
/// </summary>
[JsonIgnore]
public TradeType Type { get; set; }

/// <summary>
/// Target pair
/// </summary>
[JsonIgnore]
public string Pair => BitfinexSymbolUtils.ExtractPair(Symbol);


internal static void Handle(JToken token, ConfigurationState config, Subject<PrivateTrade> subject, TradeType type)
{
var data = token[2];
if (data?.Type != JTokenType.Array)
{
return;
}

var trade = data.ToObject<PrivateTrade>();
if (trade != null)
{
trade.Type = type;
SetGlobalData(trade, config, token, 2, true);
subject.OnNext(trade);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,43 @@
namespace Bitfinex.Client.Websocket.Responses.TradesPrivate
{
internal class PrivateTradeConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(PrivateTrade);
}
return objectType == typeof(PrivateTrade);
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
JsonSerializer serializer)
{
var array = JArray.Load(reader);
return JArrayToTradingTicker(array);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
JsonSerializer serializer)
{
var array = JArray.Load(reader);
return JArrayToTradingTicker(array);
}

public override bool CanWrite => false;
public override bool CanWrite => false;

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}

private PrivateTrade JArrayToTradingTicker(JArray array)
{
return new PrivateTrade
{
return new PrivateTrade
{
Id = (long)array[0],
Symbol = (string)array[1],
MtsCreate = BitfinexTime.ConvertToTime((long)array[2]),
OrderId = (long)array[3],
ExecAmount = (double)array[4],
ExecPrice = (double)array[5],
OrderType = OrderConverter.ParseType((string)array[6]),
OrderPrice = (double)array[7],
IsMaker = (int)array[8] > 0,
Fee = (double?)array[9],
FeeCurrency = (string)array[10]
};
}
Id = (long)array[0],
Symbol = (string)array[1],
MtsCreate = BitfinexTime.ConvertToTime((long)array[2]),
OrderId = (long)array[3],
ExecAmount = (double)array[4],
ExecPrice = (double)array[5],
OrderType = OrderConverter.ParseType((string)array[6]),
OrderPrice = (double)array[7],
IsMaker = (int)array[8] > 0,
Fee = (double?)array[9],
FeeCurrency = (string)array[10],
Cid = (long?)array[11]
};
}
}
}
Loading