1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-10-04 02:11:11 +00:00

Updated remaining quantity/volumes to SharedOrderQuantity model in Shared APIs, added QuantityType to SharedOrderBook, added auto calculated quote quantity where for SharedOrderQuantity where it makes sense

This commit is contained in:
Jkorf
2026-08-21 09:51:17 +02:00
parent 79e2efec70
commit e7eb559074
7 changed files with 68 additions and 21 deletions
@@ -1,4 +1,5 @@
using System.Diagnostics; using System;
using System.Diagnostics;
namespace CryptoExchange.Net.SharedApis namespace CryptoExchange.Net.SharedApis
{ {
@@ -15,26 +16,44 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// Quantity of the best ask /// Quantity of the best ask
/// </summary> /// </summary>
public decimal BestAskQuantity { get; set; } [Obsolete("Use `BestAskQuantities` instead")]
public decimal BestAskQuantity => BestAskQuantities.QuantityInBaseAsset ?? BestAskQuantities.QuantityInContracts ?? 0;
/// <summary>
/// Quantities of the best ask
/// </summary>
public SharedOrderQuantity BestAskQuantities { get; set; }
/// <summary> /// <summary>
/// Price of the best bid /// Price of the best bid
/// </summary> /// </summary>
public decimal BestBidPrice { get; set; } public decimal BestBidPrice { get; set; }
/// <summary> /// <summary>
/// Quantity of the best bid /// Quantity of the best bid
/// </summary> /// </summary>
public decimal BestBidQuantity { get; set; } [Obsolete("Use `BestBidQuantities` instead")]
public decimal BestBidQuantity => BestBidQuantities.QuantityInBaseAsset ?? BestBidQuantities.QuantityInContracts ?? 0;
/// <summary>
/// Quantities of the best bid
/// </summary>
public SharedOrderQuantity BestBidQuantities { get; set; }
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public SharedBookTicker(SharedSymbol? sharedSymbol, string symbol, decimal bestAskPrice, decimal bestAskQuantity, decimal bestBidPrice, decimal bestBidQuantity) public SharedBookTicker(
SharedSymbol? sharedSymbol,
string symbol,
decimal bestAskPrice,
SharedOrderQuantity bestAskQuantity,
decimal bestBidPrice,
SharedOrderQuantity bestBidQuantity)
: base(sharedSymbol, symbol) : base(sharedSymbol, symbol)
{ {
BestAskPrice = bestAskPrice; BestAskPrice = bestAskPrice;
BestAskQuantity = bestAskQuantity; BestAskQuantities = bestAskQuantity.WithCalculatedQuantities(bestAskPrice, null);
BestBidPrice = bestBidPrice; BestBidPrice = bestBidPrice;
BestBidQuantity = bestBidQuantity; BestBidQuantities = bestBidQuantity.WithCalculatedQuantities(bestBidPrice, null);
} }
} }
} }
@@ -1,4 +1,6 @@
namespace CryptoExchange.Net.SharedApis using System;
namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Open interest /// Open interest
@@ -8,14 +10,19 @@
/// <summary> /// <summary>
/// Current open interest /// Current open interest
/// </summary> /// </summary>
public decimal OpenInterest { get; set; } [Obsolete("Use `OpenInterests` instead")]
public decimal OpenInterest => OpenInterests.QuantityInBaseAsset ?? OpenInterests.QuantityInContracts ?? 0;
/// <summary>
/// Current open interest
/// </summary>
public SharedOrderQuantity OpenInterests { get; set; }
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public SharedOpenInterest(decimal openInterest) public SharedOpenInterest(SharedOrderQuantity openInterest)
{ {
OpenInterest = openInterest; OpenInterests = openInterest;
} }
} }
} }
@@ -7,6 +7,10 @@ namespace CryptoExchange.Net.SharedApis
/// </summary> /// </summary>
public record SharedOrderBook public record SharedOrderBook
{ {
/// <summary>
/// The quantity notation the order book is in, either BaseAsset or Contract
/// </summary>
public SharedQuantityType QuantityType { get; set; }
/// <summary> /// <summary>
/// Asks list /// Asks list
/// </summary> /// </summary>
@@ -19,8 +23,9 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public SharedOrderBook(ISymbolOrderBookEntry[] asks, ISymbolOrderBookEntry[] bids) public SharedOrderBook(SharedQuantityType quantityType, ISymbolOrderBookEntry[] asks, ISymbolOrderBookEntry[] bids)
{ {
QuantityType = quantityType;
Asks = asks; Asks = asks;
Bids = bids; Bids = bids;
} }
@@ -16,7 +16,12 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// Current size of the position /// Current size of the position
/// </summary> /// </summary>
public decimal PositionSize { get; set; } [Obsolete("Use `PositionSizes` instead")]
public decimal PositionSize => PositionSizes.QuantityInContracts ?? PositionSizes.QuantityInBaseAsset ?? 0;
/// <summary>
/// Current size of the position
/// </summary>
public SharedOrderQuantity PositionSizes { get; set; }
/// <summary> /// <summary>
/// Side of the position /// Side of the position
/// </summary> /// </summary>
@@ -57,10 +62,10 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public SharedPosition(SharedSymbol? sharedSymbol, string symbol, decimal positionSize, DateTime? updateTime) public SharedPosition(SharedSymbol? sharedSymbol, string symbol, SharedOrderQuantity positionSize, DateTime? updateTime)
: base(sharedSymbol, symbol) : base(sharedSymbol, symbol)
{ {
PositionSize = positionSize; PositionSizes = positionSize;
UpdateTime = updateTime; UpdateTime = updateTime;
} }
} }
@@ -24,7 +24,12 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// Position size /// Position size
/// </summary> /// </summary>
public decimal Quantity { get; set; } [Obsolete("Use `Quantities` instead")]
public decimal Quantity => Quantities.QuantityInContracts ?? Quantities .QuantityInBaseAsset ?? 0;
/// <summary>
/// Position size
/// </summary>
public SharedOrderQuantity Quantities { get; set; }
/// <summary> /// <summary>
/// Realized profit/loss /// Realized profit/loss
/// </summary> /// </summary>
@@ -55,7 +60,7 @@ namespace CryptoExchange.Net.SharedApis
SharedPositionSide side, SharedPositionSide side,
decimal openPrice, decimal openPrice,
decimal closePrice, decimal closePrice,
decimal quantity, SharedOrderQuantity quantity,
decimal realizedPnl, decimal realizedPnl,
DateTime timestamp) DateTime timestamp)
: base(sharedSymbol, symbol) : base(sharedSymbol, symbol)
@@ -63,7 +68,7 @@ namespace CryptoExchange.Net.SharedApis
PositionSide = side; PositionSide = side;
AverageOpenPrice = openPrice; AverageOpenPrice = openPrice;
AverageClosePrice = closePrice; AverageClosePrice = closePrice;
Quantity = quantity; Quantities = quantity;
RealizedPnl = realizedPnl; RealizedPnl = realizedPnl;
Timestamp = timestamp; Timestamp = timestamp;
} }
@@ -36,7 +36,7 @@ namespace CryptoExchange.Net.SharedApis
/// </summary> /// </summary>
public SharedTrade(SharedSymbol? sharedSymbol, string symbol, SharedOrderQuantity quantities, decimal price, DateTime timestamp) : base(sharedSymbol, symbol) public SharedTrade(SharedSymbol? sharedSymbol, string symbol, SharedOrderQuantity quantities, decimal price, DateTime timestamp) : base(sharedSymbol, symbol)
{ {
Quantities = quantities; Quantities = quantities.WithCalculatedQuantities(price, null);
Price = price; Price = price;
Timestamp = timestamp; Timestamp = timestamp;
} }
@@ -16,7 +16,13 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// Traded quantity /// Traded quantity
/// </summary> /// </summary>
public decimal Quantity { get; set; } [Obsolete("Use `Quantities` instead")]
public decimal Quantity => Quantities.QuantityInBaseAsset ?? Quantities.QuantityInQuoteAsset ?? 0;
/// <summary>
/// Traded quantity
/// </summary>
public SharedOrderQuantity Quantities { get; set; }
/// <summary> /// <summary>
/// Trade price /// Trade price
/// </summary> /// </summary>
@@ -53,14 +59,14 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public SharedUserTrade(SharedSymbol? sharedSymbol, string symbol, string orderId, string id, SharedOrderSide? side, decimal quantity, decimal price, DateTime timestamp) public SharedUserTrade(SharedSymbol? sharedSymbol, string symbol, string orderId, string id, SharedOrderSide? side, SharedOrderQuantity quantity, decimal price, DateTime timestamp)
: base(sharedSymbol, symbol) : base(sharedSymbol, symbol)
{ {
Symbol = symbol; Symbol = symbol;
OrderId = orderId; OrderId = orderId;
Id = id; Id = id;
Side = side; Side = side;
Quantity = quantity; Quantities = quantity.WithCalculatedQuantities(price, null);
Price = price; Price = price;
Timestamp = timestamp; Timestamp = timestamp;
} }