Skip to content

Commit

Permalink
v-5.4.1010
Browse files Browse the repository at this point in the history
  • Loading branch information
burakoner committed Oct 9, 2024
1 parent 2defe67 commit 93f6ee7
Show file tree
Hide file tree
Showing 31 changed files with 501 additions and 397 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
## Change Log & Release Notes

* * Version 5.4.1010 - 09 Oct 2024
* Updated WebSocket API endpoints and models to [2024-10-04](https://www.okx.com/docs-v5/log_en/#2024-10-04) version
* Moved Status methods to Public Client
* Moved Announcement methods to Public Client
* Removed Market alias for Public Client
* Added WS / Fills channel
* Refactoring and performance improvements

* Version 5.4.1009 - 09 Oct 2024
* Updated endpoints and models to [2024-10-04](https://www.okx.com/docs-v5/log_en/#2024-10-04) version
* Updated Rest API endpoints and models to [2024-10-04](https://www.okx.com/docs-v5/log_en/#2024-10-04) version

* Version 5.4.1001 - 01 Oct 2024
* ApiSharp 3.0.0 Update
Expand Down
28 changes: 20 additions & 8 deletions OKX.Api.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
internal class Program
{
static async Task Main(string[] args)
{
var ws = new OKXWebSocketApiClient();
ws.SetApiCredentials("ab69cb97-05fb-430f-b880-49940796f86e", "BCD93B0F1C9BCB9C2BE3AD3E2BE53DCE", "bo1144167AZ*");

await ws.Account.SubscribeToAccountUpdatesAsync(data =>
{
Console.WriteLine($"Account Balance: {data}");
}, "BTC", 100);

Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
static async Task Main2(string[] args)
{
#region Rest Api Client Examples
var api = new OkxRestApiClient();
Expand Down Expand Up @@ -66,13 +79,9 @@ static async Task Main(string[] args)
var public_40 = await api.Public.GetExchangeRateAsync();
var public_41 = await api.Public.GetIndexComponentsAsync("BTC-USDT");
var public_42 = await api.Public.GetEconomicCalendarDataAsync("BTC-USDT");

// Status Methods (Unsigned)
var system_01 = await api.Status.GetSystemUpgradeStatusAsync();

// Announcement Methods
var announcement_01 = await api.Announcement.GetAnnouncementTypesAsync(); // (Unsigned)
var announcement_02 = await api.Announcement.GetAnnouncementsAsync(); // (Signed)
var public_43 = await api.Public.GetAnnouncementTypesAsync();
var public_44 = await api.Public.GetAnnouncementsAsync();
var public_45 = await api.Public.GetSystemUpgradeStatusAsync();

// Trading Account Methods (Signed)
var account_01 = await api.Account.GetInstrumentsAsync(OkxInstrumentType.Spot);
Expand Down Expand Up @@ -578,7 +587,10 @@ await ws.Trade.SubscribeToOrderUpdatesAsync((data) =>
{
// ... Your logic here
}, OkxInstrumentType.Futures, "INSTRUMENT-FAMILY", "INSTRUMENT-ID");

await ws.Trade.SubscribeToFillsAsync((data) =>
{
// ... Your logic here
});
await ws.Trade.PlaceOrderAsync(new OkxTradeOrderPlaceRequest());
await ws.Trade.PlaceOrdersAsync(new List<OkxTradeOrderPlaceRequest>());
await ws.Trade.CancelOrderAsync(new OkxTradeOrderCancelRequest());
Expand Down
29 changes: 21 additions & 8 deletions OKX.Api/Account/Clients/OkxAccountSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
public class OkxAccountSocketClient(OKXWebSocketApiClient root)
{
// Internal
internal OKXWebSocketApiClient Root { get; } = root;
internal OKXWebSocketApiClient _ { get; } = root;

/// <summary>
/// Retrieve account information. Data will be pushed when triggered by events such as placing/canceling order, and will also be pushed in regular interval according to subscription granularity.
/// </summary>
/// <param name="onData">On Data Handler</param>
/// <param name="currency">Currency</param>
/// <param name="updateInterval">0: only push due to account events
/// The data will be pushed both by events and regularly if this field is omitted or set to other values than 0.
/// The following format should be strictly obeyed when using this field.</param>
/// <param name="ct">Cancellation Token</param>
/// <returns></returns>
public async Task<CallResult<WebSocketUpdateSubscription>> SubscribeToAccountUpdatesAsync(Action<OkxAccountBalance> onData, CancellationToken ct = default)
public async Task<CallResult<WebSocketUpdateSubscription>> SubscribeToAccountUpdatesAsync(
Action<OkxAccountBalance> onData,
string? currency = null,
int? updateInterval = null,
CancellationToken ct = default)
{
var internalHandler = new Action<WebSocketDataEvent<OkxSocketUpdateResponse<List<OkxAccountBalance>>>>(data =>
{
Expand All @@ -24,9 +32,14 @@ public async Task<CallResult<WebSocketUpdateSubscription>> SubscribeToAccountUpd

var request = new OkxSocketRequest(OkxSocketOperation.Subscribe, new OkxSocketRequestArgument
{
Channel = "account"
Channel = "account",
Currency = currency,
ExtraParameters = updateInterval.HasValue
? new Dictionary<string, string> { { "interval", updateInterval.Value.ToOkxString() } }
: null
});
return await Root.RootSubscribeAsync(OkxSocketEndpoint.Private, request, null, true, internalHandler, ct).ConfigureAwait(false);

return await _.RootSubscribeAsync(OkxSocketEndpoint.Private, request, null, true, internalHandler, ct).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -65,7 +78,7 @@ public async Task<CallResult<WebSocketUpdateSubscription>> SubscribeToPositionUp
InstrumentFamily = symbol.InstrumentFamily,
});
var request = new OkxSocketRequest(OkxSocketOperation.Subscribe, arguments);
return await Root.RootSubscribeAsync(OkxSocketEndpoint.Private, request, null, true, internalHandler, ct).ConfigureAwait(false);
return await _.RootSubscribeAsync(OkxSocketEndpoint.Private, request, null, true, internalHandler, ct).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -86,7 +99,7 @@ public async Task<CallResult<WebSocketUpdateSubscription>> SubscribeToBalanceAnd
{
Channel = "balance_and_position"
});
return await Root.RootSubscribeAsync(OkxSocketEndpoint.Private, request, null, true, internalHandler, ct).ConfigureAwait(false);
return await _.RootSubscribeAsync(OkxSocketEndpoint.Private, request, null, true, internalHandler, ct).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -113,7 +126,7 @@ public async Task<CallResult<WebSocketUpdateSubscription>> SubscribeToPositionRi
Channel = "liquidation-warning",
InstrumentType = instrumentType
});
return await Root.RootSubscribeAsync(OkxSocketEndpoint.Private, request, null, true, internalHandler, ct).ConfigureAwait(false);
return await _.RootSubscribeAsync(OkxSocketEndpoint.Private, request, null, true, internalHandler, ct).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -135,6 +148,6 @@ public async Task<CallResult<WebSocketUpdateSubscription>> SubscribeToAccountGre
{
Channel = "account-greeks",
});
return await Root.RootSubscribeAsync(OkxSocketEndpoint.Private, request, null, true, internalHandler, ct).ConfigureAwait(false);
return await _.RootSubscribeAsync(OkxSocketEndpoint.Private, request, null, true, internalHandler, ct).ConfigureAwait(false);
}
}
6 changes: 3 additions & 3 deletions OKX.Api/Algo/Clients/OkxAlgoSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class OkxAlgoSocketClient(OKXWebSocketApiClient root)
{
// Internal
internal OKXWebSocketApiClient Root { get; } = root;
internal OKXWebSocketApiClient _ { get; } = root;

/// <summary>
/// Retrieve algo orders (includes trigger order, oco order, conditional order). Data will not be pushed when first subscribed. Data will only be pushed when triggered by events such as placing/canceling order.
Expand Down Expand Up @@ -52,7 +52,7 @@ public async Task<CallResult<WebSocketUpdateSubscription>> SubscribeToAlgoOrderU
InstrumentFamily = symbol.InstrumentFamily,
});
var request = new OkxSocketRequest(OkxSocketOperation.Subscribe, arguments);
return await Root.RootSubscribeAsync(OkxSocketEndpoint.Business, request, null, true, internalHandler, ct).ConfigureAwait(false);
return await _.RootSubscribeAsync(OkxSocketEndpoint.Business, request, null, true, internalHandler, ct).ConfigureAwait(false);
}


