-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update symbol price validation for new "PERCENT_PRICE" filter
For #111. Extend InclusiveRange (w/ PriceRange class) to transparently get symbol average price to calculate minimum and maximum price limits.
- Loading branch information
Showing
5 changed files
with
134 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
|
||
namespace Binance | ||
{ | ||
public sealed class PriceRange : InclusiveRange | ||
{ | ||
#region Public Properties | ||
|
||
public decimal MultiplierUp { get; } | ||
|
||
public decimal MultiplierDown { get; } | ||
|
||
public override decimal Minimum => Math.Floor(GetAveragePrice() * MultiplierDown / Increment) * Increment; | ||
|
||
public override decimal Maximum => Math.Ceiling(GetAveragePrice() * MultiplierUp / Increment) * Increment; | ||
|
||
#endregion Public Properties | ||
|
||
#region Private Fields | ||
|
||
private IBinanceApi _api; | ||
|
||
private string _symbol; | ||
|
||
private decimal _averagePrice; | ||
|
||
private DateTime _lastUpdate = DateTime.MinValue; | ||
|
||
#endregion Private Fields | ||
|
||
#region Constructor | ||
|
||
public PriceRange(IBinanceApi api, string symbol, decimal multiplierUp, decimal multiplierDown, decimal increment) | ||
: base(0, 0, increment) | ||
{ | ||
Throw.IfNull(api, nameof(api)); | ||
Throw.IfNullOrWhiteSpace(symbol, nameof(symbol)); | ||
|
||
_api = api; | ||
_symbol = symbol; | ||
|
||
MultiplierUp = multiplierUp; | ||
MultiplierDown = multiplierDown; | ||
} | ||
|
||
#endregion Constructor | ||
|
||
#region Private Methods | ||
|
||
private decimal GetAveragePrice() | ||
{ | ||
if (_averagePrice == 0 || DateTime.UtcNow - _lastUpdate > TimeSpan.FromSeconds(1)) | ||
{ | ||
_averagePrice = _api.GetAvgPriceAsync(_symbol).GetAwaiter().GetResult().Value; | ||
_lastUpdate = DateTime.UtcNow; | ||
} | ||
|
||
return _averagePrice; | ||
} | ||
|
||
#endregion Private Methods | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters