Skip to content

Commit

Permalink
Websocket refactoring (#28)
Browse files Browse the repository at this point in the history
Websocket refactoring
  • Loading branch information
JKorf authored Feb 24, 2024
1 parent 7bc3dbd commit daa1e89
Show file tree
Hide file tree
Showing 65 changed files with 1,158 additions and 1,031 deletions.
3 changes: 1 addition & 2 deletions OKX.Net.UnitTests/JsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ await _comparer.ProcessSubject("Unified/Account", c => c.UnifiedApi.Account,
},
ignoreProperties: new Dictionary<string, List<string>>
{
{ "GetAccountConfigurationAsync", new List<string>{ "traderInsts" } },
{ "GetAccountPositionsAsync", new List<string>{ "closeOrderAlgo" } }
{ "GetAccountConfigurationAsync", new List<string>{ "traderInsts" } }
}
);
}
Expand Down
1 change: 1 addition & 0 deletions OKX.Net.UnitTests/OXKRestClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using OKX.Net.Clients;
using OKX.Net.Objects.Core;
using OKX.Net.Interfaces.Clients.UnifiedApi;
using CryptoExchange.Net.Objects.Sockets;

namespace OKX.Net.UnitTests
{
Expand Down
9 changes: 1 addition & 8 deletions OKX.Net/Clients/OKXRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ public class OKXRestClient : BaseRestClient, IOKXRestClient
/// Create a new instance of the OKXRestClient using provided options
/// </summary>
/// <param name="optionsDelegate">Option configuration delegate</param>
public OKXRestClient(Action<OKXRestOptions> optionsDelegate) : this(null, null, optionsDelegate)
{
}

/// <summary>
/// Create a new instance of the OKXRestClient using default options
/// </summary>
public OKXRestClient(ILoggerFactory? loggerFactory = null, HttpClient? httpClient = null) : this(httpClient, loggerFactory, null)
public OKXRestClient(Action<OKXRestOptions>? optionsDelegate = null) : this(null, null, optionsDelegate)
{
}

Expand Down
2 changes: 1 addition & 1 deletion OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal OKXRestClientUnifiedApi(ILogger logger, HttpClient? httpClient, OKXRest
Trading = new OKXRestClientUnifiedApiTrading(this);
SubAccounts = new OKXRestClientUnifiedApiSubAccounts(this);

_ref = !string.IsNullOrEmpty(options.BrokerId) ? options.BrokerId : "078ee129065aBCDE";
_ref = !string.IsNullOrEmpty(options.BrokerId) ? options.BrokerId! : "1425d83a94fbBCDE";

if (options.Environment.EnvironmentName == TradeEnvironmentNames.Testnet)
{
Expand Down
13 changes: 13 additions & 0 deletions OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -814,4 +814,17 @@ public virtual async Task<WebCallResult<OKXTransferInfo>> GetTransferAsync(strin

return result.As(result.Data.Data.FirstOrDefault());
}

/// <inheritdoc />
public virtual async Task<WebCallResult<OKXAccountMode>> SetAccountModeAsync(OKXAccountLevel mode, CancellationToken ct = default)
{
var parameters = new ParameterCollection();
parameters.AddEnum("acctLv", mode);

var result = await _baseClient.ExecuteAsync<OKXRestApiResponse<IEnumerable<OKXAccountMode>>>(_baseClient.GetUri("api/v5/account/set-account-level"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
if (!result.Success) return result.AsError<OKXAccountMode>(result.Error!);
if (result.Data.ErrorCode > 0) return result.AsError<OKXAccountMode>(new OKXRestApiError(result.Data.ErrorCode, result.Data.ErrorMessage!, null));

return result.As(result.Data.Data.FirstOrDefault());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using OKX.Net.Converters;
using OKX.Net.Enums;
using OKX.Net.ExtensionMethods;
using OKX.Net.Interfaces.Clients.UnifiedApi;
using OKX.Net.Objects.Core;
using OKX.Net.Objects.Market;
Expand Down
3 changes: 1 addition & 2 deletions OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiTrading.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Options;
using OKX.Net.Converters;
using OKX.Net.Converters;
using OKX.Net.Enums;
using OKX.Net.Interfaces.Clients.UnifiedApi;
using OKX.Net.Objects.Core;
Expand Down
Loading

0 comments on commit daa1e89

Please sign in to comment.