OKX.Api
2.5.7
See the version list below for details.
dotnet add package OKX.Api --version 2.5.7
NuGet\Install-Package OKX.Api -Version 2.5.7
<PackageReference Include="OKX.Api" Version="2.5.7" />
paket add OKX.Api --version 2.5.7
#r "nuget: OKX.Api, 2.5.7"
// Install OKX.Api as a Cake Addin #addin nuget:?package=OKX.Api&version=2.5.7 // Install OKX.Api as a Cake Tool #tool nuget:?package=OKX.Api&version=2.5.7
OKX.Api
A .Net wrapper for the OKX API as described on OKX, including all features the API provides using clear and readable objects.
If you think something is broken, something is missing or have any questions, please open an Issue
Donations
Donations are greatly appreciated and a motivation to keep improving.
BTC: 33WbRKqt7wXARVdAJSu1G1x3QnbyPtZ2bH
ETH: 0x65b02db9b67b73f5f1e983ae10796f91ded57b64
USDT (TRC-20): TXwqoD7doMESgitfWa8B2gHL7HuweMmNBJ
Installation
Available on Nuget.
PM> Install-Package OKX.Api
To get started with OKX.Api first you will need to get the library itself. The easiest way to do this is to install the package into your project using NuGet. Using Visual Studio this can be done in two ways.
Using the package manager
In Visual Studio right click on your solution and select 'Manage NuGet Packages for solution...'. A screen will appear which initially shows the currently installed packages. In the top bit select 'Browse'. This will let you download net package from the NuGet server. In the search box type 'OKX.Api' and hit enter. The OKX.Api package should come up in the results. After selecting the package you can then on the right hand side select in which projects in your solution the package should install. After you've selected all project you wish to install and use OKX.Api in hit 'Install' and the package will be downloaded and added to you projects.
Using the package manager console
In Visual Studio in the top menu select 'Tools' → 'NuGet Package Manager' → 'Package Manager Console'. This should open up a command line interface. On top of the interface there is a dropdown menu where you can select the Default Project. This is the project that OKX.Api will be installed in. After selecting the correct project type Install-Package OKX.Api
in the command line interface. This should install the latest version of the package in your project.
After doing either of above steps you should now be ready to actually start using OKX.Api.
Getting started
After installing it's time to actually use it. To get started we have to add the OKX.Api namespace: using OKX.Api;
.
OKX.Api provides two clients to interact with the OKX.Api. The OKXRestApiClient
provides all rest API calls. The OKXWebSocketApiClient
provides functions to interact with the websocket provided by the OKX.Api. Both clients are disposable and as such can be used in a using
statement.
Rest Api Examples
var api = new OKXRestApiClient();
api.SetApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX", "XXXXXXXX-API-PASSPHRASE-XXXXXXXX");
// Order Book Trading -> Market Data Methods (Signed)
var market_01 = await api.Public.GetTickersAsync(OkxInstrumentType.Spot);
var market_02 = await api.Public.GetTickerAsync("BTC-USDT");
var market_03 = await api.Public.GetOrderBookAsync("BTC-USDT", 40);
var market_04 = await api.Public.GetOrderBookFullAsync("BTC-USDT", 5000);
var market_05 = await api.Public.GetCandlesticksAsync("BTC-USDT", "6Hutc");
var market_06 = await api.Public.GetCandlesticksAsync("BTC-USDT", OkxPeriod.OneHour);
var market_07 = await api.Public.GetCandlestickHistoryAsync("BTC-USDT", "6Hutc");
var market_08 = await api.Public.GetCandlestickHistoryAsync("BTC-USDT", OkxPeriod.OneHour);
var market_09 = await api.Public.GetTradesAsync("BTC-USDT");
var market_10 = await api.Public.GetTradeHistoryAsync("BTC-USDT");
var market_11 = await api.Public.GetOptionTradesByInstrumentFamilyAsync("BTC-USDT");
var market_12 = await api.Public.GetOptionTradesAsync("BTC-USDT");
var market_13 = await api.Public.Get24HourVolumeAsync();
// Public Methods (Unsigned)
var public_01 = await api.Public.GetInstrumentsAsync(OkxInstrumentType.Spot);
var public_02 = await api.Public.GetInstrumentsAsync(OkxInstrumentType.Margin);
var public_03 = await api.Public.GetInstrumentsAsync(OkxInstrumentType.Swap, instrumentId: "BTC-USDT-SWAP");
var public_04 = await api.Public.GetInstrumentsAsync(OkxInstrumentType.Futures);
var public_05 = await api.Public.GetInstrumentsAsync(OkxInstrumentType.Option, "USD");
var public_06 = await api.Public.GetInstrumentsAsync(OkxInstrumentType.Swap, instrumentId: "BTC-USDT-SWAP", signed: true);
var public_07 = await api.Public.GetDeliveryExerciseHistoryAsync(OkxInstrumentType.Futures, "BTC-USD");
var public_08 = await api.Public.GetDeliveryExerciseHistoryAsync(OkxInstrumentType.Option, "BTC-USD");
var public_09 = await api.Public.GetOpenInterestsAsync(OkxInstrumentType.Futures);
var public_10 = await api.Public.GetOpenInterestsAsync(OkxInstrumentType.Option, "BTC-USD");
var public_11 = await api.Public.GetOpenInterestsAsync(OkxInstrumentType.Swap, "BTC-USD");
var public_12 = await api.Public.GetFundingRatesAsync("BTC-USD-SWAP");
var public_13 = await api.Public.GetFundingRateHistoryAsync("BTC-USD-SWAP");
var public_14 = await api.Public.GetLimitPriceAsync("BTC-USD-SWAP");
var public_15 = await api.Public.GetOptionMarketDataAsync("BTC-USD");
var public_16 = await api.Public.GetEstimatedPriceAsync("BTC-USD-211004-41000-C");
var public_17 = await api.Public.GetDiscountInfoAsync();
var public_18 = await api.Public.GetServerTimeAsync();
var public_19 = await api.Public.GetMarkPricesAsync(OkxInstrumentType.Futures);
var public_20 = await api.Public.GetPositionTiersAsync(OkxInstrumentType.Futures, OkxAccountMarginMode.Isolated, "BTC-USD");
var public_21 = await api.Public.GetInterestRatesAsync();
var public_22 = await api.Public.GetVIPInterestRatesAsync();
var public_23 = await api.Public.GetUnderlyingAsync(OkxInstrumentType.Futures);
var public_24 = await api.Public.GetUnderlyingAsync(OkxInstrumentType.Option);
var public_25 = await api.Public.GetUnderlyingAsync(OkxInstrumentType.Swap);
var public_26 = await api.Public.GetInsuranceFundAsync(OkxInstrumentType.Margin, currency: "BTC");
var public_27 = await api.Public.GetUnitConvertAsync("BTC-USD-SWAP", price: 35000, size: 0.888m);
var public_28 = await api.Public.GetOptionTickBandsAsync();
var public_29 = await api.Public.GetPremiumHistoryAsync(instrumentId: "BTC-USDT");
var public_30 = await api.Public.GetIndexTickersAsync(instrumentId: "BTC-USDT");
var public_31 = await api.Public.GetIndexCandlesticksAsync("BTC-USDT", "6Hutc");
var public_32 = await api.Public.GetIndexCandlesticksAsync("BTC-USDT", OkxPeriod.OneHour);
var public_33 = await api.Public.GetIndexCandlesticksHistoryAsync("BTC-USDT", "6Hutc");
var public_34 = await api.Public.GetIndexCandlesticksHistoryAsync("BTC-USDT", OkxPeriod.OneHour);
var public_35 = await api.Public.GetMarkPriceCandlesticksAsync("BTC-USDT", "6Hutc");
var public_36 = await api.Public.GetMarkPriceCandlesticksAsync("BTC-USDT", OkxPeriod.OneHour);
var public_37 = await api.Public.GetMarkPriceCandlesticksHistoryAsync("BTC-USDT", "6Hutc");
var public_38 = await api.Public.GetMarkPriceCandlesticksHistoryAsync("BTC-USDT", OkxPeriod.OneHour);
var public_39 = await api.Public.GetOracleAsync();
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.Public.GetSystemUpgradeStatusAsync();
// Trading Account Methods (Signed)
var account_01 = await api.Account.GetInstrumentsAsync(OkxInstrumentType.Spot);
var account_02 = await api.Account.GetBalancesAsync();
var account_03 = await api.Account.GetPositionsAsync();
var account_04 = await api.Account.GetPositionsHistoryAsync();
var account_05 = await api.Account.GetPositionRiskAsync();
var account_06 = await api.Account.GetBillHistoryAsync();
var account_07 = await api.Account.GetBillArchiveAsync();
var account_08 = await api.Account.ApplyBillDataAsync(2022, "Q1");
var account_09 = await api.Account.GetBillDataAsync(2022, "Q1");
var account_10 = await api.Account.GetConfigurationAsync();
var account_11 = await api.Account.SetPositionModeAsync(OkxTradePositionMode.LongShortMode);
var account_12 = await api.Account.GetLeverageAsync("BTC-USD-211008", OkxAccountMarginMode.Isolated);
var account_13 = await api.Account.SetLeverageAsync(30, null, "BTC-USD-211008", OkxAccountMarginMode.Isolated, OkxTradePositionSide.Long);
var account_14 = await api.Account.GetMaximumOrderQuantityAsync("BTC-USDT", OkxTradeMode.Isolated);
var account_15 = await api.Account.GetMaximumAvailableAmountAsync("BTC-USDT", OkxTradeMode.Isolated);
var account_16 = await api.Account.SetMarginAmountAsync("BTC-USDT", OkxTradePositionSide.Long, OkxAccountMarginAddReduce.Add, 100.0m);
var account_17 = await api.Account.GetLeverageEstimatedInformationAsync(OkxInstrumentType.Futures, OkxAccountMarginMode.Cross, 10);
var account_18 = await api.Account.GetMaximumLoanAmountAsync("BTC-USDT", OkxAccountMarginMode.Cross);
var account_19 = await api.Account.GetFeeRatesAsync(OkxInstrumentType.Spot, OkxInstrumentRuleType.Normal);
var account_20 = await api.Account.GetFeeRatesAsync(OkxInstrumentType.Futures, OkxInstrumentRuleType.Normal);
var account_21 = await api.Account.GetInterestAccruedAsync();
var account_22 = await api.Account.GetInterestRateAsync();
var account_23 = await api.Account.SetGreeksAsync(OkxAccountGreeksType.GreeksInCoins);
var account_24 = await api.Account.SetIsolatedMarginModeAsync(OkxInstrumentType.Futures, OkxAccountIsolatedMarginMode.AutoTransfer);
var account_25 = await api.Account.GetMaximumWithdrawalsAsync();
var account_26 = await api.Account.GetRiskStateAsync();
var account_27 = await api.Account.QuickMarginBorrowAsync("BTC-USDT", "BTC", 0.1m);
var account_28 = await api.Account.QuickMarginRepayAsync("BTC-USDT", "BTC", 0.1m);
var account_29 = await api.Account.GetQuickMarginBorrowRepayHistoryAsync();
var account_30 = await api.Account.VipLoanBorrowAsync("USDT", 1000.0m);
var account_31 = await api.Account.VipLoanRepayAsync("USDT", 1000.0m, 1_000_001);
var account_32 = await api.Account.GetVipLoanBorrowRepayHistoryAsync();
var account_33 = await api.Account.GetVipLoanBorrowRepayHistoryAsync("USDT");
var account_34 = await api.Account.GetVipInterestAccruedDataAsync();
var account_35 = await api.Account.GetVipInterestAccruedDataAsync("USDT");
var account_36 = await api.Account.GetVipInterestDeductedDataAsync();
var account_37 = await api.Account.GetVipInterestDeductedDataAsync("USDT");
var account_38 = await api.Account.GetVipLoanOrdersAsync();
var account_39 = await api.Account.GetVipLoanOrderDetailsAsync();
var account_40 = await api.Account.GetInterestLimitsAsync();
var account_41 = await api.Account.GetFixedLoanBorrowingLimitAsync();
var account_42 = await api.Account.GetFixedLoanBorrowingQuoteAsync(OkxAccountFixedLoanBorrowingType.Normal);
var account_43 = await api.Account.PlaceFixedLoanBorrowingOrderAsync("", 0.0m, 0.0m, "30D");
var account_44 = await api.Account.AmendFixedLoanBorrowingOrderAsync(1_000_001L);
var account_45 = await api.Account.RenewFixedLoanBorrowingOrderAsync(1_000_001L);
var account_46 = await api.Account.RepayFixedLoanBorrowingOrderAsync(1_000_001L);
var account_47 = await api.Account.GetFixedLoanBorrowingOrdersAsync(1_000_001L);
var account_48 = await api.Account.PositionBuilderAsync();
var account_49 = await api.Account.SetRiskOffsetAmountAsync("BTC", 1.0M);
var account_50 = await api.Account.GetGreeksAsync();
var account_51 = await api.Account.GetPositionTiersAsync(OkxInstrumentType.Futures);
var account_52 = await api.Account.SetRiskOffsetTypeAsync(OkxAccountRiskOffsetType.UsdtDerivativesUsdt);
var account_53 = await api.Account.ActivateOptionAsync();
var account_54 = await api.Account.SetAutoLoanAsync(true);
var account_55 = await api.Account.SetLevelAsync(OkxAccountLevel.Simple);
var account_56 = await api.Account.ResetMmpAsync("BTC-USDT");
var account_57 = await api.Account.SetMmpAsync("BTC-USDT", 5000, 5000, 1);
var account_58 = await api.Account.GetMmpAsync("BTC-USDT");
// Order Book Trading -> Trade Methods (Signed)
var trade_01 = await api.Trading.PlaceOrderAsync("BTC-USDT", OkxTradeMode.Cash, OkxTradeOrderSide.Buy, OkxTradePositionSide.Long, OkxTradeOrderType.MarketOrder, 0.1m);
var trade_02 = await api.Trading.PlaceOrdersAsync([]);
var trade_03 = await api.Trading.CancelOrderAsync("BTC-USDT");
var trade_04 = await api.Trading.CancelOrdersAsync([]);
var trade_05 = await api.Trading.AmendOrderAsync("BTC-USDT");
var trade_06 = await api.Trading.AmendOrdersAsync([]);
var trade_07 = await api.Trading.ClosePositionAsync("BTC-USDT", OkxAccountMarginMode.Isolated);
var trade_08 = await api.Trading.GetOrderAsync("BTC-USDT");
var trade_09 = await api.Trading.GetOpenOrdersAsync();
var trade_10 = await api.Trading.GetOrderHistoryAsync(OkxInstrumentType.Swap);
var trade_11 = await api.Trading.GetOrderArchiveAsync(OkxInstrumentType.Futures);
var trade_12 = await api.Trading.GetTradesAsync();
var trade_13 = await api.Trading.GetTradesHistoryAsync(OkxInstrumentType.Futures);
var trade_14 = await api.Trading.ApplyTradesArchiveAsync(2021, OkxQuarter.Quarter3);
var trade_15 = await api.Trading.GetTradesArchiveAsync(2021, OkxQuarter.Quarter3);
var trade_16 = await api.Trading.GetEasyConvertCurrenciesAsync();
var trade_17 = await api.Trading.PlaceEasyConvertOrderAsync([], "USDT");
var trade_18 = await api.Trading.GetEasyConvertHistoryAsync();
var trade_19 = await api.Trading.GetOneClickRepayCurrenciesAsync(OkxTradeDebtType.Isolated);
var trade_20 = await api.Trading.PlaceOneClickRepayOrderAsync([], "USDT");
var trade_21 = await api.Trading.GetOneClickRepayHistoryAsync();
var trade_22 = await api.Trading.MassCancelAsync(OkxInstrumentType.Option, "USDT");
var trade_23 = await api.Trading.CancelAllAfterAsync(30, "TAG");
var trade_24 = await api.Trading.GetAccountRateLimitAsync();
var trade_25 = await api.Trading.CheckOrderAsync("BTC-USDT", OkxTradeMode.Cash, OkxTradeOrderSide.Buy, OkxTradePositionSide.Long, OkxTradeOrderType.MarketOrder, 0.1m);
// Order Book Trading -> Algo Trading Methods (Signed)
var algo_01 = await api.Algo.PlaceOrderAsync("BTC-USDT", OkxTradeMode.Isolated, OkxTradeOrderSide.Sell, OkxAlgoOrderType.Conditional);
var algo_02 = await api.Algo.CancelOrderAsync(1_000_001L, "BTC-USDT");
var algo_03 = await api.Algo.CancelOrdersAsync([]);
var algo_04 = await api.Algo.AmendOrderAsync("BTC-USDT");
var algo_05 = await api.Algo.CancelAdvanceAsync([]);
var algo_06 = await api.Algo.GetOrderAsync(algoOrderId: 1_000_001);
var algo_07 = await api.Algo.GetOpenOrdersAsync(OkxAlgoOrderType.OCO);
var algo_08 = await api.Algo.GetOrderHistoryAsync(OkxAlgoOrderType.Conditional);
// Order Book Trading -> Grid Trading Methods (Signed)
var grid_01 = await api.Grid.PlaceOrderAsync(new OkxGridPlaceOrderRequest
{
InstrumentId = "BTC-USDT",
AlgoOrderType = OkxGridAlgoOrderType.SpotGrid,
MaximumPrice = 5000,
MinimumPrice = 400,
GridNumber = 10,
GridRunType = OkxGridRunType.Arithmetic,
QuoteSize = 25,
TriggerParameters =
[
new()
{
TriggerAction = OkxGridAlgoTriggerAction.Stop,
TriggerStrategy = OkxGridTriggerStrategy.Price,
TriggerPrice = "1000"
}
]
});
var grid_02 = await api.Grid.PlaceOrderAsync(
instrumentId: "BTC-USDT-SWAP",
algoOrderType: OkxGridAlgoOrderType.ContractGrid,
maximumPrice: 5000,
minimumPrice: 400,
gridNumber: 10,
gridRunType: OkxGridRunType.Arithmetic,
size: 200,
contractGridDirection: OkxGridContractDirection.Long,
leverage: 2,
triggerParameters:
[
new ()
{
TriggerAction = OkxGridAlgoTriggerAction.Start,
TriggerStrategy = OkxGridTriggerStrategy.Rsi,
TimeFrame = OkxGridAlgoTimeFrame.ThirtyMinutes,
Threshold = "10",
TriggerCondition = OkxGridAlgoTriggerCondition.Cross,
TimePeriod = "14"
},
new ()
{
TriggerAction = OkxGridAlgoTriggerAction.Stop,
TriggerStrategy = OkxGridTriggerStrategy.Price,
TriggerPrice = "1000",
ContractAlgoStopType = OkxGridContractAlgoStopType.KeepPositions,
}
]
);
var grid_03 = await api.Grid.AmendOrderAsync(new OkxGridOrderAmendRequest());
var grid_04 = await api.Grid.AmendOrderAsync(448965992920907776, "BTC-USDT-SWAP", 1200);
var grid_05 = await api.Grid.StopOrderAsync(448965992920907776, "BTC-USDT", OkxGridAlgoOrderType.SpotGrid, OkxGridSpotAlgoStopType.SellBaseCurrency);
var grid_06 = await api.Grid.ClosePositionAsync(448965992920907776, true);
var grid_07 = await api.Grid.CancelClosePositionAsync(448965992920907776, 570627699870375936);
var grid_08 = await api.Grid.TriggerOrderAsync(448965992920907776);
var grid_09 = await api.Grid.GetOpenOrdersAsync(OkxGridAlgoOrderType.SpotGrid);
var grid_10 = await api.Grid.GetOrdersHistoryAsync(OkxGridAlgoOrderType.SpotGrid);
var grid_11 = await api.Grid.GetOrderAsync(OkxGridAlgoOrderType.SpotGrid, 448965992920907776);
var grid_12 = await api.Grid.GetSubOrdersAsync(OkxGridAlgoOrderType.SpotGrid, 448965992920907776, OkxGridAlgoSubOrderType.Live);
var grid_13 = await api.Grid.GetPositionsAsync(OkxGridAlgoOrderType.ContractGrid, 448965992920907776);
var grid_14 = await api.Grid.WithdrawIncomeAsync(448965992920907776);
var grid_15 = await api.Grid.ComputeMarginBalanceAsync(448965992920907776, OkxAccountMarginAddReduce.Add, 10.0m);
var grid_16 = await api.Grid.AdjustMarginBalanceAsync(448965992920907776, OkxAccountMarginAddReduce.Add, 10.0m);
var grid_17 = await api.Grid.AddInvestmentAsync(448965992920907776, 1000.0m);
var grid_18 = await api.Grid.GetAIParameterAsync(OkxGridAlgoOrderType.SpotGrid, "BTC-USDT");
var grid_19 = await api.Grid.ComputeMinimumInvestmentAsync("ETH-USDT", OkxGridAlgoOrderType.SpotGrid, 5000, 3000, 50, OkxGridRunType.Arithmetic);
var grid_20 = await api.Grid.RsiBacktestAsync("BTC-USDT", OkxGridAlgoTimeFrame.ThreeMinutes, 30, 14);
// Order Book Trading -> Signal Bot Trading Methods (Signed)
var signal_01 = await api.SignalBot.CreateSignalChannelAsync("long short", "this is the first version");
var signal_02 = await api.SignalBot.GetSignalChannelsAsync(OkxSignalBotSourceType.FreeSignal);
var signal_03 = await api.SignalBot.CreateSignalBotAsync(
signalChannelId: 627921182788161536,
instrumentIds: [
"BTC-USDT-SWAP",
"ETH-USDT-SWAP",
"LTC-USDT-SWAP"
],
leverage: 10.0m,
amount: 100.0m,
orderType: OkxSignalBotOrderType.TradingViewSignal,
entryParamaters: new OkxSignalBotEntryParamaters
{
AllowMultipleEntry = true,
EntryType = OkxSignalBotEntryType.TradingViewSignal,
Amount = "",
Ratio = ""
},
exitParamaters: new OkxSignalBotExitParamaters
{
TakeProfitStopLossTriggerPrice = OkxSignalBotTriggerPrice.Price,
TakeProfitPercentage = "",
StopLossPercentage = ""
});
var signal_04 = await api.SignalBot.CancelSignalOrdersAsync(627921182788161536);
// Order Book Trading -> Recurring Buy Methods (Signed)
var recurring_01 = await api.RecurringBuy.PlaceOrderAsync("Strategy Name", new List<OkxRecurringBuyItem>(), OkxRecurringBuyPeriod.Monthly, 1, null, 1, "UTC", 1000.0m, "USDT", OkxTradeMode.Cross);
var recurring_02 = await api.RecurringBuy.AmendOrderAsync(1_000_001, "Strategy Name");
var recurring_03 = await api.RecurringBuy.StopOrderAsync(1_000_001);
var recurring_04 = await api.RecurringBuy.GetOpenOrdersAsync();
var recurring_05 = await api.RecurringBuy.GetOrderHistoryAsync();
var recurring_06 = await api.RecurringBuy.GetOrderAsync(algoOrderId: 1_000_001);
var recurring_07 = await api.RecurringBuy.GetSubOrdersAsync(algoOrderId: 1_000_001);
// Order Book Trading -> Copy Trading Methods (Signed)
var copy_01 = await api.CopyTrading.GetLeadingPositionsAsync();
var copy_02 = await api.CopyTrading.GetLeadingPositionsHistoryAsync();
var copy_03 = await api.CopyTrading.PlaceLeadingStopOrderAsync(leadingPositionId: 1_000_001);
var copy_04 = await api.CopyTrading.CloseLeadingPositionAsync(leadingPositionId: 1_000_001);
var copy_05 = await api.CopyTrading.GetLeadingInstrumentsAsync();
var copy_06 = await api.CopyTrading.SetLeadingInstrumentsAsync(["BTC-USDT", "ETH-USDT"]);
var copy_07 = await api.CopyTrading.GetProfitSharingDetailsAsync();
var copy_08 = await api.CopyTrading.GetProfitSharingTotalAsync();
var copy_09 = await api.CopyTrading.GetUnrealizedProfitSharingDetailsAsync();
var copy_10 = await api.CopyTrading.GetTotalUnrealizedProfitSharingAsync();
var copy_11 = await api.CopyTrading.ApplyForLeadTradingAsync([]);
var copy_12 = await api.CopyTrading.StopLeadTradingAsync();
var copy_13 = await api.CopyTrading.AmendProfitSharingRatioAsync(1.0m);
var copy_14 = await api.CopyTrading.GetAccountConfigurationAsync();
var copy_15 = await api.CopyTrading.FirstCopySettingsAsync("---CODE---", OkxCopyTradingMarginMode.Copy, OkxCopyTradingInstrumentIdType.Copy, 1000.0M, OkxCopyTradingPositionCloseType.CopyClose);
var copy_16 = await api.CopyTrading.AmendCopySettingsAsync("---CODE---", OkxCopyTradingMarginMode.Copy, OkxCopyTradingInstrumentIdType.Copy, 1000.0M, OkxCopyTradingPositionCloseType.CopyClose);
var copy_17 = await api.CopyTrading.StopCopyingAsync("---CODE---", OkxCopyTradingPositionCloseType.CopyClose, OkxInstrumentType.Option);
var copy_18 = await api.CopyTrading.GetCopySettingsAsync("---CODE---");
var copy_19 = await api.CopyTrading.GetMultipleLeverages(OkxAccountMarginMode.Isolated, "---CODE---", []);
var copy_20 = await api.CopyTrading.GetMultipleLeverages(OkxAccountMarginMode.Isolated, "---CODE---", default, "", "", "");
var copy_21 = await api.CopyTrading.SetMultipleLeverageAsync(OkxAccountMarginMode.Isolated, 10.0m, []);
var copy_22 = await api.CopyTrading.SetMultipleLeverageAsync(OkxAccountMarginMode.Isolated, 10.0m, default, "", "", "");
var copy_23 = await api.CopyTrading.GetMyLeadTradersAsync();
var copy_24 = await api.CopyTrading.GetMyLeadTradersHistoryAsync();
var copy_25 = await api.CopyTrading.GetPublicConfigurationAsync();
var copy_26 = await api.CopyTrading.GetLeadTradersRanksAsync();
var copy_27 = await api.CopyTrading.GetLeadTraderWeeklyPnlAsync("---CODE---");
var copy_28 = await api.CopyTrading.GetLeadTraderDailyPnlAsync("---CODE---", "");
var copy_29 = await api.CopyTrading.GetLeadTraderStatsAsync("---CODE---", "");
var copy_30 = await api.CopyTrading.GetLeadTraderCurrencyPreferencesAsync("---CODE---");
var copy_31 = await api.CopyTrading.GetLeadTraderCurrentPositionsAsync("---CODE---");
var copy_32 = await api.CopyTrading.GetLeadTraderPositionHistoryAsync("---CODE---");
var copy_33 = await api.CopyTrading.GetCopyTradersAsync("---CODE---");
var copy_34 = await api.CopyTrading.GetMyLeadTradersRanksAsync();
var copy_35 = await api.CopyTrading.GetMyLeadTraderWeeklyPnlAsync("---CODE---");
var copy_36 = await api.CopyTrading.GetMyLeadTraderDailyPnlAsync("---CODE---", "");
var copy_37 = await api.CopyTrading.GetMyLeadTraderStatsAsync("---CODE---", "");
var copy_38 = await api.CopyTrading.GetMyLeadTraderCurrencyPreferencesAsync("---CODE---");
var copy_39 = await api.CopyTrading.GetMyLeadTraderCurrentPositionsAsync("---CODE---");
var copy_40 = await api.CopyTrading.GetMyLeadTraderPositionHistoryAsync("---CODE---");
var copy_41 = await api.CopyTrading.GetMyCopyTradersAsync("---CODE---");
// Block Trading Methods (Unsigned)
var block_01 = await api.Block.GetCounterpartiesAsync();
var block_02 = await api.Block.CreateRfqAsync([], []);
var block_03 = await api.Block.CancelRfqAsync();
var block_04 = await api.Block.CancelRfqsAsync();
var block_05 = await api.Block.CancelAllRfqsAsync();
var block_06 = await api.Block.ExecuteQuoteAsync("", "");
var block_07 = await api.Block.GetQuoteProductsAsync();
var block_08 = await api.Block.SetQuoteProductsAsync([]);
var block_09 = await api.Block.ResetMmpAsync();
var block_10 = await api.Block.SetMmpAsync(30, 30, 30);
var block_11 = await api.Block.GetMmpAsync();
var block_12 = await api.Block.CreateQuoteAsync("", OkxTradeOrderSide.Buy, []);
var block_13 = await api.Block.CancelQuoteAsync();
var block_14 = await api.Block.CancelQuotesAsync();
var block_15 = await api.Block.CancelAllQuotesAsync();
var block_16 = await api.Block.CancelAllQuotesAfterAsync(30);
var block_17 = await api.Block.GetRfqsAsync();
var block_18 = await api.Block.GetQuotesAsync();
var block_19 = await api.Block.GetTradesAsync();
var block_20 = await api.Block.GetPublicExecutedTradesAsync();
var block_21 = await api.Block.GetTickersAsync(OkxInstrumentType.Futures);
var block_22 = await api.Block.GetTickerAsync("");
var block_23 = await api.Block.GetPublicRecentTradesAsync("");
// Spread Trading Methods (Signed)
var spread_01 = await api.Spread.PlaceOrderAsync("", OkxTradeOrderSide.Buy, OkxSpreadOrderType.LimitOrder, 1.0m);
var spread_02 = await api.Spread.CancelOrderAsync();
var spread_03 = await api.Spread.CancelOrdersAsync("");
var spread_04 = await api.Spread.AmendOrderAsync("");
var spread_05 = await api.Spread.GetOrderAsync();
var spread_06 = await api.Spread.GetOpenOrdersAsync();
var spread_07 = await api.Spread.GetOrderHistoryAsync();
var spread_08 = await api.Spread.GetOrderArchiveAsync();
var spread_09 = await api.Spread.GetTradesAsync();
var spread_10 = await api.Spread.GetSpreadsAsync();
var spread_11 = await api.Spread.GetOrderBookAsync("");
var spread_12 = await api.Spread.GetTickerAsync("");
var spread_13 = await api.Spread.GetTradesAsync();
var spread_14 = await api.Spread.GetCandlesticksAsync("", OkxPeriod.OneDay);
var spread_15 = await api.Spread.GetCandlesticksHistoryAsync("", OkxPeriod.OneDay);
var spread_16 = await api.Spread.CancelAllAfterAsync(30, "");
// Trading Statistics Methods (Unsigned)
var rubik_01 = await api.Rubik.GetSupportCoinAsync();
var rubik_02 = await api.Rubik.GetContractOpenInterestHistoryAsync("");
var rubik_03 = await api.Rubik.GetTakerVolumeAsync("BTC", OkxInstrumentType.Spot);
var rubik_04 = await api.Rubik.GetContractTakerVolumeAsync("");
var rubik_05 = await api.Rubik.GetMarginLendingRatioAsync("BTC", "1D");
var rubik_06 = await api.Rubik.GetTopTradersContractLongShortRatioAsync("");
var rubik_07 = await api.Rubik.GetTopTradersContractLongShortRatioByPositionAsync("");
var rubik_08 = await api.Rubik.GetContractLongShortRatioAsync("");
var rubik_09 = await api.Rubik.GetLongShortRatioAsync("BTC", "1D");
var rubik_10 = await api.Rubik.GetContractSummaryAsync("BTC", "1D");
var rubik_11 = await api.Rubik.GetOptionsSummaryAsync("BTC", "1D");
var rubik_12 = await api.Rubik.GetPutCallRatioAsync("BTC", "1D");
var rubik_13 = await api.Rubik.GetInterestVolumeExpiryAsync("BTC", "1D");
var rubik_14 = await api.Rubik.GetInterestVolumeStrikeAsync("BTC", "20210623", "1D");
var rubik_15 = await api.Rubik.GetTakerFlowAsync("BTC", "1D");
// Funding Account Methods (Signed)
var funding_01 = await api.Funding.GetCurrenciesAsync();
var funding_02 = await api.Funding.GetBalancesAsync();
var funding_03 = await api.Funding.GetNonTradableBalancesAsync();
var funding_04 = await api.Funding.GetAssetValuationAsync();
var funding_05 = await api.Funding.FundTransferAsync("BTC", 0.5m, OkxFundingTransferType.TransferWithinAccount, OkxAccount.Funding, OkxAccount.Trading);
var funding_06 = await api.Funding.FundTransferStateAsync();
var funding_07 = await api.Funding.GetFundingBillDetailsAsync("BTC");
var funding_08 = await api.Funding.GetLightningDepositsAsync("BTC", 0.001m);
var funding_09 = await api.Funding.GetDepositAddressAsync("BTC");
var funding_10 = await api.Funding.GetDepositAddressAsync("USDT");
var funding_12 = await api.Funding.GetDepositHistoryAsync("USDT");
var funding_13 = await api.Funding.WithdrawAsync("USDT", 100.0m, OkxFundingWithdrawalDestination.DigitalCurrencyAddress, "toAddress", 1.0m, "USDT-TRC20");
var funding_14 = await api.Funding.GetLightningWithdrawalsAsync("BTC", "invoice", "password");
var funding_15 = await api.Funding.CancelWithdrawalAsync(1_000_001);
var funding_16 = await api.Funding.GetWithdrawalHistoryAsync("USDT");
var funding_17 = await api.Funding.GetDepositStatusAsync("", "", "", "");
var funding_18 = await api.Funding.GetWithdrawalStatusAsync(1_000_000l);
var funding_19 = await api.Funding.ConvertDustAssetsAsync([]);
var funding_20 = await api.Funding.GetExchangeListAsync();
var funding_21 = await api.Funding.ApplyForMonthlyStatementAsync();
var funding_22 = await api.Funding.GetMonthlyStatementAsync("");
var funding_23 = await api.Funding.GetConvertCurrenciesAsync();
var funding_24 = await api.Funding.GetConvertCurrencyPairAsync("", "");
var funding_25 = await api.Funding.EstimateQuoteAsync("", "", OkxTradeOrderSide.Buy, 1000.0M, "");
var funding_26 = await api.Funding.PlaceConvertOrderAsync("", "", "", OkxTradeOrderSide.Buy, 1000.0M, "");
var funding_27 = await api.Funding.GetConvertHistoryAsync();
// Sub-Account Methods (Signed)
var subaccount_01 = await api.SubAccount.GetSubAccountsAsync();
var subaccount_02 = await api.SubAccount.ResetSubAccountApiKeyAsync("subAccountName", "apiKey", "apiLabel", true, true, "");
var subaccount_03 = await api.SubAccount.GetSubAccountTradingBalancesAsync("subAccountName");
var subaccount_04 = await api.SubAccount.GetSubAccountFundingBalancesAsync("subAccountName");
var subaccount_05 = await api.SubAccount.GetSubAccountMaximumWithdrawalsAsync("subAccountName");
var subaccount_06 = await api.SubAccount.GetSubAccountBillsAsync();
var subaccount_07 = await api.SubAccount.GetManagedSubAccountBillsAsync();
var subaccount_08 = await api.SubAccount.TransferBetweenSubAccountsAsync("BTC", 0.5m, OkxAccount.Funding, OkxAccount.Trading, "fromSubAccountName", "toSubAccountName");
var subaccount_09 = await api.SubAccount.SetPermissionOfTransferOutAsync("", true);
var subaccount_10 = await api.SubAccount.GetEntrustSubAccountsAsync("");
var subaccount_11 = await api.SubAccount.SetLoanAllocationAsync(false, []);
var subaccount_12 = await api.SubAccount.GetInterestLimitsAsync("");
// Financial Product -> On-Chain Earn Methods (Signed)
var onchain_01 = await api.Financial.OnChainEarn.GetOffersAsync();
var onchain_02 = await api.Financial.OnChainEarn.PurchaseAsync("", []);
var onchain_03 = await api.Financial.OnChainEarn.RedeemAsync("", "");
var onchain_04 = await api.Financial.OnChainEarn.CancelAsync("", "");
var onchain_05 = await api.Financial.OnChainEarn.GetOpenOrdersAsync();
var onchain_06 = await api.Financial.OnChainEarn.GetHistoryAsync();
// Financial Product -> ETH Staking Methods (Signed)
var staking_01 = await api.Financial.EthStaking.PurchaseAsync(1.0m);
var staking_02 = await api.Financial.EthStaking.RedeemAsync(1.0m);
var staking_03 = await api.Financial.EthStaking.GetBalancesAsync();
var staking_04 = await api.Financial.EthStaking.GetHistoryAsync(OkxFinancialEthStakingType.Purchase);
var staking_05 = await api.Financial.EthStaking.GetApyHistoryAsync(30);
// Financial Product -> Simple Earn Flexible Methods (Signed)
var flexible_01 = await api.Financial.FlexibleSimpleEarn.GetBalancesAsync();
var flexible_02 = await api.Financial.FlexibleSimpleEarn.PurchaseAsync("", 1_000.0m, 1.0m);
var flexible_03 = await api.Financial.FlexibleSimpleEarn.RedeemAsync("", 1_000.0m, 1.0m);
var flexible_04 = await api.Financial.FlexibleSimpleEarn.SetLendingRateAsync("", 1.0m);
var flexible_05 = await api.Financial.FlexibleSimpleEarn.GetLendingHistoryAsync();
var flexible_06 = await api.Financial.FlexibleSimpleEarn.GetPublicBorrowSummaryAsync();
var flexible_07 = await api.Financial.FlexibleSimpleEarn.GetPublicBorrowHistoryAsync();
// Financial Product -> Simple Earn Fixed Methods (Signed)
var fixed_01 = await api.Financial.FixedSimpleEarn.GetLendingOffersAsync();
var fixed_02 = await api.Financial.FixedSimpleEarn.GetLendingApyHistoryAsync();
var fixed_03 = await api.Financial.FixedSimpleEarn.GetPendingLendingVolumeAsync();
var fixed_04 = await api.Financial.FixedSimpleEarn.PlaceOrderAsync("", 1_000.0m, 1.0m, "");
var fixed_05 = await api.Financial.FixedSimpleEarn.AmendOrderAsync(1_000_000L);
var fixed_06 = await api.Financial.FixedSimpleEarn.GetOrdersAsync();
var fixed_07 = await api.Financial.FixedSimpleEarn.GetSubOrdersAsync();
// Affiliate Methods (Signed)
var affiliate_01 = await api.Affiliate.GetInviteeAsync(1_000_000L);
// TODO: NDBroker Methods (Signed)
// TODO: FDBroker Methods (Signed)
WebSocket Api Examples
The OKX.Api socket client provides several socket endpoint to which can be subscribed.
var ws = new OKXWebSocketApiClient();
ws.SetApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX", "XXXXXXXX-API-PASSPHRASE-XXXXXXXX");
// Subscription
var subscription = await ws.Public.SubscribeToTickersAsync((data) =>
{
// ... Your logic here
Console.WriteLine($"Ticker {data.InstrumentId} Ask:{data.AskPrice} Bid:{data.BidPrice}");
}, "BTC-USDT");
// UnSubscription
_ = ws.UnsubscribeAsync(subscription.Data);
// Public Updates --------------------------------------------------------------------------------
await ws.Public.SubscribeToInstrumentsAsync((data) =>
{
// ... Your logic here
}, OkxInstrumentType.Spot);
await ws.Public.SubscribeToOpenInterestsAsync((data) =>
{
// ... Your logic here
}, "BTC-USDT");
await ws.Public.SubscribeToFundingRatesAsync((data) =>
{
// ... Your logic here
}, "BTC-USDT");
await ws.Public.SubscribeToPriceLimitAsync((data) =>
{
// ... Your logic here
}, "BTC-USDT");
await ws.Public.SubscribeToOptionSummaryAsync((data) =>
{
// ... Your logic here
}, "USD");
await ws.Public.SubscribeToEstimatedPriceAsync((data) =>
{
// ... Your logic here
}, OkxInstrumentType.Option);
await ws.Public.SubscribeToMarkPriceAsync((data) =>
{
// ... Your logic here
}, "BTC-USDT");
await ws.Public.SubscribeToIndexTickersAsync((data) =>
{
// ... Your logic here
}, "BTC-USDT");
await ws.Public.SubscribeToMarkPriceCandlesticksAsync((data) =>
{
// ... Your logic here
}, "BTC-USDT", OkxPeriod.FiveMinutes);
await ws.Public.SubscribeToIndexCandlesticksAsync((data) =>
{
// ... Your logic here
}, "BTC-USDT", OkxPeriod.FiveMinutes);
var pairs = new List<string> { "BTC-USDT", "LTC-USDT", "ETH-USDT", "XRP-USDT", "BCH-USDT", "EOS-USDT", "OKB-USDT", "ETC-USDT", "TRX-USDT", "BSV-USDT", "DASH-USDT", "NEO-USDT", "QTUM-USDT", "XLM-USDT", "ADA-USDT", "AE-USDT", "BLOC-USDT", "EGT-USDT", "IOTA-USDT", "SC-USDT", "WXT-USDT", "ZEC-USDT", };
foreach (var pair in pairs)
{
await ws.Public.SubscribeToTickersAsync((data) =>
{
// ... Your logic here
Console.WriteLine($"Ticker {data.InstrumentId} Ask:{data.AskPrice} Bid:{data.BidPrice}");
}, pair);
}
await ws.Public.SubscribeToCandlesticksAsync((data) =>
{
// ... Your logic here
}, "BTC-USDT", OkxPeriod.FiveMinutes);
await ws.Public.SubscribeToTradesAsync((data) =>
{
// ... Your logic here
}, "BTC-USDT");
await ws.Public.SubscribeToOrderBookAsync((data) =>
{
// ... Your logic here
}, "BTC-USDT", OkxOrderBookType.OrderBook);
await ws.Public.SubscribeToSystemUpgradeStatusAsync((data) =>
{
// ... Your logic here
});
// End of Public Updates -------------------------------------------------------------------
// TradingAccount Updates
await ws.Account.SubscribeToAccountUpdatesAsync((data) =>
{
// ... Your logic here
});
await ws.Account.SubscribeToPositionUpdatesAsync((data) =>
{
// ... Your logic here
}, OkxInstrumentType.Futures, "INSTRUMENT-FAMILY", "INSTRUMENT-ID");
await ws.Account.SubscribeToBalanceAndPositionUpdatesAsync((data) =>
{
// ... Your logic here
});
await ws.Account.SubscribeToPositionRiskUpdatesAsync(OkxInstrumentType.Futures, (data) =>
{
// ... Your logic here
});
await ws.Account.SubscribeToAccountGreeksUpdatesAsync((data) =>
{
// ... Your logic here
});
// End of TradingAccount Updates -----------------------------------------------------------
// TODO: FundingAccount Updates
// Trade Updates (Private) -----------------------------------------------------------------
await ws.Trading.SubscribeToOrderUpdatesAsync((data) =>
{
// ... Your logic here
}, OkxInstrumentType.Futures, "INSTRUMENT-FAMILY", "INSTRUMENT-ID");
await ws.Trading.PlaceOrderAsync(new Trade.Models.OkxOrderPlaceRequest());
await ws.Trading.PlaceOrdersAsync(new List<Trade.Models.OkxOrderPlaceRequest>());
await ws.Trading.CancelOrderAsync(new Trade.Models.OkxOrderCancelRequest());
await ws.Trading.CancelOrdersAsync(new List<Trade.Models.OkxOrderCancelRequest>());
await ws.Trading.AmendOrderAsync(new Trade.Models.OkxOrderAmendRequest());
await ws.Trading.AmendOrdersAsync(new List<Trade.Models.OkxOrderAmendRequest>());
// End of Trade Updates (Private) ----------------------------------------------------------
// AlgoTrading Updates (Private) -----------------------------------------------------------
await ws.AlgoTrading.SubscribeToAlgoOrderUpdatesAsync((data) =>
{
// ... Your logic here
}, OkxInstrumentType.Futures, "INSTRUMENT-FAMILY", "INSTRUMENT-ID");
await ws.AlgoTrading.SubscribeToAdvanceAlgoOrderUpdatesAsync((data) =>
{
// ... Your logic here
}, OkxInstrumentType.Futures, "INSTRUMENT-FAMILY", "INSTRUMENT-ID");
// End of AlgoTrading Updates (Private) ----------------------------------------------------
// TODO: GridTrading Updates (Private)
// RecurringBuy Updates (Private) ----------------------------------------------------------
await ws.RecurringBuy.SubscribeToOrderUpdatesAsync((data) =>
{
// ... Your logic here
}, OkxInstrumentType.Spot);
// End of RecurringBuy Updates (Private) ---------------------------------------------------
// TODO: CopyTrading Updates (Private)
// TODO: BlockTrading Updates (Private)
// TODO: SpreadTrading Updates (Private)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.4.1223 | 153 | 12/23/2024 |
5.4.1219 | 1,237 | 12/19/2024 |
5.4.1217 | 1,265 | 12/17/2024 |
5.4.1202 | 3,189 | 12/1/2024 |
5.4.1025 | 7,010 | 10/25/2024 |
5.4.1021 | 6,788 | 10/21/2024 |
5.4.1011 | 9,896 | 10/10/2024 |
5.4.1010 | 11,154 | 10/9/2024 |
5.4.1001 | 8,446 | 10/1/2024 |
2.6.8 | 3,800 | 9/26/2024 |
2.6.7 | 16,452 | 9/20/2024 |
2.6.4 | 10,005 | 9/19/2024 |
2.5.7 | 10,747 | 9/18/2024 |
2.5.6 | 8,530 | 9/18/2024 |
2.5.5 | 6,928 | 9/18/2024 |
2.5.1 | 14,633 | 9/17/2024 |
2.4.8 | 10,242 | 8/19/2024 |
2.3.1 | 9,899 | 8/9/2024 |
2.2.5 | 14,622 | 7/24/2024 |
2.2.0 | 8,708 | 7/20/2024 |
2.0.6 | 5,094 | 7/2/2024 |
2.0.3 | 5,648 | 4/6/2024 |
2.0.2 | 4,924 | 3/28/2024 |
2.0.1 | 2,478 | 3/27/2024 |
1.7.2 | 231 | 3/19/2024 |
1.7.0 | 482 | 2/29/2024 |
1.6.0 | 50,164 | 2/5/2024 |
1.5.6 | 639 | 1/3/2024 |
1.5.5 | 715 | 12/10/2023 |
1.5.1 | 662 | 11/15/2023 |
1.5.0 | 544 | 11/13/2023 |
1.4.0 | 970 | 9/18/2023 |
1.3.1 | 206,914 | 8/6/2023 |
1.2.5 | 776 | 8/6/2023 |
1.2.3 | 1,241 | 8/3/2023 |
1.2.2 | 1,244 | 7/28/2023 |
1.1.7 | 1,160 | 6/27/2023 |
1.1.0 | 3,780 | 5/7/2023 |
1.0.6 | 734 | 5/6/2023 |
1.0.5 | 802 | 4/19/2023 |
1.0.4 | 782 | 4/18/2023 |
1.0.3 | 801 | 4/18/2023 |
1.0.2 | 764 | 4/17/2023 |
1.0.1 | 979 | 3/25/2023 |
1.0.0 | 783 | 3/25/2023 |
Please refer to changelog at Github https://github.com/burakoner/OKX.Api/blob/master/CHANGELOG.md