Expand Down Expand Up @@ -100,7 +100,7 @@ public async Task<CallResult<WebSocketUpdateSubscription>> SubscribeToAdvanceAlg
InstrumentFamily = symbol.InstrumentFamily,
});
var request = new OkxSocketRequest(OkxSocketOperation.Subscribe, arguments);
return await Root.RootSubscribeAsync(OkxSocketEndpoint.Business, request, null, true, internalHandler, ct).ConfigureAwait(false);
return await _.RootSubscribeAsync(OkxSocketEndpoint.Business, request, null, true, internalHandler, ct).ConfigureAwait(false);
}

}
39 changes: 0 additions & 39 deletions OKX.Api/Announcement/Clients/OkxAnnouncementRestClient.cs

This file was deleted.

8 changes: 4 additions & 4 deletions OKX.Api/Base/Clients/OkxBaseRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
public abstract class OkxBaseRestClient : RestApiClient
{
internal ILogger Logger { get => _logger; }
internal OkxRestApiClient Root { get; }
internal OkxRestApiOptions Options { get { return Root.Options; } }
internal OkxRestApiClient _ { get; }
internal OkxRestApiOptions Options { get { return _.Options; } }
internal TimeSyncState TimeSyncState { get; } = new("OKX RestApi");

internal OkxBaseRestClient(OkxRestApiClient root) : base(root.Logger, root.Options)
{
Root = root;
_ = root;
ManualParseError = true;

RequestBodyFormat = RestRequestBodyFormat.Json;
Expand Down Expand Up @@ -50,7 +50,7 @@ protected override Task<ServerError> TryParseErrorAsync(JToken error)
return Task.FromResult<ServerError>(null);
}
/// <inheritdoc />
protected override Task<RestCallResult<DateTime>> GetServerTimestampAsync() => Root.Public.GetServerTimeAsync();
protected override Task<RestCallResult<DateTime>> GetServerTimestampAsync() => _.Public.GetServerTimeAsync();
/// <inheritdoc />
protected override TimeSyncInfo GetTimeSyncInfo() => new(Logger, Options.AutoTimestamp, Options.AutoTimestampInterval, TimeSyncState);
/// <inheritdoc />
Expand Down
18 changes: 15 additions & 3 deletions OKX.Api/Base/Requests/OkxSocketRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ public record OkxSocketRequestArgument
[JsonProperty("channel")]
public string? Channel { get; set; }

/// <summary>
/// Currency
/// </summary>
[JsonProperty("ccy", NullValueHandling = NullValueHandling.Ignore)]
public string? Currency { get; set; }

/// <summary>
/// Algo Order Id
/// </summary>
[JsonProperty("algoId", NullValueHandling = NullValueHandling.Ignore)]
public string? AlgoOrderId { get; set; }

/// <summary>
/// Instrument Family
/// </summary>
Expand All @@ -149,10 +161,10 @@ public record OkxSocketRequestArgument
public OkxInstrumentType? InstrumentType { get; set; }

/// <summary>
/// Algo Order Id
/// Additional configuration
/// </summary>
[JsonProperty("algoId", NullValueHandling = NullValueHandling.Ignore)]
public string? AlgoOrderId { get; set; }
[JsonProperty("extraParams", NullValueHandling = NullValueHandling.Ignore)]
public Dictionary<string, string>? ExtraParameters { get; set; }
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion OKX.Api/Block/Clients/OkxBlockSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
public class OkxBlockSocketClient(OKXWebSocketApiClient root)
{
// Internal
internal OKXWebSocketApiClient Root { get; } = root;
internal OKXWebSocketApiClient _ { get; } = root;

// TODO: Rfqs channel
// TODO: Quotes channel
// TODO: Structure block trades channel

// TODO: Public structure block trades channel
// TODO: Public block trades channel
// TODO: Block tickers channel
Expand Down
2 changes: 1 addition & 1 deletion OKX.Api/CopyTrading/Clients/OkxCopyTradingSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class OkxCopyTradingSocketClient(OKXWebSocketApiClient root)
{
// Internal
internal OKXWebSocketApiClient Root { get; } = root;
internal OKXWebSocketApiClient _ { get; } = root;

// WS / Copy trading notification channel
// WS / Lead trading notification channel
Expand Down
2 changes: 1 addition & 1 deletion OKX.Api/Funding/Clients/OKXFundingSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class OkxFundingSocketClient(OKXWebSocketApiClient root)
{
// Internal
internal OKXWebSocketApiClient Root { get; } = root;
internal OKXWebSocketApiClient _ { get; } = root;

// TODO: Deposit info channel
// TODO: Withdrawal info channel
Expand Down
2 changes: 1 addition & 1 deletion OKX.Api/Grid/Clients/OkxGridSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class OkxGridSocketClient(OKXWebSocketApiClient root)
{
// Internal
internal OKXWebSocketApiClient Root { get; } = root;
internal OKXWebSocketApiClient _ { get; } = root;

// TODO: WS / Spot grid algo orders channel
// TODO: WS / Contract grid algo orders channel
Expand Down
8 changes: 4 additions & 4 deletions OKX.Api/OKX.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<PropertyGroup>
<PackageId>OKX.Api</PackageId>
<Authors>Burak Öner</Authors>
<Version>5.4.1009</Version>
<FileVersion>5.4.1009</FileVersion>
<PackageVersion>5.4.1009</PackageVersion>
<AssemblyVersion>5.4.1009</AssemblyVersion>
<Version>5.4.1010</Version>
<FileVersion>5.4.1010</FileVersion>
<PackageVersion>5.4.1010</PackageVersion>
<AssemblyVersion>5.4.1010</AssemblyVersion>
<Description>OKX V5 Api Wrapper. Up-to-date, most-complete, well-organized, well-documented, easy-to-use, multi-task and multi-thread compatible OKX Cryptocurrency Exchange Rest and Websocket Api Wrapper</Description>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>OKX;OKEX;Binance;BNB;BTC;Api;Client;Rest;Web;Websocket;Socket;Wrapper;Crypto;Currency;Cryptocurrency;Exchange;Trade;Trading;Bitcoin;Spot;Margin;Futures;Derivates;Stock;Options;Swap;</PackageTags>
Expand Down
20 changes: 0 additions & 20 deletions OKX.Api/OKXRestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public class OkxRestApiClient
/// </summary>
public OkxCopyTradingRestClient CopyTrading { get; }

/// <summary>
/// Alias for Public Client
/// </summary>
public OkxPublicRestClient Market { get => Public; }

/// <summary>
/// Block Trading Client
/// </summary>
Expand Down Expand Up @@ -104,17 +99,6 @@ public class OkxRestApiClient
/// Affiliate Client
/// </summary>
public OkxAffiliateRestClient Affiliate { get; }

/// <summary>
/// Status Client
/// </summary>
public OkxStatusRestClient Status { get; }

/// <summary>
/// Announcement Client
/// </summary>
public OkxAnnouncementRestClient Announcement { get; }

#endregion

#region Constructors
Expand Down Expand Up @@ -160,8 +144,6 @@ public OkxRestApiClient(ILogger? logger, OkxRestApiOptions options)
Rubik = new OkxRubikRestClient(this);
Broker = new OkxBrokerRestClient(this);
Affiliate = new OkxAffiliateRestClient(this);
Status = new OkxStatusRestClient(this);
Announcement = new OkxAnnouncementRestClient(this);
}
#endregion

Expand Down Expand Up @@ -200,8 +182,6 @@ public void SetApiCredentials(OkxApiCredentials credentials)
Rubik.SetApiCredentials(credentials);
Broker.SetApiCredentials(credentials);
Affiliate.SetApiCredentials(credentials);
Status.SetApiCredentials(credentials);
Announcement.SetApiCredentials(credentials);
}
#endregion
}
5 changes: 0 additions & 5 deletions OKX.Api/OKXWebSocketApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public class OKXWebSocketApiClient : OkxBaseSocketClient
/// </summary>
public OkxCopyTradingSocketClient CopyTrading { get; }

/// <summary>
/// Alias for Public Client
/// </summary>
public OkxPublicSocketClient Market { get => Public; }

/// <summary>
/// Block Trading Client
/// </summary>
Expand Down
Loading

0 comments on commit 93f6ee7

Please sign in to comment.