-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
210 additions
and
300 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
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 |
---|---|---|
@@ -1,76 +1,76 @@ | ||
using CryptoExchange.Net.Authentication; | ||
using CryptoExchange.Net.Logging; | ||
using CryptoExchange.Net.Objects; | ||
using Microsoft.Extensions.Logging; | ||
using CryptoExchange.Net.Objects.Options; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
|
||
namespace Bitmex.Net.Client | ||
{ | ||
public class BitmexClientOptions : ClientOptions | ||
public class BitmexRestOptions : RestExchangeOptions | ||
{ | ||
|
||
private const string ProductionEndpoint = "https://www.bitmex.com/api/v1"; | ||
private const string TestNetEndpoint = "https://testnet.bitmex.com/api/v1"; | ||
|
||
public BitmexClientOptions(HttpClient client, string key, string secret, bool isTest = false, bool outputOriginalData = false) : this(new ApiCredentials(key, secret), isTest, outputOriginalData) | ||
readonly bool isTestnet = false; | ||
public BitmexRestOptions(string key, string secret, bool isTest = false, bool outputOriginalData = false) : this(new ApiCredentials(key, secret), isTest, outputOriginalData) | ||
{ | ||
CommonApiOptions.HttpClient = client; | ||
} | ||
public BitmexClientOptions(HttpClient client) : this(false) | ||
public BitmexRestOptions() : this(null) | ||
{ | ||
CommonApiOptions.HttpClient = client; | ||
} | ||
public BitmexClientOptions(string key, string secret, bool isTest = false, bool outputOriginalData = false) : this(new ApiCredentials(key, secret), isTest, outputOriginalData) | ||
public BitmexRestOptions(bool isTest) : this(null, isTest) | ||
{ | ||
} | ||
|
||
public BitmexClientOptions(bool isTest = false, bool outputOriginalData = false) : base() | ||
private BitmexRestOptions(bool isTest, bool outputOriginalData) : base() | ||
{ | ||
CommonApiOptions = new(isTest ? TestNetEndpoint : ProductionEndpoint) { OutputOriginalData = outputOriginalData }; | ||
LogLevel = Microsoft.Extensions.Logging.LogLevel.Debug; | ||
isTestnet = isTest; | ||
CommonApiOptions = new() { OutputOriginalData = outputOriginalData }; | ||
} | ||
|
||
public BitmexClientOptions(ApiCredentials apiCredentials, bool isTest, bool outputOriginalData = false) : this(isTest, outputOriginalData) | ||
public BitmexRestOptions(ApiCredentials apiCredentials, bool isTest = false, bool outputOriginalData = false, RateLimitingBehaviour rateLimitingBehaviour = RateLimitingBehaviour.Wait) | ||
: this(isTest, outputOriginalData) | ||
{ | ||
ApiCredentials = apiCredentials; | ||
CommonApiOptions.RateLimiters.Add( | ||
new RateLimiter().AddTotalRateLimit( | ||
ApiCredentials is null ? 30 : 120, | ||
TimeSpan.FromMinutes(1)) | ||
); | ||
CommonApiOptions.RateLimiters.Add( | ||
new RateLimiter().AddEndpointLimit( | ||
BitmexMarginClient.GetEndPointsWithAdditionalRateLimiter(CommonApiOptions.BaseAddress), | ||
10, | ||
TimeSpan.FromSeconds(1)) | ||
); | ||
CommonApiOptions.RateLimitingBehaviour = RateLimitingBehaviour.Wait; | ||
} | ||
|
||
// for cloning this instance only | ||
private BitmexClientOptions(BitmexClientOptions baseOn) : base(baseOn) | ||
{ | ||
CommonApiOptions = baseOn.CommonApiOptions; | ||
UpdateRateLimiters(); | ||
CommonApiOptions.RateLimitingBehaviour = rateLimitingBehaviour; | ||
} | ||
|
||
/// <summary> | ||
/// <summary> | ||
/// Default options | ||
/// </summary> | ||
public static BitmexClientOptions Default { get; set; } = new BitmexClientOptions() | ||
public static BitmexRestOptions Default { get; set; } = new BitmexRestOptions() | ||
{ | ||
}; | ||
|
||
internal RestApiClientOptions CommonApiOptions { get; set; } | ||
|
||
internal RestApiOptions CommonApiOptions { get; set; } | ||
internal string BaseAddress => isTestnet ? TestNetEndpoint : ProductionEndpoint; | ||
public void SetApiCredentials(ApiCredentials credentials) | ||
{ | ||
ApiCredentials = credentials; | ||
UpdateRateLimiters(); | ||
} | ||
public BitmexRestOptions Copy() | ||
{ | ||
var newOne = Copy<BitmexRestOptions>(); | ||
newOne.CommonApiOptions = CommonApiOptions; | ||
return newOne; | ||
} | ||
public BitmexClientOptions Copy() | ||
|
||
private void UpdateRateLimiters() | ||
{ | ||
return new BitmexClientOptions(this); | ||
CommonApiOptions.RateLimiters.Clear(); | ||
CommonApiOptions.RateLimiters.Add( | ||
new RateLimiter().AddTotalRateLimit( | ||
ApiCredentials is null ? 30 : 120, | ||
TimeSpan.FromMinutes(1)) | ||
); | ||
CommonApiOptions.RateLimiters.Add( | ||
new RateLimiter().AddEndpointLimit( | ||
BitmexMarginClient.GetEndPointsWithAdditionalRateLimiter(BaseAddress), | ||
10, | ||
TimeSpan.FromSeconds(1)) | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.