diff --git a/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApi.cs b/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApi.cs index 8f76110..cd6bf74 100644 --- a/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApi.cs +++ b/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApi.cs @@ -11,6 +11,8 @@ internal class OKXRestClientUnifiedApi : RestApiClient, IOKXRestClientUnifiedApi #region Internal Fields private static TimeSyncState _timeSyncState = new("Unified Api"); + internal readonly string _ref = "078ee129065aBCDE"; + public event Action? OnOrderPlaced; public event Action? OnOrderCanceled; #endregion @@ -32,6 +34,8 @@ internal OKXRestClientUnifiedApi(ILogger logger, HttpClient? httpClient, OKXRest Trading = new OKXRestClientUnifiedApiTrading(this); SubAccounts = new OKXRestClientUnifiedApiSubAccounts(this); + _ref = !string.IsNullOrEmpty(options.BrokerId) ? options.BrokerId : "078ee129065aBCDE"; + if (options.Environment.EnvironmentName == TradeEnvironmentNames.Testnet) { StandardRequestHeaders = new Dictionary diff --git a/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiTrading.cs b/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiTrading.cs index e176ec4..4f0f30a 100644 --- a/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiTrading.cs +++ b/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiTrading.cs @@ -7,7 +7,6 @@ namespace OKX.Net.Clients.UnifiedApi; internal class OKXRestClientUnifiedApiTrading : IOKXRestClientUnifiedApiTrading { - private const string _ref = "078ee129065aBCDE"; private const string _bodyParameterKey = ""; private static Random _random = new Random(); @@ -70,8 +69,8 @@ public virtual async Task> PlaceOrderAsync( {"side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, {"ordType", JsonConvert.SerializeObject(type, new OrderTypeConverter(false)) }, {"sz", quantity.ToString(CultureInfo.InvariantCulture) }, - {"tag", _ref }, - {"clOrdId", _ref + (clientOrderId ?? RandomString(15)) }, + {"tag", _baseClient._ref }, + {"clOrdId", _baseClient._ref + (clientOrderId ?? RandomString(15)) }, }; parameters.AddOptionalParameter("px", price?.ToString(CultureInfo.InvariantCulture)); parameters.AddOptionalParameter("ccy", asset); @@ -119,8 +118,8 @@ public virtual async Task>> Pla { foreach (var order in orders) { - order.Tag = _ref; - order.ClientOrderId = _ref + (order.ClientOrderId ?? RandomString(15)); + order.Tag = _baseClient._ref; + order.ClientOrderId = _baseClient._ref + (order.ClientOrderId ?? RandomString(15)); } var parameters = new Dictionary @@ -276,8 +275,8 @@ public virtual async Task> ClosePosition var parameters = new Dictionary { {"instId", symbol }, {"mgnMode", JsonConvert.SerializeObject(marginMode, new MarginModeConverter(false)) }, - {"tag", "c84128021aecBCDE" }, - {"clOrdId", _ref + RandomString(15) } + {"tag", _baseClient._ref }, + {"clOrdId", _baseClient._ref + RandomString(15) } }; if (positionSide.HasValue) @@ -565,8 +564,8 @@ public virtual async Task> PlaceAlgoOrderAsy {"side", JsonConvert.SerializeObject(orderSide, new OrderSideConverter(false)) }, {"ordType", JsonConvert.SerializeObject(algoOrderType, new AlgoOrderTypeConverter(false)) }, {"sz", quantity.ToString() }, - {"tag", _ref }, - {"clOrdId", _ref + RandomString(15) } + {"tag", _baseClient._ref }, + {"clOrdId", _baseClient._ref + RandomString(15) } }; parameters.AddOptionalParameter("ccy", asset); parameters.AddOptionalParameter("reduceOnly", reduceOnly); diff --git a/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApi.cs b/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApi.cs index ca495c6..835d206 100644 --- a/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApi.cs +++ b/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApi.cs @@ -19,6 +19,7 @@ public class OKXSocketClientUnifiedApi : SocketApiClient, IOKXSocketClientUnifie /// public IOKXSocketClientUnifiedApiTrading Trading { get; } + internal readonly string _ref = "078ee129065aBCDE"; private bool _demoTrading; #region ctor @@ -33,6 +34,8 @@ internal OKXSocketClientUnifiedApi(ILogger logger, OKXSocketOptions options) : ExchangeData = new OKXSocketClientUnifiedApiExchangeData(logger, this); Trading = new OKXSocketClientUnifiedApiTrading(logger, this); + _ref = !string.IsNullOrEmpty(options.BrokerId) ? options.BrokerId : "078ee129065aBCDE"; + _demoTrading = options.Environment.EnvironmentName == TradeEnvironmentNames.Testnet; } #endregion diff --git a/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApiTrading.cs b/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApiTrading.cs index d2d6780..229154f 100644 --- a/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApiTrading.cs +++ b/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApiTrading.cs @@ -12,7 +12,6 @@ public class OKXSocketClientUnifiedApiTrading : IOKXSocketClientUnifiedApiTradin { private readonly OKXSocketClientUnifiedApi _client; private static Random _random = new Random(); - private const string _ref = "078ee129065aBCDE"; private readonly ILogger _logger; @@ -53,8 +52,8 @@ public async Task> PlaceOrderAsync(string symb }; parameters.AddOptionalParameter("ccy", asset); - parameters.AddOptionalParameter("clOrdId", _ref + (clientOrderId ?? RandomString(15))); - parameters.AddOptionalParameter("tag", _ref); + parameters.AddOptionalParameter("clOrdId", _client._ref + (clientOrderId ?? RandomString(15))); + parameters.AddOptionalParameter("tag", _client._ref); parameters.AddOptionalParameter("posSide", EnumConverter.GetString(positionSide)); parameters.AddOptionalParameter("px", price?.ToString(CultureInfo.InvariantCulture)); parameters.AddOptionalParameter("reduceOnly", reduceOnly); @@ -75,8 +74,8 @@ public async Task>> PlaceMultipleO { foreach (var order in orders) { - order.Tag = _ref; - order.ClientOrderId = _ref + (order.ClientOrderId ?? RandomString(15)); + order.Tag = _client._ref; + order.ClientOrderId = _client._ref + (order.ClientOrderId ?? RandomString(15)); } return await _client.QueryInternalAsync>(_client.GetUri("/ws/v5/private"), "batch-orders", orders, true, 1).ConfigureAwait(false); diff --git a/OKX.Net/OKX.Net.xml b/OKX.Net/OKX.Net.xml index b358e61..a17d8a0 100644 --- a/OKX.Net/OKX.Net.xml +++ b/OKX.Net/OKX.Net.xml @@ -4875,6 +4875,11 @@ Whether or not to sign public requests + + + Broker ID for earning rebates + + Options for the unified API @@ -4890,6 +4895,11 @@ Default options for new OKXRestClients + + + Broker ID for earning rebates + + Options for the Unified API diff --git a/OKX.Net/Objects/Options/OKXRestOptions.cs b/OKX.Net/Objects/Options/OKXRestOptions.cs index 6af1fda..dfe646b 100644 --- a/OKX.Net/Objects/Options/OKXRestOptions.cs +++ b/OKX.Net/Objects/Options/OKXRestOptions.cs @@ -21,6 +21,11 @@ public class OKXRestOptions : RestExchangeOptions public bool SignPublicRequests { get; set; } + /// + /// Broker ID for earning rebates + /// + public string? BrokerId { get; set; } + /// /// Options for the unified API /// @@ -30,6 +35,7 @@ internal OKXRestOptions Copy() { var options = Copy(); options.SignPublicRequests = SignPublicRequests; + options.BrokerId = BrokerId; options.UnifiedOptions = UnifiedOptions.Copy(); return options; } diff --git a/OKX.Net/Objects/Options/OKXSocketOptions.cs b/OKX.Net/Objects/Options/OKXSocketOptions.cs index 7388db5..4b177c4 100644 --- a/OKX.Net/Objects/Options/OKXSocketOptions.cs +++ b/OKX.Net/Objects/Options/OKXSocketOptions.cs @@ -17,6 +17,11 @@ public class OKXSocketOptions : SocketExchangeOptions Environment = OKXEnvironment.Live }; + /// + /// Broker ID for earning rebates + /// + public string? BrokerId { get; set; } + /// /// Options for the Unified API /// @@ -25,6 +30,7 @@ public class OKXSocketOptions : SocketExchangeOptions internal OKXSocketOptions Copy() { var options = Copy(); + options.BrokerId = BrokerId; options.UnifiedOptions = UnifiedOptions.Copy(); return options; }